MediaWiki  1.30.0
LanguageSrTest.php
Go to the documentation of this file.
1 <?php
24  public function testEasyConversions() {
25  $this->assertCyrillic(
26  'шђчћжШЂЧЋЖ',
27  'Cyrillic guessing characters'
28  );
29  $this->assertLatin(
30  'šđč枊ĐČĆŽ',
31  'Latin guessing characters'
32  );
33  }
34 
38  public function testMixedConversions() {
39  $this->assertCyrillic(
40  'шђчћжШЂЧЋЖ - šđčćž',
41  'Mostly cyrillic characters'
42  );
43  $this->assertLatin(
44  'šđč枊ĐČĆŽ - шђчћж',
45  'Mostly latin characters'
46  );
47  }
48 
53  $this->assertConverted(
54  '4 latin: šđčć | 4 cyrillic: шђчћ',
55  'sr-ec'
56  );
57  $this->assertConverted(
58  '4 latin: šđčć | 4 cyrillic: шђчћ',
59  'sr-el'
60  );
61  }
62 
67  public function testConversionToCyrillic() {
68  // A simple convertion of Latin to Cyrillic
69  $this->assertEquals( 'абвг',
70  $this->convertToCyrillic( 'abvg' )
71  );
72  // Same as above, but assert that -{}-s must be removed and not converted
73  $this->assertEquals( 'ljабnjвгdž',
74  $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
75  );
76  // A simple convertion of Cyrillic to Cyrillic
77  $this->assertEquals( 'абвг',
78  $this->convertToCyrillic( 'абвг' )
79  );
80  // Same as above, but assert that -{}-s must be removed and not converted
81  $this->assertEquals( 'ljабnjвгdž',
82  $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
83  );
84  // This text has some Latin, but is recognized as Cyrillic, so it should not be converted
85  $this->assertEquals( 'abvgшђжчћ',
86  $this->convertToCyrillic( 'abvgшђжчћ' )
87  );
88  // Same as above, but assert that -{}-s must be removed
89  $this->assertEquals( 'љabvgњшђжчћџ',
90  $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
91  );
92  // This text has some Cyrillic, but is recognized as Latin, so it should be converted
93  $this->assertEquals( 'абвгшђжчћ',
94  $this->convertToCyrillic( 'абвгšđžčć' )
95  );
96  // Same as above, but assert that -{}-s must be removed and not converted
97  $this->assertEquals( 'ljабвгnjшђжчћdž',
98  $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-' )
99  );
100  // Roman numerals are not converted
101  $this->assertEquals( 'а I б II в III г IV шђжчћ',
102  $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
103  );
104  }
105 
109  public function testConversionToLatin() {
110  // A simple convertion of Latin to Latin
111  $this->assertEquals( 'abcd',
112  $this->convertToLatin( 'abcd' )
113  );
114  // A simple convertion of Cyrillic to Latin
115  $this->assertEquals( 'abcd',
116  $this->convertToLatin( 'абцд' )
117  );
118  // This text has some Latin, but is recognized as Cyrillic, so it should be converted
119  $this->assertEquals( 'abcdšđžčć',
120  $this->convertToLatin( 'abcdшђжчћ' )
121  );
122  // This text has some Cyrillic, but is recognized as Latin, so it should not be converted
123  $this->assertEquals( 'абцдšđžčć',
124  $this->convertToLatin( 'абцдšđžčć' )
125  );
126  }
127 
132  public function testPlural( $result, $value ) {
133  $forms = [ 'one', 'few', 'other' ];
134  $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
135  }
136 
141  public function testGetPluralRuleType( $result, $value ) {
142  $this->assertEquals( $result, $this->getLang()->getPluralRuleType( $value ) );
143  }
144 
145  public static function providePlural() {
146  return [
147  [ 'one', 1 ],
148  [ 'other', 11 ],
149  [ 'one', 91 ],
150  [ 'one', 121 ],
151  [ 'few', 2 ],
152  [ 'few', 3 ],
153  [ 'few', 4 ],
154  [ 'few', 334 ],
155  [ 'other', 5 ],
156  [ 'other', 15 ],
157  [ 'other', 120 ],
158  ];
159  }
160 
165  public function testPluralTwoForms( $result, $value ) {
166  $forms = [ 'one', 'other' ];
167  $this->assertEquals( $result, $this->getLang()->convertPlural( $value, $forms ) );
168  }
169 
170  public static function providePluralTwoForms() {
171  return [
172  [ 'one', 1 ],
173  [ 'other', 11 ],
174  [ 'other', 4 ],
175  [ 'one', 91 ],
176  [ 'one', 121 ],
177  ];
178  }
179 
180  # #### HELPERS #####################################################
181 
187  protected function assertUnConverted( $text, $variant, $msg = '' ) {
188  $this->assertEquals(
189  $text,
190  $this->convertTo( $text, $variant ),
191  $msg
192  );
193  }
194 
201  protected function assertConverted( $text, $variant, $msg = '' ) {
202  $this->assertNotEquals(
203  $text,
204  $this->convertTo( $text, $variant ),
205  $msg
206  );
207  }
208 
216  protected function assertCyrillic( $text, $msg = '' ) {
217  $this->assertUnConverted( $text, 'sr-ec', $msg );
218  $this->assertConverted( $text, 'sr-el', $msg );
219  }
220 
228  protected function assertLatin( $text, $msg = '' ) {
229  $this->assertUnConverted( $text, 'sr-el', $msg );
230  $this->assertConverted( $text, 'sr-ec', $msg );
231  }
232 
234  protected function convertTo( $text, $variant ) {
235  return $this->getLang()
236  ->mConverter
237  ->convertTo(
238  $text, $variant
239  );
240  }
241 
242  protected function convertToCyrillic( $text ) {
243  return $this->convertTo( $text, 'sr-ec' );
244  }
245 
246  protected function convertToLatin( $text ) {
247  return $this->convertTo( $text, 'sr-el' );
248  }
249 }
LanguageSrTest\testPluralTwoForms
testPluralTwoForms( $result, $value)
providePluralTwoForms Language::convertPlural
Definition: LanguageSrTest.php:165
LanguageSrTest\testSameAmountOfLatinAndCyrillicGetConverted
testSameAmountOfLatinAndCyrillicGetConverted()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:52
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:216
$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 '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:1963
LanguageSrTest\testConversionToCyrillic
testConversionToCyrillic()
Definition: LanguageSrTest.php:67
LanguageSrTest\convertToLatin
convertToLatin( $text)
Definition: LanguageSrTest.php:246
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:141
LanguageSrTest\testConversionToLatin
testConversionToLatin()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:109
LanguageSrTest\testEasyConversions
testEasyConversions()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:24
LanguageSrTest\testPlural
testPlural( $result, $value)
providePlural Language::convertPlural
Definition: LanguageSrTest.php:132
$value
$value
Definition: styleTest.css.php:45
LanguageSrTest\providePlural
static providePlural()
Definition: LanguageSrTest.php:145
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:228
LanguageSrTest\assertConverted
assertConverted( $text, $variant, $msg='')
Wrapper to verify a text is different once converted to a variant.
Definition: LanguageSrTest.php:201
LanguageSrTest\assertUnConverted
assertUnConverted( $text, $variant, $msg='')
Wrapper to verify text stay the same after applying conversion.
Definition: LanguageSrTest.php:187
LanguageSrTest\testMixedConversions
testMixedConversions()
LanguageConverter::convertTo.
Definition: LanguageSrTest.php:38
LanguageSrTest
Tests for MediaWiki languages/LanguageSr.php.
Definition: LanguageSrTest.php:20
LanguageSrTest\convertToCyrillic
convertToCyrillic( $text)
Definition: LanguageSrTest.php:242
LanguageSrTest\providePluralTwoForms
static providePluralTwoForms()
Definition: LanguageSrTest.php:170
LanguageSrTest\convertTo
convertTo( $text, $variant)
Wrapper for converter::convertTo() method.
Definition: LanguageSrTest.php:234