3 class LanguageTest
extends MediaWikiTestCase
{
7 $this->lang
= Language
::factory( 'en' );
13 function testLanguageConvertDoubleWidthToSingleWidth() {
15 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
16 $this->lang
->normalizeForSearch(
17 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
19 'convertDoubleWidth() with the full alphabet and digits'
23 function testFormatTimePeriod() {
26 $this->lang
->formatTimePeriod( 9.45 ),
27 'formatTimePeriod() rounding (<10s)'
32 $this->lang
->formatTimePeriod( 9.95 ),
33 'formatTimePeriod() rounding (<10s)'
38 $this->lang
->formatTimePeriod( 59.55 ),
39 'formatTimePeriod() rounding (<60s)'
44 $this->lang
->formatTimePeriod( 119.55 ),
45 'formatTimePeriod() rounding (<1h)'
50 $this->lang
->formatTimePeriod( 3599.55 ),
51 'formatTimePeriod() rounding (<1h)'
56 $this->lang
->formatTimePeriod( 7199.55 ),
57 'formatTimePeriod() rounding (>=1h)'
62 $this->lang
->formatTimePeriod( 7199.55, 'avoidseconds' ),
63 'formatTimePeriod() rounding (>=1h), avoidseconds'
68 $this->lang
->formatTimePeriod( 7199.55, 'avoidminutes' ),
69 'formatTimePeriod() rounding (>=1h), avoidminutes'
74 $this->lang
->formatTimePeriod( 172799.55, 'avoidseconds' ),
75 'formatTimePeriod() rounding (=48h), avoidseconds'
80 $this->lang
->formatTimePeriod( 259199.55, 'avoidminutes' ),
81 'formatTimePeriod() rounding (>48h), avoidminutes'
86 $this->lang
->formatTimePeriod( 176399.55, 'avoidseconds' ),
87 'formatTimePeriod() rounding (>48h), avoidseconds'
92 $this->lang
->formatTimePeriod( 176399.55, 'avoidminutes' ),
93 'formatTimePeriod() rounding (>48h), avoidminutes'
98 $this->lang
->formatTimePeriod( 259199.55, 'avoidseconds' ),
99 'formatTimePeriod() rounding (>48h), avoidseconds'
104 $this->lang
->formatTimePeriod( 172801.55, 'avoidseconds' ),
105 'formatTimePeriod() rounding, (>48h), avoidseconds'
110 $this->lang
->formatTimePeriod( 176460.55 ),
111 'formatTimePeriod() rounding, recursion, (>48h)'
115 function testTruncate() {
118 $this->lang
->truncate( "1234567890", 0, 'XXX' ),
119 'truncate prefix, len 0, small ellipsis'
124 $this->lang
->truncate( "1234567890", 8, 'XXX' ),
125 'truncate prefix, small ellipsis'
130 $this->lang
->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ),
131 'truncate prefix, large ellipsis'
136 $this->lang
->truncate( "1234567890", -8, 'XXX' ),
137 'truncate suffix, small ellipsis'
142 $this->lang
->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ),
143 'truncate suffix, large ellipsis'
148 * @dataProvider provideHTMLTruncateData()
150 function testTruncateHtml( $len, $ellipsis, $input, $expected ) {
154 $this->lang
->truncateHTML( $input, $len, $ellipsis )
159 * Array format is ($len, $ellipsis, $input, $expected)
161 function provideHTMLTruncateData() {
163 array( 0, 'XXX', "1234567890", "XXX" ),
164 array( 8, 'XXX', "1234567890", "12345XXX" ),
165 array( 5, 'XXXXXXXXXXXXXXX', '1234567890', "1234567890" ),
167 '<p><span style="font-weight:bold;"></span></p>',
168 '<p><span style="font-weight:bold;"></span></p>',
171 '<p><span style="font-weight:bold;">123456789</span></p>',
172 '<p><span style="font-weight:bold;">***</span></p>',
175 '<p><span style="font-weight:bold;"> 23456789</span></p>',
176 '<p><span style="font-weight:bold;">***</span></p>',
179 '<p><span style="font-weight:bold;">123456789</span></p>',
180 '<p><span style="font-weight:bold;">***</span></p>',
183 '<p><span style="font-weight:bold;">123456789</span></p>',
184 '<p><span style="font-weight:bold;">1***</span></p>',
187 '<tt><span style="font-weight:bold;">123456789</span></tt>',
188 '<tt><span style="font-weight:bold;">12***</span></tt>',
191 '<p><a href="www.mediawiki.org">123456789</a></p>',
192 '<p><a href="www.mediawiki.org">123***</a></p>',
195 '<p><a href="www.mediawiki.org">12 456789</a></p>',
196 '<p><a href="www.mediawiki.org">12 ***</a></p>',
199 '<small><span style="font-weight:bold;">123<p id="#moo">456</p>789</span></small>',
200 '<small><span style="font-weight:bold;">123<p id="#moo">4***</p></span></small>',
203 '<div><span style="font-weight:bold;">123<span>4</span>56789</span></div>',
204 '<div><span style="font-weight:bold;">123<span>4</span>5***</span></div>',
207 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
208 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
211 '<p><font style="font-weight:bold;">123456789</font></p>',
212 '<p><font style="font-weight:bold;">123456789</font></p>',
218 * Test Language::isValidBuiltInCode()
219 * @dataProvider provideLanguageCodes
221 function testBuiltInCodeValidation( $code, $message = '' ) {
223 (bool) Language
::isValidBuiltInCode( $code ),
224 "validating code $code $message"
228 function testBuiltInCodeValidationRejectUnderscore() {
230 (bool) Language
::isValidBuiltInCode( 'be_tarask' ),
231 "reject underscore in language code"
235 function provideLanguageCodes() {
237 array( 'fr' , 'Two letters, minor case' ),
238 array( 'EN' , 'Two letters, upper case' ),
239 array( 'tyv' , 'Three letters' ),
240 array( 'tokipona' , 'long language code' ),
241 array( 'be-tarask', 'With dash' ),
242 array( 'Zh-classical', 'Begin with upper case, dash' ),
243 array( 'Be-x-old', 'With extension (two dashes)' ),