4881103ffb5faeba7a764c0e752095abbcb963c4
[lhc/web/wiklou.git] / tests / phpunit / languages / classes / 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 * @todo methods in test class should be tidied:
15 * - Should be split into separate test methods and data providers
16 * - Tests for LanguageConverter and Language should probably be separate..
17 */
18
19 /** Tests for MediaWiki languages/LanguageUz.php */
20 class LanguageUzTest extends LanguageClassesTestCase {
21
22 /**
23 * @author Nikola Smolenski
24 * @covers LanguageConverter::convertTo
25 */
26 public function testConversionToCyrillic() {
27 // A convertion of Latin to Cyrillic
28 $this->assertEquals( 'абвгғ',
29 $this->convertToCyrillic( 'abvggʻ' )
30 );
31 // Same as above, but assert that -{}-s must be removed and not converted
32 $this->assertEquals( 'ljабnjвгўоdb',
33 $this->convertToCyrillic( '-{lj}-ab-{nj}-vgoʻo-{db}-' )
34 );
35 // A simple convertion of Cyrillic to Cyrillic
36 $this->assertEquals( 'абвг',
37 $this->convertToCyrillic( 'абвг' )
38 );
39 // Same as above, but assert that -{}-s must be removed and not converted
40 $this->assertEquals( 'ljабnjвгdaž',
41 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{da}-ž' )
42 );
43 }
44
45 /**
46 * @covers LanguageConverter::convertTo
47 */
48 public function testConversionToLatin() {
49 // A simple convertion of Latin to Latin
50 $this->assertEquals( 'abdef',
51 $this->convertToLatin( 'abdef' )
52 );
53 // A convertion of Cyrillic to Latin
54 $this->assertEquals( 'gʻabtsdOʻQyo',
55 $this->convertToLatin( 'ғабцдЎҚё' )
56 );
57 }
58
59 ##### HELPERS #####################################################
60 /**
61 * Wrapper to verify text stay the same after applying conversion
62 * @param string $text Text to convert
63 * @param string $variant Language variant 'uz-cyrl' or 'uz-latn'
64 * @param string $msg Optional message
65 */
66 protected function assertUnConverted( $text, $variant, $msg = '' ) {
67 $this->assertEquals(
68 $text,
69 $this->convertTo( $text, $variant ),
70 $msg
71 );
72 }
73
74 /**
75 * Wrapper to verify a text is different once converted to a variant.
76 * @param string $text Text to convert
77 * @param string $variant Language variant 'uz-cyrl' or 'uz-latn'
78 * @param string $msg Optional message
79 */
80 protected function assertConverted( $text, $variant, $msg = '' ) {
81 $this->assertNotEquals(
82 $text,
83 $this->convertTo( $text, $variant ),
84 $msg
85 );
86 }
87
88 /**
89 * Verifiy the given Cyrillic text is not converted when using
90 * using the cyrillic variant and converted to Latin when using
91 * the Latin variant.
92 * @param string $text Text to convert
93 * @param string $msg Optional message
94 */
95 protected function assertCyrillic( $text, $msg = '' ) {
96 $this->assertUnConverted( $text, 'uz-cyrl', $msg );
97 $this->assertConverted( $text, 'uz-latn', $msg );
98 }
99
100 /**
101 * Verifiy the given Latin text is not converted when using
102 * using the Latin variant and converted to Cyrillic when using
103 * the Cyrillic variant.
104 * @param string $text Text to convert
105 * @param string $msg Optional message
106 */
107 protected function assertLatin( $text, $msg = '' ) {
108 $this->assertUnConverted( $text, 'uz-latn', $msg );
109 $this->assertConverted( $text, 'uz-cyrl', $msg );
110 }
111
112 /** Wrapper for converter::convertTo() method*/
113 protected function convertTo( $text, $variant ) {
114 return $this->getLang()->mConverter->convertTo( $text, $variant );
115 }
116
117 protected function convertToCyrillic( $text ) {
118 return $this->convertTo( $text, 'uz-cyrl' );
119 }
120
121 protected function convertToLatin( $text ) {
122 return $this->convertTo( $text, 'uz-latn' );
123 }
124 }