wiki.techinc.nl/tests/phpunit/languages/LanguageTest.php
Antoine Musso 0330258617 Underscore are not valid in language code
* Reject underscore in validation
* Still case unsensitive
* Corrected tests using underscore


Follow up r83160 which was a follow up of r82927 (language code validation)
2011-03-04 17:16:09 +00:00

91 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once dirname(dirname(__FILE__)). '/bootstrap.php';
class LanguageTest extends MediaWikiTestCase {
private $lang;
function setUp() {
$this->lang = Language::factory( 'en' );
}
function tearDown() {
unset( $this->lang );
}
function testLanguageConvertDoubleWidthToSingleWidth() {
$this->assertEquals(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
$this->lang->normalizeForSearch(
""
),
'convertDoubleWidth() with the full alphabet and digits'
);
}
function testFormatTimePeriod() {
$this->assertEquals(
"9.5s",
$this->lang->formatTimePeriod( 9.45 ),
'formatTimePeriod() rounding (<10s)'
);
$this->assertEquals(
"10s",
$this->lang->formatTimePeriod( 9.95 ),
'formatTimePeriod() rounding (<10s)'
);
$this->assertEquals(
"1m 0s",
$this->lang->formatTimePeriod( 59.55 ),
'formatTimePeriod() rounding (<60s)'
);
$this->assertEquals(
"2m 0s",
$this->lang->formatTimePeriod( 119.55 ),
'formatTimePeriod() rounding (<1h)'
);
$this->assertEquals(
"1h 0m 0s",
$this->lang->formatTimePeriod( 3599.55 ),
'formatTimePeriod() rounding (<1h)'
);
$this->assertEquals(
"2h 0m 0s",
$this->lang->formatTimePeriod( 7199.55 ),
'formatTimePeriod() rounding (>=1h)'
);
}
/**
* Test Language::isValidBuiltInCode()
* @dataProvider provideLanguageCodes
*/
function testBuiltInCodeValidation( $code, $message = '' ) {
$this->assertTrue(
(bool) Language::isValidBuiltInCode( $code ),
"validating code $code $message"
);
}
function testBuiltInCodeValidationRejectUnderscore() {
$this->assertFalse(
(bool) Language::isValidBuiltInCode( 'be_tarask' ),
"reject underscore in language code"
);
}
function provideLanguageCodes() {
return array(
array( 'fr' , 'Two letters, minor case' ),
array( 'EN' , 'Two letters, upper case' ),
array( 'tyv' , 'Three letters' ),
array( 'tokipona' , 'long language code' ),
array( 'be-tarask', 'With dash' ),
array( 'Zh-classical', 'Begin with upper case, dash' ),
array( 'Be-x-old', 'With extension (two dashes)' ),
);
}
}