MediaWiki REL1_34
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}
const NS_MODULE
$wgContLang
Definition Setup.php:800
This is the subclass for Lua library tests.
@covers Scribunto_LuaLanguageLibrary
__construct( $name=null, array $data=[], $dataName='', $engineName=null)