X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FMWTimestampTest.php;h=c1a46fed5b8a4b53896c862577d8f3abf8f91e84;hp=70e4aeab4a463abff5164695874bcdfbb9a0df54;hb=bb9e1c1aa906b3c6c2c19eb48c33b635dee6af20;hpb=f3f0b47a6a6d1c9581d815c7ac5bd5636c3dea1e diff --git a/tests/phpunit/includes/MWTimestampTest.php b/tests/phpunit/includes/MWTimestampTest.php index 70e4aeab4a..c1a46fed5b 100644 --- a/tests/phpunit/includes/MWTimestampTest.php +++ b/tests/phpunit/includes/MWTimestampTest.php @@ -4,7 +4,6 @@ * Tests timestamp parsing and output. */ class MWTimestampTest extends MediaWikiLangTestCase { - protected function setUp() { parent::setUp(); @@ -12,128 +11,6 @@ class MWTimestampTest extends MediaWikiLangTestCase { $this->setMwGlobals( 'wgHooks', [] ); } - /** - * @covers MWTimestamp::__construct - */ - public function testConstructWithNoTimestamp() { - $timestamp = new MWTimestamp(); - $this->assertInternalType( 'string', $timestamp->getTimestamp() ); - $this->assertNotEmpty( $timestamp->getTimestamp() ); - $this->assertNotEquals( false, strtotime( $timestamp->getTimestamp( TS_MW ) ) ); - } - - /** - * @covers MWTimestamp::__toString - */ - public function testToString() { - $timestamp = new MWTimestamp( '1406833268' ); // Equivalent to 20140731190108 - $this->assertEquals( '1406833268', $timestamp->__toString() ); - } - - public static function provideValidTimestampDifferences() { - return [ - [ '1406833268', '1406833269', '00 00 00 01' ], - [ '1406833268', '1406833329', '00 00 01 01' ], - [ '1406833268', '1406836929', '00 01 01 01' ], - [ '1406833268', '1406923329', '01 01 01 01' ], - ]; - } - - /** - * @dataProvider provideValidTimestampDifferences - * @covers MWTimestamp::diff - */ - public function testDiff( $timestamp1, $timestamp2, $expected ) { - $timestamp1 = new MWTimestamp( $timestamp1 ); - $timestamp2 = new MWTimestamp( $timestamp2 ); - $diff = $timestamp1->diff( $timestamp2 ); - $this->assertEquals( $expected, $diff->format( '%D %H %I %S' ) ); - } - - /** - * Test parsing of valid timestamps and outputing to MW format. - * @dataProvider provideValidTimestamps - * @covers MWTimestamp::getTimestamp - */ - public function testValidParse( $format, $original, $expected ) { - $timestamp = new MWTimestamp( $original ); - $this->assertEquals( $expected, $timestamp->getTimestamp( TS_MW ) ); - } - - /** - * Test outputting valid timestamps to different formats. - * @dataProvider provideValidTimestamps - * @covers MWTimestamp::getTimestamp - */ - public function testValidOutput( $format, $expected, $original ) { - $timestamp = new MWTimestamp( $original ); - $this->assertEquals( $expected, (string)$timestamp->getTimestamp( $format ) ); - } - - /** - * Test an invalid timestamp. - * @expectedException TimestampException - * @covers MWTimestamp - */ - public function testInvalidParse() { - new MWTimestamp( "This is not a timestamp." ); - } - - /** - * Test an out of range timestamp - * @dataProvider provideOutOfRangeTimestamps - * @expectedException TimestampException - * @covers MWTimestamp - */ - public function testOutOfRangeTimestamps( $format, $input ) { - $timestamp = new MWTimestamp( $input ); - $timestamp->getTimestamp( $format ); - } - - /** - * Test requesting an invalid output format. - * @expectedException TimestampException - * @covers MWTimestamp::getTimestamp - */ - public function testInvalidOutput() { - $timestamp = new MWTimestamp( '1343761268' ); - $timestamp->getTimestamp( 98 ); - } - - /** - * Returns a list of valid timestamps in the format: - * [ type, timestamp_of_type, timestamp_in_MW ] - */ - public static function provideValidTimestamps() { - return [ - // Various formats - [ TS_UNIX, '1343761268', '20120731190108' ], - [ TS_MW, '20120731190108', '20120731190108' ], - [ TS_DB, '2012-07-31 19:01:08', '20120731190108' ], - [ TS_ISO_8601, '2012-07-31T19:01:08Z', '20120731190108' ], - [ TS_ISO_8601_BASIC, '20120731T190108Z', '20120731190108' ], - [ TS_EXIF, '2012:07:31 19:01:08', '20120731190108' ], - [ TS_RFC2822, 'Tue, 31 Jul 2012 19:01:08 GMT', '20120731190108' ], - [ TS_ORACLE, '31-07-2012 19:01:08.000000', '20120731190108' ], - [ TS_POSTGRES, '2012-07-31 19:01:08 GMT', '20120731190108' ], - // Some extremes and weird values - [ TS_ISO_8601, '9999-12-31T23:59:59Z', '99991231235959' ], - [ TS_UNIX, '-62135596801', '00001231235959' ] - ]; - } - - /** - * Returns a list of out of range timestamps in the format: - * [ type, timestamp_of_type ] - */ - public static function provideOutOfRangeTimestamps() { - return [ - // Various formats - [ TS_MW, '-62167219201' ], // -0001-12-31T23:59:59Z - [ TS_MW, '253402300800' ], // 10000-01-01T00:00:00Z - ]; - } - /** * @dataProvider provideHumanTimestampTests * @covers MWTimestamp::getHumanTimestamp @@ -146,7 +23,7 @@ class MWTimestampTest extends MediaWikiLangTestCase { $expectedOutput, // The expected output $desc // Description ) { - $user = $this->getMock( 'User' ); + $user = $this->createMock( 'User' ); $user->expects( $this->any() ) ->method( 'getOption' ) ->with( 'timecorrection' ) @@ -279,7 +156,7 @@ class MWTimestampTest extends MediaWikiLangTestCase { $expectedOutput, // The expected output $desc // Description ) { - $user = $this->getMock( 'User' ); + $user = $this->createMock( 'User' ); $user->expects( $this->any() ) ->method( 'getOption' ) ->with( 'timecorrection' )