From 9186ab95943b7c2467a0f27f30bed9db3c589b9d Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sat, 27 Jun 2015 14:57:44 +0200 Subject: LinkDB::filterDay(): check input date format Signed-off-by: VirtualTam --- tests/LinkDBTest.php | 23 +++++++++++++---------- tests/UtilsTest.php | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index ee8dbee3..8b0bd23b 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -396,19 +396,22 @@ class LinkDBTest extends PHPUnit_Framework_TestCase /** * Use an invalid date format + * @expectedException Exception + * @expectedExceptionMessageRegExp /Invalid date format/ */ - public function testFilterInvalidDay() + public function testFilterInvalidDayWithChars() { - $this->assertEquals( - 0, - sizeof(self::$privateLinkDB->filterDay('Rainy day, dream away')) - ); + self::$privateLinkDB->filterDay('Rainy day, dream away'); + } - // TODO: check input format - $this->assertEquals( - 6, - sizeof(self::$privateLinkDB->filterDay('20')) - ); + /** + * Use an invalid date format + * @expectedException Exception + * @expectedExceptionMessageRegExp /Invalid date format/ + */ + public function testFilterInvalidDayDigits() + { + self::$privateLinkDB->filterDay('20'); } /** diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index bbba99f2..90392dfb 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -74,5 +74,24 @@ class UtilsTest extends PHPUnit_Framework_TestCase $this->assertTrue(endsWith('å!ùµ', 'ùµ', false)); $this->assertTrue(endsWith('µ$åù', 'åù', true)); } + + /** + * Check valid date strings, according to a DateTime format + */ + public function testCheckValidDateFormat() + { + $this->assertTrue(checkDateFormat('Ymd', '20150627')); + $this->assertTrue(checkDateFormat('Y-m-d', '2015-06-27')); + } + + /** + * Check erroneous date strings, according to a DateTime format + */ + public function testCheckInvalidDateFormat() + { + $this->assertFalse(checkDateFormat('Ymd', '2015')); + $this->assertFalse(checkDateFormat('Y-m-d', '2015-06')); + $this->assertFalse(checkDateFormat('Ymd', 'DeLorean')); + } } ?> -- cgit v1.2.3