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