MediaWiki  REL1_31
LanguageSrTest.php
Go to the documentation of this file.
1 <?php
27  public function testEasyConversions() {
28  $this->assertCyrillic(
29  'шђчћжШЂЧЋЖ',
30  'Cyrillic guessing characters'
31  );
32  $this->assertLatin(
33  'šđč枊ĐČĆŽ',
34  'Latin guessing characters'
35  );
36  }
37 
41  public function testMixedConversions() {
42  $this->assertCyrillic(
43  'шђчћжШЂЧЋЖ - šđčćž',
44  'Mostly cyrillic characters'
45  );
46  $this->assertLatin(
47  'šđč枊ĐČĆŽ - шђчћж',
48  'Mostly latin characters'
49  );
50  }
51 
56  $this->assertConverted(
57  '4 latin: šđčć | 4 cyrillic: шђчћ',
58  'sr-ec'
59  );
60  $this->assertConverted(
61  '4 latin: šđčć | 4 cyrillic: шђчћ',
62  'sr-el'
63  );
64  }
65 
70  public function testConversionToCyrillic() {
71  // A simple convertion of Latin to Cyrillic
72  $this->assertEquals( 'абвг',
73  $this->convertToCyrillic( 'abvg' )
74  );
75  // Same as above, but assert that -{}-s must be removed and not converted
76  $this->assertEquals( 'ljабnjвгdž',
77  $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
78  );
79  // A simple convertion of Cyrillic to Cyrillic
80  $this->assertEquals( 'абвг',
81  $this->convertToCyrillic( 'абвг' )
82  );
83  // Same as above, but assert that -{}-s must be removed and not converted
84  $this->assertEquals( 'ljабnjвгdž',
85  $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
86  );
87  // This text has some Latin, but is recognized as Cyrillic, so it should not be converted
88  $this->assertEquals( 'abvgшђжчћ',
89  $this->convertToCyrillic( 'abvgшђжчћ' )
90  );
91  // Same as above, but assert that -{}-s must be removed
92  $this->assertEquals( 'љabvgњшђжчћџ',
93  $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
94  );
95  // This text has some Cyrillic, but is recognized as Latin, so it should be converted
96  $this->assertEquals( 'абвгшђжчћ',
97  $this->convertToCyrillic( 'абвгšđžčć' )
98  );
99  // Same as above, but assert that -{}-s must be removed and not converted
100  $this->assertEquals( 'ljабвгnjшђжчћdž',
101  $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
102  );
103  // Roman numerals are not converted
104  $this->assertEquals( 'а I б II в III г IV шђжчћ',
105  $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
106  );
107  }
108 
112  public function testConversionToLatin() {
113  // A simple convertion of Latin to Latin
114  $this->assertEquals( 'abcd',
115  $this->convertToLatin( 'abcd' )
116  );
117  // A simple convertion of Cyrillic to Latin
118  $this->assertEquals( 'abcd',
119  $this->convertToLatin( 'абцд' )
120  );
121  // This text has some Latin, but is recognized as Cyrillic, so it should be converted
122  $this->assertEquals( 'abcdšđžčć',
123  $this->convertToLatin( 'abcdшђжчћ' )
124  );
125  // This text has some Cyrillic, but is recognized as Latin, so it should not be converted
126  $this->assertEquals( 'абцдšđžčć',
127  $this->convertToLatin( 'абцдšđžčć' )
128  );
129  }
130 
135  public function testPlural( $result, $value ) {
136  $forms = [ 'one', 'few', 'other' ];
137  $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
138  }
139 
144  public function testGetPluralRuleType( $result, $value ) {
145  $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
146  }
147 
148  public static function providePlural() {
149  return [
150  [ 'one', 1 ],
151  [ 'other', 11 ],
152  [ 'one', 91 ],
153  [ 'one', 121 ],
154  [ 'few', 2 ],
155  [ 'few', 3 ],
156  [ 'few', 4 ],
157  [ 'few', 334 ],
158  [ 'other', 5 ],
159  [ 'other', 15 ],
160  [ 'other', 120 ],
161  ];
162  }
163 
168  public function testPluralTwoForms( $result, $value ) {
169  $forms = [ 'one', 'other' ];
170  $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
171  }
172 
173  public static function providePluralTwoForms() {
174  return [
175  [ 'one', 1 ],
176  [ 'other', 11 ],
177  [ 'other', 4 ],
178  [ 'one', 91 ],
179  [ 'one', 121 ],
180  ];
181  }
182 
183  # #### HELPERS #####################################################
184 
190  protected function assertUnConverted( $text, $variant, $msg = '' ) {
191  $this->assertEquals(
192  $text,
193  $this->convertTo( $text, $variant ),
194  $msg
195  );
196  }
197 
204  protected function assertConverted( $text, $variant, $msg = '' ) {
205  $this->assertNotEquals(
206  $text,
207  $this->convertTo( $text, $variant ),
208  $msg
209  );
210  }
211 
219  protected function assertCyrillic( $text, $msg = '' ) {
220  $this->assertUnConverted( $text, 'sr-ec', $msg );
221  $this->assertConverted( $text, 'sr-el', $msg );
222  }
223 
231  protected function assertLatin( $text, $msg = '' ) {
232  $this->assertUnConverted( $text, 'sr-el', $msg );
233  $this->assertConverted( $text, 'sr-ec', $msg );
234  }
235 
237  protected function convertTo( $text, $variant ) {
238  return $this->getLang()
239  ->mConverter
240  ->convertTo(
241  $text, $variant
242  );
243  }
244 
245  protected function convertToCyrillic( $text ) {
246  return $this->convertTo( $text, 'sr-ec' );
247  }
248 
249  protected function convertToLatin( $text ) {
250  return $this->convertTo( $text, 'sr-el' );
251  }
252 }
LanguageSrTest\testPluralTwoForms
testPluralTwoForms( $result, $value)
providePluralTwoForms Language::convertPlural
Definition: LanguageSrTest.php:168
LanguageSrTest\testSameAmountOfLatinAndCyrillicGetConverted
testSameAmountOfLatinAndCyrillicGetConverted()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:55
LanguageClassesTestCase
Helping class to run tests using a clean language instance.
Definition: LanguageClassesTestCase.php:21
LanguageClassesTestCase\getLang
getLang()
Definition: LanguageClassesTestCase.php:41
LanguageSrTest\assertCyrillic
assertCyrillic( $text, $msg='')
Verifiy the given Cyrillic text is not converted when using using the cyrillic variant and converted ...
Definition: LanguageSrTest.php:219
LanguageSrTest\testConversionToCyrillic
testConversionToCyrillic()
Definition: LanguageSrTest.php:70
LanguageSrTest\convertToLatin
convertToLatin( $text)
Definition: LanguageSrTest.php:249
$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. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. '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 '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 '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 '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. '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 IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() '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 Sanitizer::validateEmail(), 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. '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) '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 '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:Array with elements of the form "language:title" in the order that they will be output. & $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. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. 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:1993
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
LanguageSrTest\testGetPluralRuleType
testGetPluralRuleType( $result, $value)
providePlural Language::getPluralRuleType
Definition: LanguageSrTest.php:144
LanguageSrTest\testConversionToLatin
testConversionToLatin()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:112
LanguageSrTest\testEasyConversions
testEasyConversions()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:27
LanguageSrTest\testPlural
testPlural( $result, $value)
providePlural Language::convertPlural
Definition: LanguageSrTest.php:135
$value
$value
Definition: styleTest.css.php:45
LanguageSrTest\providePlural
static providePlural()
Definition: LanguageSrTest.php:148
LanguageSrTest\assertLatin
assertLatin( $text, $msg='')
Verifiy the given Latin text is not converted when using using the Latin variant and converted to Cyr...
Definition: LanguageSrTest.php:231
LanguageSrTest\assertConverted
assertConverted( $text, $variant, $msg='')
Wrapper to verify a text is different once converted to a variant.
Definition: LanguageSrTest.php:204
LanguageSrTest\assertUnConverted
assertUnConverted( $text, $variant, $msg='')
Wrapper to verify text stay the same after applying conversion.
Definition: LanguageSrTest.php:190
LanguageSrTest\testMixedConversions
testMixedConversions()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:41
LanguageSrTest
LanguageSr SrConverter.
Definition: LanguageSrTest.php:23
LanguageSrTest\convertToCyrillic
convertToCyrillic( $text)
Definition: LanguageSrTest.php:245
LanguageSrTest\providePluralTwoForms
static providePluralTwoForms()
Definition: LanguageSrTest.php:173
LanguageSrTest\convertTo
convertTo( $text, $variant)
Wrapper for converter::convertTo() method.
Definition: LanguageSrTest.php:237