* @dataProvider provideLanguageCodes
* @covers Language::isValidBuiltInCode
*/
- public function testBuiltInCodeValidation( $code, $message = '' ) {
- $this->assertTrue(
+ public function testBuiltInCodeValidation( $code, $expected, $message = '' ) {
+ $this->assertEquals( $expected,
(bool)Language::isValidBuiltInCode( $code ),
"validating code $code $message"
);
}
- /**
- * @covers Language::isValidBuiltInCode
- */
- public function testBuiltInCodeValidationRejectUnderscore() {
- $this->assertFalse(
- (bool)Language::isValidBuiltInCode( 'be_tarask' ),
- "reject underscore in language code"
- );
- }
-
public static 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)' ),
+ array( 'fr', true, 'Two letters, minor case' ),
+ array( 'EN', false, 'Two letters, upper case' ),
+ array( 'tyv', true, 'Three letters' ),
+ array( 'tokipona', true, 'long language code' ),
+ array( 'be-tarask', true, 'With dash' ),
+ array( 'be-x-old', true, 'With extension (two dashes)' ),
+ array( 'be_tarask', false, 'Reject underscores' ),
);
}
* @covers Language::sprintfDate
*/
public function testSprintfDate( $format, $ts, $expected, $msg ) {
+ $ttl = null;
$this->assertEquals(
$expected,
- $this->getLang()->sprintfDate( $format, $ts ),
+ $this->getLang()->sprintfDate( $format, $ts, null, $ttl ),
"sprintfDate('$format', '$ts'): $msg"
);
+ if ( $ttl ) {
+ $dt = new DateTime( $ts );
+ $lastValidTS = $dt->add( new DateInterval( 'PT' . ( $ttl - 1 ) . 'S' ) )->format( 'YmdHis' );
+ $this->assertEquals(
+ $expected,
+ $this->getLang()->sprintfDate( $format, $lastValidTS, null ),
+ "sprintfDate('$format', '$ts'): TTL $ttl too high (output was different at $lastValidTS)"
+ );
+ } else {
+ // advance the time enough to make all of the possible outputs different (except possibly L)
+ $dt = new DateTime( $ts );
+ $newTS = $dt->add( new DateInterval( 'P1Y1M8DT13H1M1S' ) )->format( 'YmdHis' );
+ $this->assertEquals(
+ $expected,
+ $this->getLang()->sprintfDate( $format, $newTS, null ),
+ "sprintfDate('$format', '$ts'): Missing TTL (output was different at $newTS)"
+ );
+ }
}
/**