| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
class BanConverterTest extends MediaWikiIntegrationTestCase { |
| 8 |
|
| 9 |
use LanguageConverterTestTrait; |
| 10 |
|
| 11 |
public function testHasVariants() { |
| 12 |
$this->assertTrue( $this->getLanguageConverter()->hasVariants(), 'ban has variants' ); |
| 13 |
} |
| 14 |
|
| 15 |
public function testHasVariantBogus() { |
| 16 |
$variants = [ |
| 17 |
'ban-bali', |
| 18 |
'ban-x-dharma', |
| 19 |
'ban-x-palmleaf', |
| 20 |
'ban-x-pku', |
| 21 |
'ban', |
| 22 |
]; |
| 23 |
|
| 24 |
foreach ( $variants as $variant ) { |
| 25 |
$this->assertTrue( $this->getLanguageConverter()->hasVariant( $variant ), |
| 26 |
"no variant for $variant language" ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
public function testBalineseDetection() { |
| 31 |
$this->assertBalinese( |
| 32 |
'ᬫᬦ᭄ᬢ᭄ᬭ - abc', |
| 33 |
'Balinese guessing characters' |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
public function testConversionToLatin() { |
| 38 |
|
| 39 |
$this->assertEquals( 'mantra', |
| 40 |
$this->convertToLatin( 'mantra' ) |
| 41 |
); |
| 42 |
|
| 43 |
$this->assertEquals( 'mantra', |
| 44 |
$this->convertToLatin( 'ᬫᬦ᭄ᬢ᭄ᬭ' ) |
| 45 |
); |
| 46 |
|
| 47 |
$this->assertEquals( 'abcdmantra', |
| 48 |
$this->convertToLatin( 'abcdᬫᬦ᭄ᬢ᭄ᬭ' ) |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
protected function assertUnConverted( $text, $variant, $msg = '' ) { |
| 61 |
$this->assertEquals( |
| 62 |
$text, |
| 63 |
$this->convertTo( $text, $variant ), |
| 64 |
$msg |
| 65 |
); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
protected function assertConverted( $text, $variant, $msg = '' ) { |
| 75 |
$this->assertNotEquals( |
| 76 |
$text, |
| 77 |
$this->convertTo( $text, $variant ), |
| 78 |
$msg |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
protected function assertBalinese( $text, $msg = '' ) { |
| 90 |
$this->assertUnConverted( $text, 'ban-bali', $msg ); |
| 91 |
$this->assertConverted( $text, 'ban', $msg ); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
protected function convertTo( $text, $variant ) { |
| 101 |
return $this->getLanguageConverter()->convertTo( $text, $variant ); |
| 102 |
} |
| 103 |
|
| 104 |
protected function convertToLatin( $text ) { |
| 105 |
return $this->convertTo( $text, 'ban' ); |
| 106 |
} |
| 107 |
} |