'2 days',
),
array(
- 365.25 * 86400, // 365.25 * 86400 = 31557600
+ // ( 365 + ( 24 * 3 + 25 ) / 400 ) * 86400 = 31556952
+ ( 365 + ( 24 * 3 + 25 ) / 400.0 ) * 86400,
'1 year',
),
array(
- 2 * 31557600,
+ 2 * 31556952,
'2 years',
),
array(
- 10 * 31557600,
+ 10 * 31556952,
'1 decade',
),
array(
- 20 * 31557600,
+ 20 * 31556952,
'2 decades',
),
array(
- 100 * 31557600,
+ 100 * 31556952,
'1 century',
),
array(
- 200 * 31557600,
+ 200 * 31556952,
'2 centuries',
),
array(
- 1000 * 31557600,
+ 1000 * 31556952,
'1 millennium',
),
array(
- 2000 * 31557600,
+ 2000 * 31556952,
'2 millennia',
),
array(
'1 hour and 1 second'
),
array(
- 31557600 + 2 * 86400 + 9000,
+ 31556952 + 2 * 86400 + 9000,
'1 year, 2 days, 2 hours and 30 minutes'
),
array(
- 42 * 1000 * 31557600 + 42,
+ 42 * 1000 * 31556952 + 42,
'42 millennia and 42 seconds'
),
array(
array( 'seconds' ),
),
array(
- 31557600 + 2 * 86400 + 9000,
+ 31556952 + 2 * 86400 + 9000,
'1 year, 2 days and 150 minutes',
array( 'years', 'days', 'minutes' ),
),
array( 'years', 'days' ),
),
array(
- 31557600 + 2 * 86400 + 9000,
+ 31556952 + 2 * 86400 + 9000,
'1 year, 2 days and 150 minutes',
array( 'minutes', 'days', 'years' ),
),
) ),
);
}
+
+ /**
+ * @covers Language::translateBlockExpiry()
+ * @dataProvider provideTranslateBlockExpiry
+ */
+ function testTranslateBlockExpiry( $expectedData, $str, $desc ) {
+ $lang = $this->getLang();
+ if ( is_array( $expectedData ) ) {
+ list( $func, $arg ) = $expectedData;
+ $expected = $lang->$func( $arg );
+ } else {
+ $expected = $expectedData;
+ }
+ $this->assertEquals( $expected, $lang->translateBlockExpiry( $str ), $desc );
+ }
+
+ function provideTranslateBlockExpiry() {
+ return array(
+ array( '2 hours', '2 hours', 'simple data from ipboptions' ),
+ array( 'indefinite', 'infinite', 'infinite from ipboptions' ),
+ array( 'indefinite', 'infinity', 'alternative infinite from ipboptions' ),
+ array( 'indefinite', 'indefinite', 'another alternative infinite from ipboptions' ),
+ array( array( 'formatDuration', 1023 * 60 * 60 ), '1023 hours', 'relative' ),
+ array( array( 'formatDuration', -1023 ), '-1023 seconds', 'negative relative' ),
+ array( array( 'formatDuration', 0 ), 'now', 'now' ),
+ array( array( 'timeanddate', '20120102070000' ), '2012-1-1 7:00 +1 day', 'mixed, handled as absolute' ),
+ array( array( 'timeanddate', '19910203040506' ), '1991-2-3 4:05:06', 'absolute' ),
+ array( array( 'timeanddate', '19700101000000' ), '1970-1-1 0:00:00', 'absolute at epoch' ),
+ array( array( 'timeanddate', '19691231235959' ), '1969-12-31 23:59:59', 'time before epoch' ),
+ array( 'dummy', 'dummy', 'return garbage as is' ),
+ );
+ }
+
+ /**
+ * @covers Language::commafy()
+ * @dataProvider provideCommafyData
+ */
+ function testCommafy( $number, $numbersWithCommas ) {
+ $this->assertEquals(
+ $numbersWithCommas,
+ $this->getLang()->commafy( $number ),
+ "commafy('$number')"
+ );
+ }
+
+ function provideCommafyData() {
+ return array(
+ array( 1, '1' ),
+ array( 10, '10' ),
+ array( 100, '100' ),
+ array( 1000, '1,000' ),
+ array( 10000, '10,000' ),
+ array( 100000, '100,000' ),
+ array( 1000000, '1,000,000' ),
+ array( 1.0001, '1.0001' ),
+ array( 10.0001, '10.0001' ),
+ array( 100.0001, '100.0001' ),
+ array( 1000.0001, '1,000.0001' ),
+ array( 10000.0001, '10,000.0001' ),
+ array( 100000.0001, '100,000.0001' ),
+ array( 1000000.0001, '1,000,000.0001' ),
+ );
+ }
+
+ function testListToText() {
+ $lang = $this->getLang();
+ $and = $lang->getMessageFromDB( 'and' );
+ $s = $lang->getMessageFromDB( 'word-separator' );
+ $c = $lang->getMessageFromDB( 'comma-separator' );
+
+ $this->assertEquals( '', $lang->listToText( array( ) ) );
+ $this->assertEquals( 'a', $lang->listToText( array( 'a' ) ) );
+ $this->assertEquals( "a{$and}{$s}b", $lang->listToText( array( 'a', 'b' ) ) );
+ $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( array( 'a', 'b', 'c' ) ) );
+ $this->assertEquals( "a{$c}b{$c}c{$and}{$s}d", $lang->listToText( array( 'a', 'b', 'c', 'd' ) ) );
+ }
+
+ /**
+ * @dataProvider provideIsSupportedLanguage
+ */
+ function testIsSupportedLanguage( $code, $expected, $comment ) {
+ $this->assertEquals( $expected, Language::isSupportedLanguage( $code ), $comment );
+ }
+
+ static function provideIsSupportedLanguage() {
+ return array(
+ array( 'en', true, 'is supported language' ),
+ array( 'fi', true, 'is supported language' ),
+ array( 'bunny', false, 'is not supported language' ),
+ array( 'FI', false, 'is not supported language, input should be in lower case' ),
+ );
+ }
}