X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Flanguages%2FLanguageTest.php;h=94ccfd018e084581cefb70bcec0526b28a4fe7a6;hb=83783cd93399fd7526aacf629e448ad3fa80e23c;hp=d8ec2e9dd8da7de6b3bb25041f87535e10f7d75f;hpb=8db04efa6ccafbdc3841a9d4223f2ad8169004ad;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index d8ec2e9dd8..94ccfd018e 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -1,23 +1,11 @@ lang = Language::factory( 'en' ); - } - protected function tearDown() { - unset( $this->lang ); - } +class LanguageTest extends LanguageClassesTestCase { function testLanguageConvertDoubleWidthToSingleWidth() { $this->assertEquals( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", - $this->lang->normalizeForSearch( + $this->getLang()->normalizeForSearch( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ), 'convertDoubleWidth() with the full alphabet and digits' @@ -28,7 +16,7 @@ class LanguageTest extends MediaWikiTestCase { * @dataProvider provideFormattableTimes */ function testFormatTimePeriod( $seconds, $format, $expected, $desc ) { - $this->assertEquals( $expected, $this->lang->formatTimePeriod( $seconds, $format ), $desc ); + $this->assertEquals( $expected, $this->getLang()->formatTimePeriod( $seconds, $format ), $desc ); } function provideFormattableTimes() { @@ -220,31 +208,31 @@ class LanguageTest extends MediaWikiTestCase { function testTruncate() { $this->assertEquals( "XXX", - $this->lang->truncate( "1234567890", 0, 'XXX' ), + $this->getLang()->truncate( "1234567890", 0, 'XXX' ), 'truncate prefix, len 0, small ellipsis' ); $this->assertEquals( "12345XXX", - $this->lang->truncate( "1234567890", 8, 'XXX' ), + $this->getLang()->truncate( "1234567890", 8, 'XXX' ), 'truncate prefix, small ellipsis' ); $this->assertEquals( "123456789", - $this->lang->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ), + $this->getLang()->truncate( "123456789", 5, 'XXXXXXXXXXXXXXX' ), 'truncate prefix, large ellipsis' ); $this->assertEquals( "XXX67890", - $this->lang->truncate( "1234567890", -8, 'XXX' ), + $this->getLang()->truncate( "1234567890", -8, 'XXX' ), 'truncate suffix, small ellipsis' ); $this->assertEquals( "123456789", - $this->lang->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ), + $this->getLang()->truncate( "123456789", -5, 'XXXXXXXXXXXXXXX' ), 'truncate suffix, large ellipsis' ); } @@ -256,7 +244,7 @@ class LanguageTest extends MediaWikiTestCase { // Actual HTML... $this->assertEquals( $expected, - $this->lang->truncateHTML( $input, $len, $ellipsis ) + $this->getLang()->truncateHTML( $input, $len, $ellipsis ) ); } @@ -355,7 +343,7 @@ class LanguageTest extends MediaWikiTestCase { function testSprintfDate( $format, $ts, $expected, $msg ) { $this->assertEquals( $expected, - $this->lang->sprintfDate( $format, $ts ), + $this->getLang()->sprintfDate( $format, $ts ), "sprintfDate('$format', '$ts'): $msg" ); } @@ -372,7 +360,7 @@ class LanguageTest extends MediaWikiTestCase { $this->assertEquals( $expected, - $this->lang->sprintfDate( $format, $ts ), + $this->getLang()->sprintfDate( $format, $ts ), "sprintfDate('$format', '$ts'): $msg" ); @@ -680,7 +668,7 @@ class LanguageTest extends MediaWikiTestCase { function testFormatSize( $size, $expected, $msg ) { $this->assertEquals( $expected, - $this->lang->formatSize( $size ), + $this->getLang()->formatSize( $size ), "formatSize('$size'): $msg" ); } @@ -742,7 +730,7 @@ class LanguageTest extends MediaWikiTestCase { function testFormatBitrate( $bps, $expected, $msg ) { $this->assertEquals( $expected, - $this->lang->formatBitrate( $bps ), + $this->getLang()->formatBitrate( $bps ), "formatBitrate('$bps'): $msg" ); } @@ -815,7 +803,7 @@ class LanguageTest extends MediaWikiTestCase { function testFormatDuration( $duration, $expected, $intervals = array() ) { $this->assertEquals( $expected, - $this->lang->formatDuration( $duration, $intervals ), + $this->getLang()->formatDuration( $duration, $intervals ), "formatDuration('$duration'): $expected" ); } @@ -950,7 +938,7 @@ class LanguageTest extends MediaWikiTestCase { function testCheckTitleEncoding( $s ) { $this->assertEquals( $s, - $this->lang->checkTitleEncoding($s), + $this->getLang()->checkTitleEncoding($s), "checkTitleEncoding('$s')" ); } @@ -1070,7 +1058,7 @@ class LanguageTest extends MediaWikiTestCase { * @dataProvider providePluralData */ function testConvertPlural( $expected, $number, $forms ) { - $chosen = $this->lang->convertPlural( $number, $forms ); + $chosen = $this->getLang()->convertPlural( $number, $forms ); $this->assertEquals( $expected, $chosen ); } @@ -1090,5 +1078,37 @@ class LanguageTest extends MediaWikiTestCase { ) ), ); } + + /** + * @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' ), + ); + } }