| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Scribunto\Tests\Engines\LuaCommon; |
| 4 |
|
| 5 |
use MediaWiki\MediaWikiServices; |
| 6 |
use MediaWiki\Title\Title; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class LanguageLibraryTest extends LuaEngineUnitTestBase { |
| 12 |
|
| 13 |
protected static $moduleName = 'LanguageLibraryTests'; |
| 14 |
|
| 15 |
public function __construct( |
| 16 |
$name = null, array $data = [], $dataName = '', $engineName = null |
| 17 |
) { |
| 18 |
parent::__construct( $name, $data, $dataName, $engineName ); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
if ( MediaWikiServices::getInstance()->getLanguageNameUtils()->getLanguageName( 'en', 'fr' ) === 'English' ) { |
| 23 |
$msg = 'Language name translations are unavailable; ' . |
| 24 |
'install Extension:CLDR or something similar'; |
| 25 |
$this->skipTests += [ |
| 26 |
'fetchLanguageName (en,ru)' => $msg, |
| 27 |
'fetchLanguageName (ru,en)' => $msg, |
| 28 |
'fetchLanguageNames (de)' => $msg, |
| 29 |
'fetchLanguageNames ([[bogus]])' => $msg, |
| 30 |
]; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
protected function getTestModules() { |
| 35 |
return parent::getTestModules() + [ |
| 36 |
'LanguageLibraryTests' => __DIR__ . '/LanguageLibraryTests.lua', |
| 37 |
]; |
| 38 |
} |
| 39 |
|
| 40 |
public function testFormatDateTTLs() { |
| 41 |
$engine = $this->getEngine(); |
| 42 |
$pp = $engine->getParser()->getPreprocessor(); |
| 43 |
|
| 44 |
$ttl = null; |
| 45 |
MediaWikiServices::getInstance()->getContentLanguage() |
| 46 |
->sprintfDate( 's', '20130101000000', null, $ttl ); |
| 47 |
if ( $ttl === null ) { |
| 48 |
$this->markTestSkipped( "Language::sprintfDate does not set a TTL" ); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
$this->extraModules['Module:FormatDate'] = ' |
| 54 |
local p = {} |
| 55 |
function p.formatCurrentDate() |
| 56 |
return mw.getContentLanguage():formatDate( "s" ) |
| 57 |
end |
| 58 |
function p.formatSpecificDate() |
| 59 |
return mw.getContentLanguage():formatDate( "s", "20130101000000" ) |
| 60 |
end |
| 61 |
return p |
| 62 |
'; |
| 63 |
|
| 64 |
$title = Title::makeTitle( NS_MODULE, 'FormatDate' ); |
| 65 |
$module = $engine->fetchModuleFromParser( $title ); |
| 66 |
|
| 67 |
$frame = $pp->newFrame(); |
| 68 |
$module->invoke( 'formatCurrentDate', $frame ); |
| 69 |
$this->assertSame( 1, $frame->getTTL(), |
| 70 |
'TTL must be equal to 1 second when lang:formatDate( \'s\' ) is called' ); |
| 71 |
|
| 72 |
$frame = $pp->newFrame(); |
| 73 |
$module->invoke( 'formatSpecificDate', $frame ); |
| 74 |
$this->assertNull( $frame->getTTL(), |
| 75 |
'TTL must not be set when lang:formatDate is called with a specific date' ); |
| 76 |
} |
| 77 |
} |