Merge "Fix return types in documentation"
[lhc/web/wiklou.git] / tests / phpunit / languages / LanguageUzTest.php
1 <?php
2 /**
3 * PHPUnit tests for the Uzbek language.
4 * The language can be represented using two scripts:
5 * - Latin (uz-latn)
6 * - Cyrillic (uz-cyrl)
7 *
8 * @author Robin Pepermans
9 * @author Antoine Musso <hashar at free dot fr>
10 * @copyright Copyright © 2012, Robin Pepermans
11 * @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr>
12 * @file
13 */
14
15 /** Tests for MediaWiki languages/LanguageUz.php */
16 class LanguageUzTest extends LanguageClassesTestCase {
17
18 /**
19 * @author Nikola Smolenski
20 */
21 function testConversionToCyrillic() {
22 // A convertion of Latin to Cyrillic
23 $this->assertEquals( 'абвгғ',
24 $this->convertToCyrillic( 'abvggʻ' )
25 );
26 // Same as above, but assert that -{}-s must be removed and not converted
27 $this->assertEquals( 'ljабnjвгўоdb',
28 $this->convertToCyrillic( '-{lj}-ab-{nj}-vgoʻo-{db}-' )
29 );
30 // A simple convertion of Cyrillic to Cyrillic
31 $this->assertEquals( 'абвг',
32 $this->convertToCyrillic( 'абвг' )
33 );
34 // Same as above, but assert that -{}-s must be removed and not converted
35 $this->assertEquals( 'ljабnjвгdaž',
36 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{da}-ž' )
37 );
38 }
39
40 function testConversionToLatin() {
41 // A simple convertion of Latin to Latin
42 $this->assertEquals( 'abdef',
43 $this->convertToLatin( 'abdef' )
44 );
45 // A convertion of Cyrillic to Latin
46 $this->assertEquals( 'gʻabtsdOʻQyo',
47 $this->convertToLatin( 'ғабцдЎҚё' )
48 );
49 }
50
51 ##### HELPERS #####################################################
52 /**
53 * Wrapper to verify text stay the same after applying conversion
54 * @param $text string Text to convert
55 * @param $variant string Language variant 'uz-cyrl' or 'uz-latn'
56 * @param $msg string Optional message
57 */
58 function assertUnConverted( $text, $variant, $msg = '' ) {
59 $this->assertEquals(
60 $text,
61 $this->convertTo( $text, $variant ),
62 $msg
63 );
64 }
65
66 /**
67 * Wrapper to verify a text is different once converted to a variant.
68 * @param $text string Text to convert
69 * @param $variant string Language variant 'uz-cyrl' or 'uz-latn'
70 * @param $msg string Optional message
71 */
72 function assertConverted( $text, $variant, $msg = '' ) {
73 $this->assertNotEquals(
74 $text,
75 $this->convertTo( $text, $variant ),
76 $msg
77 );
78 }
79
80 /**
81 * Verifiy the given Cyrillic text is not converted when using
82 * using the cyrillic variant and converted to Latin when using
83 * the Latin variant.
84 */
85 function assertCyrillic( $text, $msg = '' ) {
86 $this->assertUnConverted( $text, 'uz-cyrl', $msg );
87 $this->assertConverted( $text, 'uz-latn', $msg );
88 }
89
90 /**
91 * Verifiy the given Latin text is not converted when using
92 * using the Latin variant and converted to Cyrillic when using
93 * the Cyrillic variant.
94 */
95 function assertLatin( $text, $msg = '' ) {
96 $this->assertUnConverted( $text, 'uz-latn', $msg );
97 $this->assertConverted( $text, 'uz-cyrl', $msg );
98 }
99
100
101 /** Wrapper for converter::convertTo() method*/
102 function convertTo( $text, $variant ) {
103 return $this->getLang()->mConverter->convertTo( $text, $variant );
104 }
105
106 function convertToCyrillic( $text ) {
107 return $this->convertTo( $text, 'uz-cyrl' );
108 }
109
110 function convertToLatin( $text ) {
111 return $this->convertTo( $text, 'uz-latn' );
112 }
113 }