PHP Classes

File: .tests/DemojibakefierTest.php

Recommend this page to a friend!
  Packages of Caleb   PHP Common Class Library   .tests/DemojibakefierTest.php   Download  
File: .tests/DemojibakefierTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PHP Common Class Library
Set of classes that provides common functionality
Author: By
Last change:
Date: 9 months ago
Size: 3,423 bytes
 

Contents

Class file image Download
<?php
/**
 * Demojibakefier tests file.
 *
 * This file is a part of the "common classes package", utilised by a number of
 * packages and projects, including CIDRAM and phpMussel.
 * @link https://github.com/Maikuolan/Common
 */

/**
 * If this file remains intact after deploying the package to production,
 * preventing it from running outside of Composer may be useful as a means of
 * prevent potential attackers from hammering the file and needlessly wasting
 * cycles at the server.
 */
if (!isset($_SERVER['COMPOSER_BINARY'])) {
    die;
}

require
$ClassesDir . $Case . '.php';

/**
 * Korean placeholder text.
 * @link http://yoondongju.yonsei.ac.kr/poet/poem.asp?ID=1
 */
$TextKO = '?? ??? ??? ??? ?? ???? ???, ??? ?? ???? ?? ?????. ?? ???? ???? ?? ???? ?? ????? ??? ??? ??? ?? ??????. ????? ?? ??? ????.';

/**
 * Preamble of the United Nations Charter in Chinese.
 * @link https://www.un.org/zh/sections/un-charter/preamble/index.html
 */
$TextZH = '??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????';

$DataKO = iconv('UTF-8', 'UTF-16BE', $TextKO);
$DataZH = iconv('UTF-8', 'GB18030', $TextZH);

/** Firstly, confirm it's naturally reversible (without Demojibakefier's help). */
if (iconv('UTF-16BE', 'UTF-8', $DataKO) !== $TextKO) {
    echo
'Test failed: ' . $Case . ':L' . __LINE__ . '().' . PHP_EOL;
    exit(
$ExitCode);
}
$ExitCode++;
if (
iconv('GB18030', 'UTF-8', $DataZH) !== $TextZH) {
    echo
'Test failed: ' . $Case . ':L' . __LINE__ . '().' . PHP_EOL;
    exit(
$ExitCode);
}

/** Now we'll build our compound "wrong" data. */
$Sample = $DataKO . "\n" . $DataZH;

/** Instantiate the object. */
$Demojibakefier = new \Maikuolan\Common\Demojibakefier();

$ExitCode++;
$Reversed = explode("\n", $Demojibakefier->guard($Sample), 2);

/** Now let's check whether Demojibakefier can reverse it itself. */
$ExitCode++;
if (
$Reversed[0] !== $TextKO) {
    echo
'Test failed: ' . $Case . ':L' . __LINE__ . '().' . PHP_EOL;
    exit(
$ExitCode);
}
$ExitCode++;
if (
$Reversed[1] !== $TextZH) {
    echo
'Test failed: ' . $Case . ':L' . __LINE__ . '().' . PHP_EOL;
    exit(
$ExitCode);
}

/**
 * There are still a bunch of things that don't quite entirely work as intended
 * with the Demojibakefier class, but I can't test for those things until I fix
 * them properly anyway, hence why the tests here are quite small right now.
 * I'll update the tests later, after those oddities have been weeded out.
 */