MediaWiki  1.34.0
LanguageLibraryTest.php
Go to the documentation of this file.
1 <?php
2 
7  protected static $moduleName = 'LanguageLibraryTests';
8 
9  public function __construct(
10  $name = null, array $data = [], $dataName = '', $engineName = null
11  ) {
12  parent::__construct( $name, $data, $dataName, $engineName );
13 
14  // Skip certain tests if something isn't providing translated language names
15  // (bug 67343)
16  if ( Language::fetchLanguageName( 'en', 'fr' ) === 'English' ) {
17  $msg = 'Language name translations are unavailable; ' .
18  'install Extension:CLDR or something similar';
19  $this->skipTests += [
20  'fetchLanguageName (en,ru)' => $msg,
21  'fetchLanguageName (ru,en)' => $msg,
22  'fetchLanguageNames (de)' => $msg,
23  'fetchLanguageNames ([[bogus]])' => $msg,
24  ];
25  }
26  }
27 
28  protected function getTestModules() {
29  return parent::getTestModules() + [
30  'LanguageLibraryTests' => __DIR__ . '/LanguageLibraryTests.lua',
31  ];
32  }
33 
34  public function testFormatDateTTLs() {
35  global $wgContLang;
36 
37  $engine = $this->getEngine();
38  $pp = $engine->getParser()->getPreprocessor();
39 
40  $ttl = null;
41  $wgContLang->sprintfDate( 's', '20130101000000', null, $ttl );
42  if ( $ttl === null ) {
43  $this->markTestSkipped( "Language::sprintfDate does not set a TTL" );
44  }
45 
46  // sprintfDate has its own unit tests for making sure its output is right,
47  // so all we need to test here is we get TTLs when we're supposed to
48  $this->extraModules['Module:FormatDate'] = '
49  local p = {}
50  function p.formatCurrentDate()
51  return mw.getContentLanguage():formatDate( "s" )
52  end
53  function p.formatSpecificDate()
54  return mw.getContentLanguage():formatDate( "s", "20130101000000" )
55  end
56  return p
57  ';
58 
59  $title = Title::makeTitle( NS_MODULE, 'FormatDate' );
60  $module = $engine->fetchModuleFromParser( $title );
61 
62  $frame = $pp->newFrame();
63  $module->invoke( 'formatCurrentDate', $frame );
64  $this->assertEquals( 1, $frame->getTTL(),
65  'TTL must be equal to 1 second when lang:formatDate( \'s\' ) is called' );
66 
67  $frame = $pp->newFrame();
68  $module->invoke( 'formatSpecificDate', $frame );
69  $this->assertNull( $frame->getTTL(),
70  'TTL must not be set when lang:formatDate is called with a specific date' );
71  }
72 }
Language\fetchLanguageName
static fetchLanguageName( $code, $inLanguage=self::AS_AUTONYMS, $include=self::ALL)
Definition: Language.php:832
Scribunto_LuaLanguageLibraryTest\getTestModules
getTestModules()
Definition: LanguageLibraryTest.php:28
Scribunto_LuaEngineUnitTestBase
This is the subclass for Lua library tests.
Definition: LuaEngineUnitTestBase.php:12
NS_MODULE
const NS_MODULE
Definition: Scribunto.constants.php:5
Scribunto_LuaLanguageLibraryTest\__construct
__construct( $name=null, array $data=[], $dataName='', $engineName=null)
Definition: LanguageLibraryTest.php:9
Scribunto_LuaEngineUnitTestBase\$engine
$engine
Definition: LuaEngineUnitTestBase.php:19
$title
$title
Definition: testCompression.php:34
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
Scribunto_LuaLanguageLibraryTest\$moduleName
static $moduleName
Definition: LanguageLibraryTest.php:7
Scribunto_LuaEngineUnitTestBase\$engineName
$engineName
Definition: LuaEngineUnitTestBase.php:18
Scribunto_LuaLanguageLibraryTest
@covers Scribunto_LuaLanguageLibrary
Definition: LanguageLibraryTest.php:6
getEngine
getEngine()
Definition: LuaEngineTestHelper.php:109
Scribunto_LuaLanguageLibraryTest\testFormatDateTTLs
testFormatDateTTLs()
Definition: LanguageLibraryTest.php:34
$wgContLang
$wgContLang
Definition: Setup.php:801