diff options
author | Yaco <franco@reevo.org> | 2021-10-19 20:30:39 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2021-10-19 20:30:39 -0300 |
commit | 8c201ace3699b4928daf41eb7b4cdcb4565c6f3b (patch) | |
tree | fbd98f026864e9c1919d3ee740b6799ca0c651e2 /www/wiki/extensions/Scribunto/tests/phpunit/engines/LuaCommon/LanguageLibraryTest.php | |
parent | e3880a1c86acaa3bbd05786ad2f5c586e6511a58 (diff) |
adds Scribunto
Diffstat (limited to 'www/wiki/extensions/Scribunto/tests/phpunit/engines/LuaCommon/LanguageLibraryTest.php')
-rw-r--r-- | www/wiki/extensions/Scribunto/tests/phpunit/engines/LuaCommon/LanguageLibraryTest.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/www/wiki/extensions/Scribunto/tests/phpunit/engines/LuaCommon/LanguageLibraryTest.php b/www/wiki/extensions/Scribunto/tests/phpunit/engines/LuaCommon/LanguageLibraryTest.php new file mode 100644 index 00000000..39a631b2 --- /dev/null +++ b/www/wiki/extensions/Scribunto/tests/phpunit/engines/LuaCommon/LanguageLibraryTest.php @@ -0,0 +1,70 @@ +<?php + +// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps +class Scribunto_LuaLanguageLibraryTest extends Scribunto_LuaEngineTestBase { + protected static $moduleName = 'LanguageLibraryTests'; + + public function __construct( + $name = null, array $data = [], $dataName = '', $engineName = null + ) { + parent::__construct( $name, $data, $dataName, $engineName ); + + // Skip certain tests if something isn't providing translated language names + // (bug 67343) + if ( Language::fetchLanguageName( 'en', 'fr' ) === 'English' ) { + $msg = 'Language name translations are unavailable; ' . + 'install Extension:CLDR or something similar'; + $this->skipTests += [ + 'fetchLanguageName (en,ru)' => $msg, + 'fetchLanguageName (ru,en)' => $msg, + 'fetchLanguageNames (de)' => $msg, + 'fetchLanguageNames ([[bogus]])' => $msg, + ]; + } + } + + protected function getTestModules() { + return parent::getTestModules() + [ + 'LanguageLibraryTests' => __DIR__ . '/LanguageLibraryTests.lua', + ]; + } + + public function testFormatDateTTLs() { + global $wgContLang; + + $engine = $this->getEngine(); + $pp = $engine->getParser()->getPreprocessor(); + + $ttl = null; + $wgContLang->sprintfDate( 's', '20130101000000', null, $ttl ); + if ( $ttl === null ) { + $this->markTestSkipped( "Language::sprintfDate does not set a TTL" ); + } + + // sprintfDate has its own unit tests for making sure its output is right, + // so all we need to test here is we get TTLs when we're supposed to + $this->extraModules['Module:FormatDate'] = ' + local p = {} + function p.formatCurrentDate() + return mw.getContentLanguage():formatDate( "s" ) + end + function p.formatSpecificDate() + return mw.getContentLanguage():formatDate( "s", "20130101000000" ) + end + return p + '; + + $title = Title::makeTitle( NS_MODULE, 'FormatDate' ); + $module = $engine->fetchModuleFromParser( $title ); + + $frame = $pp->newFrame(); + $module->invoke( 'formatCurrentDate', $frame ); + $this->assertEquals( 1, $frame->getTTL(), + 'TTL must be equal to 1 second when lang:formatDate( \'s\' ) is called' ); + + $frame = $pp->newFrame(); + $module->invoke( 'formatSpecificDate', $frame ); + $this->assertNull( $frame->getTTL(), + 'TTL must not be set when lang:formatDate is called with a specific date' ); + } +} |