Add test for NodaTimeAutotranslater, allow parsing days and months BC
This commit is contained in:
parent
cb2eff61a3
commit
d56d47aee1
|
@ -420,13 +420,25 @@ final class NodaTimeAutotranslater {
|
|||
|
||||
$suffixMode = self::getSuffixModeForYearsWSuffix($start, $end);
|
||||
|
||||
// Time info to pass
|
||||
if ($suffixMode === 2) {
|
||||
$timeInfoToCopy = $timeInfo;
|
||||
$timeInfoToCopy["zeit_beginn"] = abs($start);
|
||||
$timeInfoToCopy["zeit_ende"] = abs($end);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
foreach (self::LANGS_TO_CE_FORMAT as $tLang => $ceFormat) {
|
||||
|
||||
if ($start === $end) {
|
||||
$year = sprintf(self::LANGS_SINGLE_YEAR_FORMAT[$tLang], (string)abs($start));
|
||||
if ($suffixMode === 2) {
|
||||
$year = self::getTranslations($timeInfoToCopy)[$tLang];
|
||||
}
|
||||
else {
|
||||
if ($start === $end) {
|
||||
$year = sprintf(self::LANGS_SINGLE_YEAR_FORMAT[$tLang], (string)abs($start));
|
||||
}
|
||||
else $year = sprintf(self::LANGS_YEARSPAN_FORMAT[$tLang], (string)abs($start), (string)abs($end));
|
||||
}
|
||||
else $year = sprintf(self::LANGS_YEARSPAN_FORMAT[$tLang], (string)abs($start), (string)abs($end));
|
||||
|
||||
$output[$tLang] = self::applyBcBceFormat($tLang, $year, $suffixMode);
|
||||
|
||||
|
@ -467,6 +479,7 @@ final class NodaTimeAutotranslater {
|
|||
$end = intval($timeInfo['zeit_ende']);
|
||||
$output = [];
|
||||
|
||||
if (abs($start) === 1102) throw new Exception(var_export($timeInfo, true));
|
||||
foreach (self::LANGS_YEARSPAN_FORMAT as $tLang => $format) {
|
||||
$output[$tLang] = sprintf($format, (string)abs($start), (string)abs($end));
|
||||
}
|
||||
|
@ -615,7 +628,7 @@ final class NodaTimeAutotranslater {
|
|||
public static function getTranslations(array $timeInfo):array {
|
||||
|
||||
if (!($translation_type = self::check_translatability((string)$timeInfo['zeit_beginn'], (string)$timeInfo['zeit_ende'], (string)$timeInfo['zeit_zaehlzeit_monat']))) {
|
||||
throw new MDgenericInvalidInputsException("Non-translatable date");
|
||||
throw new MDgenericInvalidInputsException("Non-translatable date: {$timeInfo['zeit_beginn']} - {$timeInfo['zeit_ende']}");
|
||||
}
|
||||
|
||||
if ($translation_type === self::TRANSLATABLE_ONLY_YEAR) {
|
||||
|
|
368
tests/NodaTimeAutotranslaterTest.php
Normal file
368
tests/NodaTimeAutotranslaterTest.php
Normal file
|
@ -0,0 +1,368 @@
|
|||
<?PHP
|
||||
/**
|
||||
* This script contains tests for the home page.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
use PHPUnit\Framework\TestCase;
|
||||
require __DIR__ . "/../src/NodaTimeAutotranslater.php";
|
||||
|
||||
/**
|
||||
* Tests for home page.
|
||||
*/
|
||||
final class NodaTimeAutotranslaterTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateSingleDay():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "1920",
|
||||
"zeit_ende" => "1920",
|
||||
"zeit_zaehlzeit_jahr" => "1920",
|
||||
"zeit_zaehlzeit_monat" => "05",
|
||||
"zeit_zaehlzeit_tag" => "01",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "01.05.1920");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateSingleDayBeforeCommonEra():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "-1920",
|
||||
"zeit_ende" => "-1920",
|
||||
"zeit_zaehlzeit_jahr" => "1920",
|
||||
"zeit_zaehlzeit_monat" => "05",
|
||||
"zeit_zaehlzeit_tag" => "01",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "01.05.1920 v. Chr.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateSingleMonth():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "1920",
|
||||
"zeit_ende" => "1920",
|
||||
"zeit_zaehlzeit_jahr" => "1920",
|
||||
"zeit_zaehlzeit_monat" => "02",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "Februar 1920");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateSingleMonthBeforeCommonEra():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "-1920",
|
||||
"zeit_ende" => "-1920",
|
||||
"zeit_zaehlzeit_jahr" => "1920",
|
||||
"zeit_zaehlzeit_monat" => "02",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "Februar 1920 v. Chr.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateDecades():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "1920",
|
||||
"zeit_ende" => "1939",
|
||||
"zeit_zaehlzeit_jahr" => "1930",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "1920-1930er Jahre");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateCentury():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "1901",
|
||||
"zeit_ende" => "2000",
|
||||
"zeit_zaehlzeit_jahr" => "1950",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "20. Jahrhundert");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateCenturies():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "1801",
|
||||
"zeit_ende" => "2000",
|
||||
"zeit_zaehlzeit_jahr" => "1900",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "19.-20. Jahrhundert");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateCenturyBeforeCommonEra():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "-2000",
|
||||
"zeit_ende" => "-1901",
|
||||
"zeit_zaehlzeit_jahr" => "1950",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "20. Jahrhundert v. Chr.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateCenturiesBeforeCommonEra():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "-2000",
|
||||
"zeit_ende" => "-1801",
|
||||
"zeit_zaehlzeit_jahr" => "1900",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "20.-19. Jahrhundert v. Chr.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateYYYYUntilYYYY():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "1000",
|
||||
"zeit_ende" => "1150",
|
||||
"zeit_zaehlzeit_jahr" => "1075",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "1000-1150");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateSingleYear():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "1000",
|
||||
"zeit_ende" => "1000",
|
||||
"zeit_zaehlzeit_jahr" => "1000",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "1000");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateSingleYearBeforeCommonEra():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "-1000",
|
||||
"zeit_ende" => "-1000",
|
||||
"zeit_zaehlzeit_jahr" => "1000",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "1000 v. Chr.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateYYYYUntilYYYYBefore1000():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "800",
|
||||
"zeit_ende" => "850",
|
||||
"zeit_zaehlzeit_jahr" => "0825",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "800-850 n. Chr.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateYYYYUntilYYYYBeforeCommonEra():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "-1156",
|
||||
"zeit_ende" => "-1102",
|
||||
"zeit_zaehlzeit_jahr" => "1075",
|
||||
"zeit_zaehlzeit_monat" => "00",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "1156-1102 v. Chr.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateSinceSingleDay():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "1920",
|
||||
"zeit_ende" => "?",
|
||||
"zeit_zaehlzeit_jahr" => "1920",
|
||||
"zeit_zaehlzeit_monat" => "05",
|
||||
"zeit_zaehlzeit_tag" => "01",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "Seit 01.05.1920");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check whether the HTML page is correctly generated.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanTranslateSinceSingleMonth():void {
|
||||
|
||||
$timeInfo = [
|
||||
"zeit_beginn" => "1920",
|
||||
"zeit_ende" => "?",
|
||||
"zeit_zaehlzeit_jahr" => "1920",
|
||||
"zeit_zaehlzeit_monat" => "05",
|
||||
"zeit_zaehlzeit_tag" => "00",
|
||||
];
|
||||
$output = NodaTimeAutotranslater::getTranslations($timeInfo);
|
||||
self::assertEquals($output["de"], "Seit Mai 1920");
|
||||
|
||||
}
|
||||
|
||||
}
|
45
tests/config.xml
Normal file
45
tests/config.xml
Normal file
|
@ -0,0 +1,45 @@
|
|||
<phpunit
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/|version|/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
beStrictAboutChangesToGlobalState="false"
|
||||
beStrictAboutOutputDuringTests="false"
|
||||
beStrictAboutResourceUsageDuringSmallTests="true"
|
||||
beStrictAboutTodoAnnotatedTests="true"
|
||||
beStrictAboutCoversAnnotation="false"
|
||||
cacheResult="false"
|
||||
cacheTokens="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertDeprecationsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
preserveGlobalState="false"
|
||||
runTestInSeparateProcess="true"
|
||||
enforceTimeLimit="true"
|
||||
failOnWarning="true"
|
||||
forceCoversAnnotation="false"
|
||||
printerClass="PHPUnit\TextUI\ResultPrinter"
|
||||
processIsolation="true"
|
||||
stopOnError="true"
|
||||
stopOnFailure="true"
|
||||
stopOnIncomplete="true"
|
||||
stopOnSkipped="true"
|
||||
stopOnRisky="true"
|
||||
testSuiteLoaderClass="PHPUnit\Runner\StandardTestSuiteLoader"
|
||||
timeoutForSmallTests="1"
|
||||
timeoutForMediumTests="10"
|
||||
timeoutForLargeTests="60"
|
||||
verbose="true">
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<!-- <file>/path/to/file</file>
|
||||
<exclude>
|
||||
<directory suffix=".php">/path/to/files</directory>
|
||||
<file>/path/to/file</file>
|
||||
</exclude>-->
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
Loading…
Reference in New Issue
Block a user