Merge "Made SSL validation in Curl HTTP requests the default."
[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 * Wrapper to verify a text is different once converted to a variant.
69 * @param $text string Text to convert
70 * @param $variant string Language variant 'uz-cyrl' or 'uz-latn'
71 * @param $msg string Optional message
72 */
73 function assertConverted( $text, $variant, $msg = '' ) {
74 $this->assertNotEquals(
75 $text,
76 $this->convertTo( $text, $variant ),
77 $msg
78 );
79 }
80
81 /**
82 * Verifiy the given Cyrillic text is not converted when using
83 * using the cyrillic variant and converted to Latin when using
84 * the Latin variant.
85 */
86 function assertCyrillic( $text, $msg = '' ) {
87 $this->assertUnConverted( $text, 'uz-cyrl', $msg );
88 $this->assertConverted( $text, 'uz-latn', $msg );
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 function convertToCyrillic( $text ) {
106 return $this->convertTo( $text, 'uz-cyrl' );
107 }
108 function convertToLatin( $text ) {
109 return $this->convertTo( $text, 'uz-latn' );
110 }
111 }