Debian Codegraph @

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

raw symbols SCIP
1 <?php
2 /**
3 * PHPUnit tests for the Talysh converter.
4 * The language can be represented using two scripts:
5 * - Latin (tly)
6 * - Cyrillic (tly-cyrl)
7 *
8 * @author Amir E. Aharoni
9 */
10
11 /**
12 * @group Language
13 * @covers \MediaWiki\Language\LanguageConverter
14 * @covers \TlyConverter
15 */
16 class TlyConverterTest extends MediaWikiIntegrationTestCase {
17 use LanguageConverterTestTrait;
18
19 public function testConversionToCyrillic() {
20 // A conversion of Latin to Cyrillic
21 $this->assertEquals(
22 'АаБбВвГгҒғДдЕеӘәЖжЗзИиЫыЈјКкЛлМмНнОоПпРрСсТтУуҮүФфХхҺһЧчҸҹШш',
23 $this->convertToCyrillic(
24 'AaBbVvQqĞğDdEeƏəJjZzİiIıYyKkLlMmNnOoPpRrSsTtUuÜüFfXxHhÇçCcŞş'
25 )
26 );
27
28 // A simple conversion of Cyrillic to Cyrillic
29 $this->assertEquals( 'Лик',
30 $this->convertToCyrillic( 'Лик' )
31 );
32
33 // Assert that -{}-s are handled correctly
34 // NB: Latin word followed by Latin word, and the second one is converted
35 $this->assertEquals( 'Lankon Осторо',
36 $this->convertToCyrillic( '-{Lankon}- Ostoro' )
37 );
38
39 // Assert that -{}-s are handled correctly
40 // NB: Latin word followed by Cyrillic word, and nothing is converted
41 $this->assertEquals( 'Lankon Осторо',
42 $this->convertToCyrillic( '-{Lankon}- Осторо' )
43 );
44 }
45
46 public function testConversionToLatin() {
47 // A conversion of Cyrillic to Latin
48 $this->assertEquals(
49 'AaBbCcÇçDdEeƏəFfĞğHhXxIıİiJjKkQqLlMmNnOoPpRrSsŞşTtUuÜüVvYyZz',
50 $this->convertToLatin(
51 'АаБбҸҹЧчДдЕеӘәФфҒғҺһХхЫыИиЖжКкГгЛлМмНнОоПпРрСсШшТтУуҮүВвЈјЗз'
52 )
53 );
54
55 // A simple conversion of Latin to Latin
56 $this->assertEquals( 'Lik',
57 $this->convertToLatin( 'Lik' )
58 );
59
60 // Assert that -{}-s are handled correctly
61 // NB: Cyrillic word followed by Cyrillic word, and the second one is converted
62 $this->assertEquals( 'Ланкон Ostoro',
63 $this->convertToLatin( '-{Ланкон}- Осторо' )
64 );
65
66 // Assert that -{}-s are handled correctly
67 // NB: Cyrillic word followed by Latin word, and nothing is converted
68 $this->assertEquals( 'Ланкон Ostoro',
69 $this->convertToLatin( '-{Ланкон}- Ostoro' )
70 );
71 }
72
73 # #### HELPERS #####################################################
74
75 /**
76 * Wrapper for converter::convertTo() method
77 * @param string $text
78 * @param string $variant
79 * @return string
80 */
81 protected function convertTo( $text, $variant ) {
82 return $this->getLanguageConverter()->convertTo( $text, $variant );
83 }
84
85 protected function convertToCyrillic( $text ) {
86 return $this->convertTo( $text, 'tly-cyrl' );
87 }
88
89 protected function convertToLatin( $text ) {
90 return $this->convertTo( $text, 'tly' );
91 }
92 }