ba9cba132af3d2031ffc723e5db98847c0d836ae
3 class LanguageTest
extends MediaWikiTestCase
{
11 $this->lang
= Language
::factory( 'en' );
17 function testLanguageConvertDoubleWidthToSingleWidth() {
19 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
20 $this->lang
->normalizeForSearch(
21 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
23 'convertDoubleWidth() with the full alphabet and digits'
27 /** @dataProvider provideFormattableTimes */
28 function testFormatTimePeriod( $seconds, $format, $expected, $desc ) {
29 $this->assertEquals( $expected, $this->lang
->formatTimePeriod( $seconds, $format ), $desc );
32 function provideFormattableTimes() {
34 array( 9.45, array(), '9.5s', 'formatTimePeriod() rounding (<10s)' ),
35 array( 9.45, array( 'noabbrevs' => true ), '9.5 seconds', 'formatTimePeriod() rounding (<10s)' ),
36 array( 9.95, array(), '10s', 'formatTimePeriod() rounding (<10s)' ),
37 array( 9.95, array( 'noabbrevs' => true ), '10 seconds', 'formatTimePeriod() rounding (<10s)' ),
38 array( 59.55, array(), '1m 0s', 'formatTimePeriod() rounding (<60s)' ),
39 array( 59.55, array( 'noabbrevs' => true ), '1 minute 0 seconds', 'formatTimePeriod() rounding (<60s)' ),
40 array( 119.55, array(), '2m 0s', 'formatTimePeriod() rounding (<1h)' ),
41 array( 119.55, array( 'noabbrevs' => true ), '2 minutes 0 seconds', 'formatTimePeriod() rounding (<1h)' ),
42 array( 3599.55, array(), '1h 0m 0s', 'formatTimePeriod() rounding (<1h)' ),
43 array( 3599.55, array( 'noabbrevs' => true ), '1 hour 0 minutes 0 seconds', 'formatTimePeriod() rounding (<1h)' ),
44 array( 7199.55, array(), '2h 0m 0s', 'formatTimePeriod() rounding (>=1h)' ),
45 array( 7199.55, array( 'noabbrevs' => true ), '2 hours 0 minutes 0 seconds', 'formatTimePeriod() rounding (>=1h)' ),
46 array( 7199.55, 'avoidseconds', '2h 0m', 'formatTimePeriod() rounding (>=1h), avoidseconds' ),
47 array( 7199.55, array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), '2 hours 0 minutes', 'formatTimePeriod() rounding (>=1h), avoidseconds' ),
48 array( 7199.55, 'avoidminutes', '2h 0m', 'formatTimePeriod() rounding (>=1h), avoidminutes' ),
49 array( 7199.55, array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ), '2 hours 0 minutes', 'formatTimePeriod() rounding (>=1h), avoidminutes' ),
50 array( 172799.55, 'avoidseconds', '48h 0m', 'formatTimePeriod() rounding (=48h), avoidseconds' ),
51 array( 172799.55, array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), '48 hours 0 minutes', 'formatTimePeriod() rounding (=48h), avoidseconds' ),
52 array( 259199.55, 'avoidminutes', '3d 0h', 'formatTimePeriod() rounding (>48h), avoidminutes' ),
53 array( 259199.55, array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ), '3 days 0 hours', 'formatTimePeriod() rounding (>48h), avoidminutes' ),
54 array( 176399.55, 'avoidseconds', '2d 1h 0m', 'formatTimePeriod() rounding (>48h), avoidseconds' ),
55 array( 176399.55, array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), '2 days 1 hour 0 minutes', 'formatTimePeriod() rounding (>48h), avoidseconds' ),
56 array( 176399.55, 'avoidminutes', '2d 1h', 'formatTimePeriod() rounding (>48h), avoidminutes' ),
57 array( 176399.55, array( 'avoid' => 'avoidminutes', 'noabbrevs' => true ), '2 days 1 hour', 'formatTimePeriod() rounding (>48h), avoidminutes' ),
58 array( 259199.55, 'avoidseconds', '3d 0h 0m', 'formatTimePeriod() rounding (>48h), avoidseconds' ),
59 array( 259199.55, array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), '3 days 0 hours 0 minutes', 'formatTimePeriod() rounding (>48h), avoidseconds' ),
60 array( 172801.55, 'avoidseconds', '2d 0h 0m', 'formatTimePeriod() rounding, (>48h), avoidseconds' ),
61 array( 172801.55, array( 'avoid' => 'avoidseconds', 'noabbrevs' => true ), '2 days 0 hours 0 minutes', 'formatTimePeriod() rounding, (>48h), avoidseconds' ),
62 array( 176460.55, array(), '2d 1h 1m 1s', 'formatTimePeriod() rounding, recursion, (>48h)' ),
63 array( 176460.55, array( 'noabbrevs' => true ), '2 days 1 hour 1 minute 1 second', 'formatTimePeriod() rounding, recursion, (>48h)' ),
68 function testTruncate() {
71 $this->lang
->truncate( "1234567890", 0, 'XXX' ),
72 'truncate prefix, len 0, small ellipsis'
77 $this->lang
->truncate( "1234567890", 8, 'XXX' ),
78 'truncate prefix, small ellipsis'
83 $this->lang
->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ),
84 'truncate prefix, large ellipsis'
89 $this->lang
->truncate( "1234567890", -8, 'XXX' ),
90 'truncate suffix, small ellipsis'
95 $this->lang
->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ),
96 'truncate suffix, large ellipsis'
101 * @dataProvider provideHTMLTruncateData()
103 function testTruncateHtml( $len, $ellipsis, $input, $expected ) {
107 $this->lang
->truncateHTML( $input, $len, $ellipsis )
112 * Array format is ($len, $ellipsis, $input, $expected)
114 function provideHTMLTruncateData() {
116 array( 0, 'XXX', "1234567890", "XXX" ),
117 array( 8, 'XXX', "1234567890", "12345XXX" ),
118 array( 5, 'XXXXXXXXXXXXXXX', '1234567890', "1234567890" ),
120 '<p><span style="font-weight:bold;"></span></p>',
121 '<p><span style="font-weight:bold;"></span></p>',
124 '<p><span style="font-weight:bold;">123456789</span></p>',
125 '<p><span style="font-weight:bold;">***</span></p>',
128 '<p><span style="font-weight:bold;"> 23456789</span></p>',
129 '<p><span style="font-weight:bold;">***</span></p>',
132 '<p><span style="font-weight:bold;">123456789</span></p>',
133 '<p><span style="font-weight:bold;">***</span></p>',
136 '<p><span style="font-weight:bold;">123456789</span></p>',
137 '<p><span style="font-weight:bold;">1***</span></p>',
140 '<tt><span style="font-weight:bold;">123456789</span></tt>',
141 '<tt><span style="font-weight:bold;">12***</span></tt>',
144 '<p><a href="www.mediawiki.org">123456789</a></p>',
145 '<p><a href="www.mediawiki.org">123***</a></p>',
148 '<p><a href="www.mediawiki.org">12 456789</a></p>',
149 '<p><a href="www.mediawiki.org">12 ***</a></p>',
152 '<small><span style="font-weight:bold;">123<p id="#moo">456</p>789</span></small>',
153 '<small><span style="font-weight:bold;">123<p id="#moo">4***</p></span></small>',
156 '<div><span style="font-weight:bold;">123<span>4</span>56789</span></div>',
157 '<div><span style="font-weight:bold;">123<span>4</span>5***</span></div>',
160 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
161 '<p><table style="font-weight:bold;"><tr><td>123456789</td></tr></table></p>',
164 '<p><font style="font-weight:bold;">123456789</font></p>',
165 '<p><font style="font-weight:bold;">123456789</font></p>',
171 * Test Language::isValidBuiltInCode()
172 * @dataProvider provideLanguageCodes
174 function testBuiltInCodeValidation( $code, $message = '' ) {
176 (bool) Language
::isValidBuiltInCode( $code ),
177 "validating code $code $message"
181 function testBuiltInCodeValidationRejectUnderscore() {
183 (bool) Language
::isValidBuiltInCode( 'be_tarask' ),
184 "reject underscore in language code"
188 function provideLanguageCodes() {
190 array( 'fr' , 'Two letters, minor case' ),
191 array( 'EN' , 'Two letters, upper case' ),
192 array( 'tyv' , 'Three letters' ),
193 array( 'tokipona' , 'long language code' ),
194 array( 'be-tarask', 'With dash' ),
195 array( 'Zh-classical', 'Begin with upper case, dash' ),
196 array( 'Be-x-old', 'With extension (two dashes)' ),
201 * @dataProvider provideSprintfDateSamples
203 function testSprintfDate( $format, $ts, $expected, $msg ) {
206 $this->lang
->sprintfDate( $format, $ts ),
207 "sprintfDate('$format', '$ts'): $msg"
211 function provideSprintfDateSamples() {
216 '1390', // note because we're testing English locale we get Latin-standard digits
217 'Iranian calendar full year'
223 'Iranian calendar short year'
229 * @dataProvider provideFormatSizes
231 function testFormatSize( $size, $expected, $msg ) {
234 $this->lang
->formatSize( $size ),
235 "formatSize('$size'): $msg"
239 function provideFormatSizes() {
286 // How big!? THIS BIG!
291 * @dataProvider provideFormatBitrate
293 function testFormatBitrate( $bps, $expected, $msg ) {
296 $this->lang
->formatBitrate( $bps ),
297 "formatBitrate('$bps'): $msg"
301 function provideFormatBitrate() {
311 "1 kilobit per second"
316 "1 megabit per second"
321 "1 gigabit per second"
326 "1 terabit per second"
331 "1 petabit per second"
336 "1 exabit per second"
341 "1 zetabit per second"
346 "1 yottabit per second"