2014-03-05 16:30:09 +00:00
|
|
|
<?php
|
|
|
|
|
2020-03-14 19:57:09 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2018-05-27 00:50:43 +00:00
|
|
|
/**
|
|
|
|
* @covers Scribunto_LuaLanguageLibrary
|
|
|
|
*/
|
2019-08-03 18:19:46 +00:00
|
|
|
class Scribunto_LuaLanguageLibraryTest extends Scribunto_LuaEngineUnitTestBase {
|
2014-03-05 16:30:09 +00:00
|
|
|
protected static $moduleName = 'LanguageLibraryTests';
|
|
|
|
|
2016-05-17 14:52:05 +00:00
|
|
|
public function __construct(
|
2017-06-15 17:19:00 +00:00
|
|
|
$name = null, array $data = [], $dataName = '', $engineName = null
|
2016-05-17 14:52:05 +00:00
|
|
|
) {
|
2014-07-01 14:21:00 +00:00
|
|
|
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';
|
2017-06-15 17:19:00 +00:00
|
|
|
$this->skipTests += [
|
2014-07-01 14:21:00 +00:00
|
|
|
'fetchLanguageName (en,ru)' => $msg,
|
|
|
|
'fetchLanguageName (ru,en)' => $msg,
|
|
|
|
'fetchLanguageNames (de)' => $msg,
|
2014-12-29 20:40:02 +00:00
|
|
|
'fetchLanguageNames ([[bogus]])' => $msg,
|
2017-06-15 17:19:00 +00:00
|
|
|
];
|
2014-07-01 14:21:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 11:43:44 +00:00
|
|
|
protected function getTestModules() {
|
2017-06-15 17:19:00 +00:00
|
|
|
return parent::getTestModules() + [
|
2014-03-05 16:30:09 +00:00
|
|
|
'LanguageLibraryTests' => __DIR__ . '/LanguageLibraryTests.lua',
|
2017-06-15 17:19:00 +00:00
|
|
|
];
|
2014-03-05 16:30:09 +00:00
|
|
|
}
|
2014-06-01 03:15:42 +00:00
|
|
|
|
2014-11-12 11:43:44 +00:00
|
|
|
public function testFormatDateTTLs() {
|
2014-06-01 03:15:42 +00:00
|
|
|
$engine = $this->getEngine();
|
|
|
|
$pp = $engine->getParser()->getPreprocessor();
|
|
|
|
|
|
|
|
$ttl = null;
|
2020-03-14 19:57:09 +00:00
|
|
|
MediaWikiServices::getInstance()->getContentLanguage()
|
|
|
|
->sprintfDate( 's', '20130101000000', null, $ttl );
|
2014-06-01 03:15:42 +00:00
|
|
|
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 );
|
2020-05-30 06:09:13 +00:00
|
|
|
$this->assertSame( 1, $frame->getTTL(),
|
2016-05-17 14:52:05 +00:00
|
|
|
'TTL must be equal to 1 second when lang:formatDate( \'s\' ) is called' );
|
2014-06-01 03:15:42 +00:00
|
|
|
|
|
|
|
$frame = $pp->newFrame();
|
|
|
|
$module->invoke( 'formatSpecificDate', $frame );
|
2016-05-17 14:52:05 +00:00
|
|
|
$this->assertNull( $frame->getTTL(),
|
|
|
|
'TTL must not be set when lang:formatDate is called with a specific date' );
|
2014-06-01 03:15:42 +00:00
|
|
|
}
|
2014-03-05 16:30:09 +00:00
|
|
|
}
|