Makes LanguageTr uc & lc match parent declaration
[lhc/web/wiklou.git] / tests / phpunit / languages / LanguageTrTest.php
1 <?php
2 /**
3 * @author Ashar Voultoiz
4 * @copyright Copyright © 2011, Ashar Voultoiz
5 * @file
6 */
7
8 require_once dirname(dirname(__FILE__)). '/bootstrap.php';
9
10 /** Tests for MediaWiki languages/LanguageTr.php */
11 class LanguageTrTest extends MediaWikiTestCase {
12 private $lang;
13
14 function setUp() {
15 $this->lang = Language::factory( 'Tr' );
16 }
17 function tearDown() {
18 unset( $this->lang );
19 }
20
21 ##### Full Turkish alphabet #################################################
22
23 function testLowerCaseTurkishAlphabetToUppercase() {
24 $this->assertEquals( 'ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ',
25 $this->lang->uc( 'abcçdefgğhıijklmnoöprsştuüvyz' ),
26 'Lower case Turkish alphabet to upper case'
27 );
28 }
29 function testUpperCaseTurkishAlphabetToUppercase() {
30 $this->assertEquals( 'ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ',
31 $this->lang->uc( 'ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ' ),
32 'Upper case Turkish alphabet to upper case'
33 );
34 }
35 function testUpperCaseTurkishAlphabetToLowercase() {
36 $this->assertEquals( 'abcçdefgğhıijklmnoöprsştuüvyz',
37 $this->lang->lc( 'ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ' ),
38 'Upper case Turkish alphabet to lower case'
39 );
40 }
41 function testLowerCaseTurkishAlphabetToLowercase() {
42 $this->assertEquals( 'abcçdefgğhıijklmnoöprsştuüvyz',
43 $this->lang->lc( 'abcçdefgğhıijklmnoöprsştuüvyz' ),
44 'Lower case Turkish alphabet to lower case'
45 );
46 }
47
48 /**
49 * See @bug 28040
50 * Credits to #wikipedia-tr users berm, []LuCkY[] and Emperyan
51 * @see http://en.wikipedia.org/wiki/Dotted_and_dotless_I
52 * @dataProvider provideDottedAndDotlessI
53 */
54 function testChangeCaseOfFirstCharBeingDottedAndDotlessI( $func, $input, $inputCase, $expected ) {
55 if( $func == 'ucfirst' ) {
56 $res = $this->lang->ucfirst( $input );
57 } elseif( $func == 'lcfirst' ) {
58 $res = $this->lang->lcfirst( $input );
59 } else {
60 throw new MWException( __METHOD__ . " given an invalid function name '$func'" );
61 }
62
63 $msg = "Converting $inputCase case '$input' with $func should give '$expected'";
64
65 $this->assertEquals( $expected, $res, $msg );
66 }
67
68 function provideDottedAndDotlessI() {
69 return array(
70 # function, input, input case, expected
71 # Case changed:
72 array( 'ucfirst', 'ı', 'lower', 'I' ),
73 array( 'ucfirst', 'i', 'lower', 'İ' ),
74 array( 'lcfirst', 'I', 'upper', 'ı' ),
75 array( 'lcfirst', 'İ', 'upper', 'i' ),
76
77 # Already using the correct case
78 array( 'ucfirst', 'I', 'upper', 'I' ),
79 array( 'ucfirst', 'İ', 'upper', 'İ' ),
80 array( 'lcfirst', 'ı', 'lower', 'ı' ),
81 array( 'lcfirst', 'i', 'lower', 'i' ),
82
83 # A real example taken from bug 28040 using
84 # http://tr.wikipedia.org/wiki/%C4%B0Phone
85 array( 'lcfirst', 'iPhone', 'lower', 'iPhone' ),
86
87 # next case is valid in Turkish but are different words if we
88 # consider IPhone is English!
89 array( 'lcfirst', 'IPhone', 'upper', 'ıPhone' ),
90
91 );
92 }
93
94 ##### LanguageTr specificities #############################################
95 /**
96 * @cover LanguageTr:lc
97 * See @bug 28040
98 */
99 function testLanguageTrLowerCasingOverride() {
100 $this->assertEquals( 'ııııı', $this->lang->lc( 'IIIII') );
101 }
102 /**
103 * @cover LanguageTr:uc
104 * See @bug 28040
105 */
106 function testLanguageTrUpperCasingOverride() {
107 $this->assertEquals( 'İİİİİ', $this->lang->uc( 'iiiii') );
108 }
109
110 ##### Upper casing a string #################################################
111 /**
112 * Generic test for the Turkish dotted and dotless I strings
113 * See @bug 28040
114 * @dataProvider provideUppercaseStringsWithDottedAndDotlessI
115 */
116 function testUpperCasingOfAStringWithDottedAndDotLessI( $expected, $input ) {
117 $this->assertEquals( $expected, $this->lang->uc( $input ) );
118 }
119 function provideUppercaseStringsWithDottedAndDotlessI() {
120 return array(
121 # expected, input string to uc()
122 array( 'IIIII', 'ııııı' ),
123 array( 'IIIII', 'IIIII' ), #identity
124 array( 'İİİİİ', 'iiiii' ), # Specifically handled by LanguageTr:uc
125 array( 'İİİİİ', 'İİİİİ' ), #identity
126 );
127 }
128
129 ##### Lower casing a string #################################################
130 /**
131 * Generic test for the Turkish dotted and dotless I strings
132 * See @bug 28040
133 * @dataProvider provideLowercaseStringsWithDottedAndDotlessI
134 */
135 function testLowerCasingOfAStringWithDottedAndDotLessI( $expected, $input ) {
136 $this->assertEquals( $expected, $this->lang->lc( $input ) );
137 }
138 function provideLowercaseStringsWithDottedAndDotlessI() {
139 return array(
140 # expected, input string to lc()
141 array( 'ııııı', 'IIIII' ), # Specifically handled by LanguageTr:lc
142 array( 'ııııı', 'ııııı' ), #identity
143 array( 'iiiii', 'İİİİİ' ),
144 array( 'iiiii', 'iiiii' ), #identity
145 );
146 }
147
148 }