MediaWiki  1.33.0
LanguageSrTest.php
Go to the documentation of this file.
1 <?php
27  public function testHasVariants() {
28  $this->assertTrue( $this->getLang()->hasVariants(), 'sr has variants' );
29  }
30 
34  public function testHasVariant() {
35  $langs = [
36  'sr' => $this->getLang(),
37  'sr-ec' => Language::factory( 'sr-ec' ),
38  'sr-cyrl' => Language::factory( 'sr-cyrl' ),
39  ];
40  foreach ( $langs as $code => $l ) {
41  $p = $l->getParentLanguage();
42  $this->assertTrue( $p !== null, 'parent language exists' );
43  $this->assertEquals( 'sr', $p->getCode(), 'sr is parent language' );
44  $this->assertTrue( $p instanceof LanguageSr, 'parent is LanguageSr' );
45  // This is a valid variant of the base
46  $this->assertTrue( $p->hasVariant( $l->getCode() ) );
47  // This test should be tweaked if/when sr-ec is renamed (T117845)
48  // to swap the roles of sr-ec and sr-Cyrl
49  $this->assertTrue( $l->hasVariant( 'sr-ec' ), 'sr-ec exists' );
50  // note that sr-cyrl is an alias, not a (strict) variant name
51  foreach ( [ 'sr-EC', 'sr-Cyrl', 'sr-cyrl', 'sr-bogus' ] as $v ) {
52  $this->assertFalse( $l->hasVariant( $v ), "$v is not a variant of $code" );
53  }
54  }
55  }
56 
60  public function testHasVariantBogus() {
61  $langs = [
62  // Note that case matters when calling Language::factory();
63  // these are all bogus language codes
64  'sr-EC' => Language::factory( 'sr-EC' ),
65  'sr-Cyrl' => Language::factory( 'sr-Cyrl' ),
66  'sr-bogus' => Language::factory( 'sr-bogus' ),
67  ];
68  foreach ( $langs as $code => $l ) {
69  $p = $l->getParentLanguage();
70  $this->assertTrue( $p === null, 'no parent for bogus language' );
71  $this->assertFalse( $l instanceof LanguageSr, "$code is not sr" );
72  $this->assertFalse( $this->getLang()->hasVariant( $code ), "$code is not a sr variant" );
73  foreach ( [ 'sr', 'sr-ec', 'sr-EC', 'sr-Cyrl', 'sr-cyrl', 'sr-bogus' ] as $v ) {
74  if ( $v !== $code ) {
75  $this->assertFalse( $l->hasVariant( $v ), "no variant $v" );
76  }
77  }
78  }
79  }
80 
84  public function testEasyConversions() {
85  $this->assertCyrillic(
86  'шђчћжШЂЧЋЖ',
87  'Cyrillic guessing characters'
88  );
89  $this->assertLatin(
90  'šđč枊ĐČĆŽ',
91  'Latin guessing characters'
92  );
93  }
94 
98  public function testMixedConversions() {
99  $this->assertCyrillic(
100  'шђчћжШЂЧЋЖ - šđčćž',
101  'Mostly Cyrillic characters'
102  );
103  $this->assertLatin(
104  'šđč枊ĐČĆŽ - шђчћж',
105  'Mostly Latin characters'
106  );
107  }
108 
113  $this->assertConverted(
114  '4 Latin: šđčć | 4 Cyrillic: шђчћ',
115  'sr-ec'
116  );
117  $this->assertConverted(
118  '4 Latin: šđčć | 4 Cyrillic: шђчћ',
119  'sr-el'
120  );
121  }
122 
127  public function testConversionToCyrillic() {
128  // A simple conversion of Latin to Cyrillic
129  $this->assertEquals( 'абвг',
130  $this->convertToCyrillic( 'abvg' )
131  );
132  // Same as above, but assert that -{}-s must be removed and not converted
133  $this->assertEquals( 'ljабnjвгdž',
134  $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
135  );
136  // A simple conversion of Cyrillic to Cyrillic
137  $this->assertEquals( 'абвг',
138  $this->convertToCyrillic( 'абвг' )
139  );
140  // Same as above, but assert that -{}-s must be removed and not converted
141  $this->assertEquals( 'ljабnjвгdž',
142  $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
143  );
144  // This text has some Latin, but is recognized as Cyrillic, so it should not be converted
145  $this->assertEquals( 'abvgшђжчћ',
146  $this->convertToCyrillic( 'abvgшђжчћ' )
147  );
148  // Same as above, but assert that -{}-s must be removed
149  $this->assertEquals( 'љabvgњшђжчћџ',
150  $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
151  );
152  // This text has some Cyrillic, but is recognized as Latin, so it should be converted
153  $this->assertEquals( 'абвгшђжчћ',
154  $this->convertToCyrillic( 'абвгšđžčć' )
155  );
156  // Same as above, but assert that -{}-s must be removed and not converted
157  $this->assertEquals( 'ljабвгnjшђжчћdž',
158  $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
159  );
160  // Roman numerals are not converted
161  $this->assertEquals( 'а I б II в III г IV шђжчћ',
162  $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
163  );
164  }
165 
169  public function testConversionToLatin() {
170  // A simple conversion of Latin to Latin
171  $this->assertEquals( 'abcd',
172  $this->convertToLatin( 'abcd' )
173  );
174  // A simple conversion of Cyrillic to Latin
175  $this->assertEquals( 'abcd',
176  $this->convertToLatin( 'абцд' )
177  );
178  // This text has some Latin, but is recognized as Cyrillic, so it should be converted
179  $this->assertEquals( 'abcdšđžčć',
180  $this->convertToLatin( 'abcdшђжчћ' )
181  );
182  // This text has some Cyrillic, but is recognized as Latin, so it should not be converted
183  $this->assertEquals( 'абцдšđžčć',
184  $this->convertToLatin( 'абцдšđžčć' )
185  );
186  }
187 
192  public function testPlural( $result, $value ) {
193  $forms = [ 'one', 'few', 'other' ];
194  $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
195  }
196 
201  public function testGetPluralRuleType( $result, $value ) {
202  $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
203  }
204 
205  public static function providePlural() {
206  return [
207  [ 'one', 1 ],
208  [ 'other', 11 ],
209  [ 'one', 91 ],
210  [ 'one', 121 ],
211  [ 'few', 2 ],
212  [ 'few', 3 ],
213  [ 'few', 4 ],
214  [ 'few', 334 ],
215  [ 'other', 5 ],
216  [ 'other', 15 ],
217  [ 'other', 120 ],
218  ];
219  }
220 
225  public function testPluralTwoForms( $result, $value ) {
226  $forms = [ 'one', 'other' ];
227  $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
228  }
229 
230  public static function providePluralTwoForms() {
231  return [
232  [ 'one', 1 ],
233  [ 'other', 11 ],
234  [ 'other', 4 ],
235  [ 'one', 91 ],
236  [ 'one', 121 ],
237  ];
238  }
239 
240  # #### HELPERS #####################################################
241 
247  protected function assertUnConverted( $text, $variant, $msg = '' ) {
248  $this->assertEquals(
249  $text,
250  $this->convertTo( $text, $variant ),
251  $msg
252  );
253  }
254 
261  protected function assertConverted( $text, $variant, $msg = '' ) {
262  $this->assertNotEquals(
263  $text,
264  $this->convertTo( $text, $variant ),
265  $msg
266  );
267  }
268 
276  protected function assertCyrillic( $text, $msg = '' ) {
277  $this->assertUnConverted( $text, 'sr-ec', $msg );
278  $this->assertConverted( $text, 'sr-el', $msg );
279  }
280 
288  protected function assertLatin( $text, $msg = '' ) {
289  $this->assertUnConverted( $text, 'sr-el', $msg );
290  $this->assertConverted( $text, 'sr-ec', $msg );
291  }
292 
294  protected function convertTo( $text, $variant ) {
295  return $this->getLang()
296  ->mConverter
297  ->convertTo(
298  $text, $variant
299  );
300  }
301 
302  protected function convertToCyrillic( $text ) {
303  return $this->convertTo( $text, 'sr-ec' );
304  }
305 
306  protected function convertToLatin( $text ) {
307  return $this->convertTo( $text, 'sr-el' );
308  }
309 }
LanguageSrTest\testPluralTwoForms
testPluralTwoForms( $result, $value)
providePluralTwoForms Language::convertPlural
Definition: LanguageSrTest.php:225
LanguageSrTest\testSameAmountOfLatinAndCyrillicGetConverted
testSameAmountOfLatinAndCyrillicGetConverted()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:112
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:276
$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. 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. '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 '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 since 1.28! 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:1983
LanguageSrTest\testConversionToCyrillic
testConversionToCyrillic()
Definition: LanguageSrTest.php:127
LanguageSrTest\convertToLatin
convertToLatin( $text)
Definition: LanguageSrTest.php:306
LanguageSrTest\testHasVariantBogus
testHasVariantBogus()
Language::hasVariant.
Definition: LanguageSrTest.php:60
LanguageSrTest\testHasVariant
testHasVariant()
Language::hasVariant.
Definition: LanguageSrTest.php:34
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:35
LanguageSrTest\testGetPluralRuleType
testGetPluralRuleType( $result, $value)
providePlural Language::getPluralRuleType
Definition: LanguageSrTest.php:201
LanguageSrTest\testConversionToLatin
testConversionToLatin()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:169
LanguageSrTest\testEasyConversions
testEasyConversions()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:84
LanguageSrTest\testPlural
testPlural( $result, $value)
providePlural Language::convertPlural
Definition: LanguageSrTest.php:192
$code
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:780
LanguageSr
Serbian (Српски / Srpski)
Definition: LanguageSr.php:174
$value
$value
Definition: styleTest.css.php:49
LanguageSrTest\providePlural
static providePlural()
Definition: LanguageSrTest.php:205
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:288
LanguageSrTest\assertConverted
assertConverted( $text, $variant, $msg='')
Wrapper to verify a text is different once converted to a variant.
Definition: LanguageSrTest.php:261
LanguageSrTest\assertUnConverted
assertUnConverted( $text, $variant, $msg='')
Wrapper to verify text stay the same after applying conversion.
Definition: LanguageSrTest.php:247
LanguageSrTest\testMixedConversions
testMixedConversions()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:98
LanguageSrTest\testHasVariants
testHasVariants()
Language::hasVariants.
Definition: LanguageSrTest.php:27
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
LanguageSrTest
LanguageSr SrConverter.
Definition: LanguageSrTest.php:23
LanguageSrTest\convertToCyrillic
convertToCyrillic( $text)
Definition: LanguageSrTest.php:302
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:215
LanguageSrTest\providePluralTwoForms
static providePluralTwoForms()
Definition: LanguageSrTest.php:230
LanguageSrTest\convertTo
convertTo( $text, $variant)
Wrapper for converter::convertTo() method.
Definition: LanguageSrTest.php:294