Underscore are not valid in language code
[lhc/web/wiklou.git] / tests / phpunit / languages / LanguageTest.php
1 <?php
2 require_once dirname(dirname(__FILE__)). '/bootstrap.php';
3
4 class LanguageTest extends MediaWikiTestCase {
5 private $lang;
6
7 function setUp() {
8 $this->lang = Language::factory( 'en' );
9 }
10 function tearDown() {
11 unset( $this->lang );
12 }
13
14 function testLanguageConvertDoubleWidthToSingleWidth() {
15 $this->assertEquals(
16 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
17 $this->lang->normalizeForSearch(
18 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
19 ),
20 'convertDoubleWidth() with the full alphabet and digits'
21 );
22 }
23
24 function testFormatTimePeriod() {
25 $this->assertEquals(
26 "9.5s",
27 $this->lang->formatTimePeriod( 9.45 ),
28 'formatTimePeriod() rounding (<10s)'
29 );
30
31 $this->assertEquals(
32 "10s",
33 $this->lang->formatTimePeriod( 9.95 ),
34 'formatTimePeriod() rounding (<10s)'
35 );
36
37 $this->assertEquals(
38 "1m 0s",
39 $this->lang->formatTimePeriod( 59.55 ),
40 'formatTimePeriod() rounding (<60s)'
41 );
42
43 $this->assertEquals(
44 "2m 0s",
45 $this->lang->formatTimePeriod( 119.55 ),
46 'formatTimePeriod() rounding (<1h)'
47 );
48
49 $this->assertEquals(
50 "1h 0m 0s",
51 $this->lang->formatTimePeriod( 3599.55 ),
52 'formatTimePeriod() rounding (<1h)'
53 );
54
55 $this->assertEquals(
56 "2h 0m 0s",
57 $this->lang->formatTimePeriod( 7199.55 ),
58 'formatTimePeriod() rounding (>=1h)'
59 );
60 }
61
62 /**
63 * Test Language::isValidBuiltInCode()
64 * @dataProvider provideLanguageCodes
65 */
66 function testBuiltInCodeValidation( $code, $message = '' ) {
67 $this->assertTrue(
68 (bool) Language::isValidBuiltInCode( $code ),
69 "validating code $code $message"
70 );
71 }
72
73 function testBuiltInCodeValidationRejectUnderscore() {
74 $this->assertFalse(
75 (bool) Language::isValidBuiltInCode( 'be_tarask' ),
76 "reject underscore in language code"
77 );
78 }
79
80 function provideLanguageCodes() {
81 return array(
82 array( 'fr' , 'Two letters, minor case' ),
83 array( 'EN' , 'Two letters, upper case' ),
84 array( 'tyv' , 'Three letters' ),
85 array( 'tokipona' , 'long language code' ),
86 array( 'be-tarask', 'With dash' ),
87 array( 'Zh-classical', 'Begin with upper case, dash' ),
88 array( 'Be-x-old', 'With extension (two dashes)' ),
89 );
90 }
91 }