Remove "Squiz.WhiteSpace.FunctionSpacing" from phpcs exclusions
[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 /**
20 * @covers LanguageUz
21 * @covers UzConverter
22 */
23 class LanguageUzTest extends LanguageClassesTestCase {
24
25 /**
26 * @author Nikola Smolenski
27 * @covers LanguageConverter::convertTo
28 */
29 public function testConversionToCyrillic() {
30 // A convertion of Latin to Cyrillic
31 $this->assertEquals( 'абвгғ',
32 $this->convertToCyrillic( 'abvggʻ' )
33 );
34 // Same as above, but assert that -{}-s must be removed and not converted
35 $this->assertEquals( 'ljабnjвгўоdb',
36 $this->convertToCyrillic( '-{lj}-ab-{nj}-vgoʻo-{db}-' )
37 );
38 // A simple convertion of Cyrillic to Cyrillic
39 $this->assertEquals( 'абвг',
40 $this->convertToCyrillic( 'абвг' )
41 );
42 // Same as above, but assert that -{}-s must be removed and not converted
43 $this->assertEquals( 'ljабnjвгdaž',
44 $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{da}-ž' )
45 );
46 }
47
48 /**
49 * @covers LanguageConverter::convertTo
50 */
51 public 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 /**
65 * Wrapper to verify text stay the same after applying conversion
66 * @param string $text Text to convert
67 * @param string $variant Language variant 'uz-cyrl' or 'uz-latn'
68 * @param string $msg Optional message
69 */
70 protected function assertUnConverted( $text, $variant, $msg = '' ) {
71 $this->assertEquals(
72 $text,
73 $this->convertTo( $text, $variant ),
74 $msg
75 );
76 }
77
78 /**
79 * Wrapper to verify a text is different once converted to a variant.
80 * @param string $text Text to convert
81 * @param string $variant Language variant 'uz-cyrl' or 'uz-latn'
82 * @param string $msg Optional message
83 */
84 protected function assertConverted( $text, $variant, $msg = '' ) {
85 $this->assertNotEquals(
86 $text,
87 $this->convertTo( $text, $variant ),
88 $msg
89 );
90 }
91
92 /**
93 * Verifiy the given Cyrillic text is not converted when using
94 * using the Cyrillic variant and converted to Latin when using
95 * the Latin variant.
96 * @param string $text Text to convert
97 * @param string $msg Optional message
98 */
99 protected function assertCyrillic( $text, $msg = '' ) {
100 $this->assertUnConverted( $text, 'uz-cyrl', $msg );
101 $this->assertConverted( $text, 'uz-latn', $msg );
102 }
103
104 /**
105 * Verifiy the given Latin text is not converted when using
106 * using the Latin variant and converted to Cyrillic when using
107 * the Cyrillic variant.
108 * @param string $text Text to convert
109 * @param string $msg Optional message
110 */
111 protected function assertLatin( $text, $msg = '' ) {
112 $this->assertUnConverted( $text, 'uz-latn', $msg );
113 $this->assertConverted( $text, 'uz-cyrl', $msg );
114 }
115
116 /** Wrapper for converter::convertTo() method*/
117 protected function convertTo( $text, $variant ) {
118 return $this->getLang()->mConverter->convertTo( $text, $variant );
119 }
120
121 protected function convertToCyrillic( $text ) {
122 return $this->convertTo( $text, 'uz-cyrl' );
123 }
124
125 protected function convertToLatin( $text ) {
126 return $this->convertTo( $text, 'uz-latn' );
127 }
128 }