Debian Codegraph @

tests/phpunit/includes/language/converters/BanConverterTest.php

raw symbols SCIP
1 <?php
2
3 /**
4 * @group Language
5 * @covers \BanConverter
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 // A simple conversion of Latin to Latin
39 $this->assertEquals( 'mantra',
40 $this->convertToLatin( 'mantra' )
41 );
42 // A simple conversion of Balinese to Latin
43 $this->assertEquals( 'mantra',
44 $this->convertToLatin( 'ᬫᬦ᭄ᬢ᭄ᬭ' )
45 );
46 // This text has some Latin, but is recognized as Balinese, so it should be converted
47 $this->assertEquals( 'abcdmantra',
48 $this->convertToLatin( 'abcdᬫᬦ᭄ᬢ᭄ᬭ' )
49 );
50 }
51
52 # #### HELPERS #####################################################
53
54 /**
55 * Wrapper to verify text stay the same after applying conversion
56 * @param string $text Text to convert
57 * @param string $variant Language variant 'ban-bali' or 'ban'
58 * @param string $msg Optional message
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 * Wrapper to verify a text is different once converted to a variant.
70 * @param string $text Text to convert
71 * @param string $variant Language variant 'ban-bali' or 'ban'
72 * @param string $msg Optional message
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 * Verifiy the given Balinese text is not converted when using
84 * using the Balinese variant and converted to Latin when using
85 * the Latin variant.
86 * @param string $text Text to convert
87 * @param string $msg Optional message
88 */
89 protected function assertBalinese( $text, $msg = '' ) {
90 $this->assertUnConverted( $text, 'ban-bali', $msg );
91 $this->assertConverted( $text, 'ban', $msg );
92 }
93
94 /**
95 * Wrapper for converter::convertTo() method
96 * @param string $text
97 * @param string $variant
98 * @return string
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 }