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