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