From b4230fa89e4214613fe77f1c74c97ad8b6d3a635 Mon Sep 17 00:00:00 2001 From: addshore Date: Sat, 25 Jan 2014 16:48:54 +0100 Subject: [PATCH] Expand MWTimestamp tests Change-Id: I00215ecd85b7403a05a75d5eaccbbd2819343624 --- tests/phpunit/includes/MWTimestampTest.php | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/phpunit/includes/MWTimestampTest.php b/tests/phpunit/includes/MWTimestampTest.php index fccd53b189..5b038a62bc 100644 --- a/tests/phpunit/includes/MWTimestampTest.php +++ b/tests/phpunit/includes/MWTimestampTest.php @@ -11,6 +11,44 @@ class MWTimestampTest extends MediaWikiLangTestCase { RequestContext::getMain()->setLanguage( Language::factory( 'en' ) ); } + /** + * @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 function provideValidTimestampDifferences() { + return array( + array( '1406833268','1406833269', '00 00 00 01' ), + array( '1406833268','1406833329', '00 00 01 01' ), + array( '1406833268','1406836929', '00 01 01 01' ), + array( '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 -- 2.20.1