MediaWiki  1.23.2
MessageCacheTest.php
Go to the documentation of this file.
1 <?php
2 
9 
10  protected function setUp() {
11  parent::setUp();
12  $this->configureLanguages();
13  MessageCache::singleton()->enable();
14  }
15 
19  protected function configureLanguages() {
20  // for the test, we need the content language to be anything but English,
21  // let's choose e.g. German (de)
22  $langCode = 'de';
23  $langObj = Language::factory( $langCode );
24 
25  $this->setMwGlobals( array(
26  'wgLanguageCode' => $langCode,
27  'wgLang' => $langObj,
28  'wgContLang' => $langObj,
29  ) );
30  }
31 
32  function addDBData() {
33  $this->configureLanguages();
34 
35  // Set up messages and fallbacks ab -> ru -> de
36  $this->makePage( 'FallbackLanguageTest-Full', 'ab' );
37  $this->makePage( 'FallbackLanguageTest-Full', 'ru' );
38  $this->makePage( 'FallbackLanguageTest-Full', 'de' );
39 
40  // Fallbacks where ab does not exist
41  $this->makePage( 'FallbackLanguageTest-Partial', 'ru' );
42  $this->makePage( 'FallbackLanguageTest-Partial', 'de' );
43 
44  // Fallback to the content language
45  $this->makePage( 'FallbackLanguageTest-ContLang', 'de' );
46 
47  // Add customizations for an existing message.
48  $this->makePage( 'sunday', 'ru' );
49 
50  // Full key tests -- always want russian
51  $this->makePage( 'MessageCacheTest-FullKeyTest', 'ab' );
52  $this->makePage( 'MessageCacheTest-FullKeyTest', 'ru' );
53 
54  // In content language -- get base if no derivative
55  $this->makePage( 'FallbackLanguageTest-NoDervContLang', 'de', 'de/none', false );
56  }
57 
66  protected function makePage( $title, $lang, $content = null, $createSubPage = true ) {
68 
69  if ( $content === null ) {
70  $content = $lang;
71  }
72  if ( $lang !== $wgContLang->getCode() || $createSubPage ) {
73  $title = "$title/$lang";
74  }
75 
77  $wikiPage = new WikiPage( $title );
78  $contentHandler = ContentHandler::makeContent( $content, $title );
79  $wikiPage->doEditContent( $contentHandler, "$lang translation test case" );
80  }
81 
87  public function testMessageFallbacks( $message, $lang, $expectedContent ) {
88  $result = MessageCache::singleton()->get( $message, true, $lang );
89  $this->assertEquals( $expectedContent, $result, "Message fallback failed." );
90  }
91 
93  return array(
94  array( 'FallbackLanguageTest-Full', 'ab', 'ab' ),
95  array( 'FallbackLanguageTest-Partial', 'ab', 'ru' ),
96  array( 'FallbackLanguageTest-ContLang', 'ab', 'de' ),
97  array( 'FallbackLanguageTest-None', 'ab', false ),
98 
99  // Existing message with customizations on the fallbacks
100  array( 'sunday', 'ab', 'амҽыш' ),
101 
102  // bug 46579
103  array( 'FallbackLanguageTest-NoDervContLang', 'de', 'de/none' ),
104  // UI language different from content language should only use de/none as last option
105  array( 'FallbackLanguageTest-NoDervContLang', 'fit', 'de/none' ),
106  );
107  }
108 
115  public function testFullKeyBehaviour( $message, $lang, $expectedContent ) {
116  $result = MessageCache::singleton()->get( $message, true, $lang, true );
117  $this->assertEquals( $expectedContent, $result, "Full key message fallback failed." );
118  }
119 
121  return array(
122  array( 'MessageCacheTest-FullKeyTest/ru', 'ru', 'ru' ),
123  array( 'MessageCacheTest-FullKeyTest/ru', 'ab', 'ru' ),
124  array( 'MessageCacheTest-FullKeyTest/ru/foo', 'ru', false ),
125  );
126  }
127 
128 }
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
MessageCacheTest
@group Database @group Cache @covers MessageCache
Definition: MessageCacheTest.php:8
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:37
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MessageCacheTest\configureLanguages
configureLanguages()
Helper function – setup site language for testing.
Definition: MessageCacheTest.php:19
MessageCacheTest\provideMessagesForFallback
provideMessagesForFallback()
Definition: MessageCacheTest.php:92
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
MessageCacheTest\makePage
makePage( $title, $lang, $content=null, $createSubPage=true)
Helper function for addDBData – adds a simple page to the database.
Definition: MessageCacheTest.php:66
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
MessageCache\singleton
static singleton()
Get the signleton instance of this class.
Definition: MessageCache.php:101
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:144
MessageCacheTest\testMessageFallbacks
testMessageFallbacks( $message, $lang, $expectedContent)
Test message fallbacks, bug #1495.
Definition: MessageCacheTest.php:87
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
MessageCacheTest\setUp
setUp()
Definition: MessageCacheTest.php:10
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
MessageCacheTest\addDBData
addDBData()
Stub.
Definition: MessageCacheTest.php:32
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
MessageCacheTest\testFullKeyBehaviour
testFullKeyBehaviour( $message, $lang, $expectedContent)
There's a fallback case where the message key is given as fully qualified – this should ignore the pa...
Definition: MessageCacheTest.php:115
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:87
MessageCacheTest\provideMessagesForFullKeys
provideMessagesForFullKeys()
Definition: MessageCacheTest.php:120