http://www.mediawiki.org/wiki/Special:Code/MediaWiki/97961
Revision: 97961
Author: catrope
Date: 2011-09-23 22:02:36 +0000 (Fri, 23 Sep 2011)
Log Message:
-----------
Rewrite testFormatTimePeriod() with a data provider
Modified Paths:
--------------
trunk/phase3/tests/phpunit/languages/LanguageTest.php
Modified: trunk/phase3/tests/phpunit/languages/LanguageTest.php
===================================================================
--- trunk/phase3/tests/phpunit/languages/LanguageTest.php 2011-09-23
21:39:37 UTC (rev 97960)
+++ trunk/phase3/tests/phpunit/languages/LanguageTest.php 2011-09-23
22:02:36 UTC (rev 97961)
@@ -19,97 +19,31 @@
'convertDoubleWidth() with the full alphabet and digits'
);
}
-
- function testFormatTimePeriod() {
- $this->assertEquals(
- "9.5s",
- $this->lang->formatTimePeriod( 9.45 ),
- 'formatTimePeriod() rounding (<10s)'
+
+ /** @dataProvider provideFormattableTimes */
+ function testFormatTimePeriod( $seconds, $avoid, $expected, $desc ) {
+ $this->assertEquals( $expected, $this->lang->formatTimePeriod(
$seconds, $avoid ), $desc );
+ }
+
+ function provideFormattableTimes() {
+ return array(
+ array( 9.45, false, '9.5s', 'formatTimePeriod()
rounding (<10s)' ),
+ array( 9.95, false, '10s', 'formatTimePeriod() rounding
(<10s)' ),
+ array( 59.55, false, '1m 0s', 'formatTimePeriod()
rounding (<60s)' ),
+ array( 119.55, false, '2m 0s', 'formatTimePeriod()
rounding (<1h)' ),
+ array( 3599.55, false, '1h 0m 0s', 'formatTimePeriod()
rounding (<1h)' ),
+ array( 7199.55, false, '2h 0m 0s', 'formatTimePeriod()
rounding (>=1h)' ),
+ array( 7199.55, 'avoidseconds', '2h 0m',
'formatTimePeriod() rounding (>=1h), avoidseconds' ),
+ array( 7199.55, 'avoidminutes', '2h 0m',
'formatTimePeriod() rounding (>=1h), avoidminutes' ),
+ array( 172799.55, 'avoidseconds', '48h 0m',
'formatTimePeriod() rounding (=48h), avoidseconds' ),
+ array( 259199.55, 'avoidminutes', '3d 0h',
'formatTimePeriod() rounding (>48h), avoidminutes' ),
+ array( 176399.55, 'avoidseconds', '2d 1h 0m',
'formatTimePeriod() rounding (>48h), avoidseconds' ),
+ array( 176399.55, 'avoidminutes', '2d 1h',
'formatTimePeriod() rounding (>48h), avoidminutes' ),
+ array( 259199.55, 'avoidseconds', '3d 0h 0m',
'formatTimePeriod() rounding (>48h), avoidseconds' ),
+ array( 172801.55, 'avoidseconds', '2d 0h 0m',
'formatTimePeriod() rounding, (>48h), avoidseconds' ),
+ array( 176460.55, false, '2d 1h 1m 1s',
'formatTimePeriod() rounding, recursion, (>48h)' ),
);
-
- $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)'
- );
-
- $this->assertEquals(
- "2h 0m",
- $this->lang->formatTimePeriod( 7199.55, 'avoidseconds'
),
- 'formatTimePeriod() rounding (>=1h), avoidseconds'
- );
-
- $this->assertEquals(
- "2h 0m",
- $this->lang->formatTimePeriod( 7199.55, 'avoidminutes'
),
- 'formatTimePeriod() rounding (>=1h), avoidminutes'
- );
-
- $this->assertEquals(
- "48h 0m",
- $this->lang->formatTimePeriod( 172799.55,
'avoidseconds' ),
- 'formatTimePeriod() rounding (=48h), avoidseconds'
- );
-
- $this->assertEquals(
- "3d 0h",
- $this->lang->formatTimePeriod( 259199.55,
'avoidminutes' ),
- 'formatTimePeriod() rounding (>48h), avoidminutes'
- );
-
- $this->assertEquals(
- "2d 1h 0m",
- $this->lang->formatTimePeriod( 176399.55,
'avoidseconds' ),
- 'formatTimePeriod() rounding (>48h), avoidseconds'
- );
-
- $this->assertEquals(
- "2d 1h",
- $this->lang->formatTimePeriod( 176399.55,
'avoidminutes' ),
- 'formatTimePeriod() rounding (>48h), avoidminutes'
- );
-
- $this->assertEquals(
- "3d 0h 0m",
- $this->lang->formatTimePeriod( 259199.55,
'avoidseconds' ),
- 'formatTimePeriod() rounding (>48h), avoidseconds'
- );
-
- $this->assertEquals(
- "2d 0h 0m",
- $this->lang->formatTimePeriod( 172801.55,
'avoidseconds' ),
- 'formatTimePeriod() rounding, (>48h), avoidseconds'
- );
-
- $this->assertEquals(
- "2d 1h 1m 1s",
- $this->lang->formatTimePeriod( 176460.55 ),
- 'formatTimePeriod() rounding, recursion, (>48h)'
- );
+
}
function testTruncate() {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs