mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-29 18:44:21 +00:00
780d8e1ec7
When os.date, os.time, or mw.language:formatDate are called, set the appropriate TTL on the output. This needs I412febf3 in core to function at all, and I3f5a80aa in core to function with formatDate. Change-Id: I59ad364d502fc247500d94c5606516ad9f98a24d
53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
class Scribunto_LuaLanguageLibraryTests extends Scribunto_LuaEngineTestBase {
|
|
protected static $moduleName = 'LanguageLibraryTests';
|
|
|
|
function getTestModules() {
|
|
return parent::getTestModules() + array(
|
|
'LanguageLibraryTests' => __DIR__ . '/LanguageLibraryTests.lua',
|
|
);
|
|
}
|
|
|
|
function testFormatDateTTLs() {
|
|
global $wgContLang;
|
|
|
|
$engine = $this->getEngine();
|
|
$pp = $engine->getParser()->getPreprocessor();
|
|
|
|
if ( !is_callable( array( $pp->newFrame(), 'getTTL' ) ) ) {
|
|
$this->markTestSkipped( "PPFrame::getTTL is not available" );
|
|
}
|
|
|
|
$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' );
|
|
}
|
|
}
|