From 4e8c268536081966f124cea7c5947fe341cc6d6a Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Wed, 21 Oct 2009 19:19:21 -0200 Subject: [PATCH] Making the test more clear by avoind +-2 days thing. Fixes #186. --- .../cases/libs/view/helpers/time.test.php | 62 ++++--------------- 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index 7fd5c1b15..997d3092b 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -470,57 +470,19 @@ class TimeHelperTest extends CakeTestCase { * @return void */ function testIsThisWeek() { - switch (date('D')) { - case 'Mon' : - for ($i = 0; $i < 6; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+7 days")); - $this->assertFalse($this->Time->isThisWeek("-1 days")); - break; - case 'Tue' : - for ($i = -1; $i < 5; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+6 days")); - $this->assertFalse($this->Time->isThisWeek("-2 days")); - break; - case 'Wed' : - for ($i = -2; $i < 5; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+5 days")); - $this->assertFalse($this->Time->isThisWeek("-3 days")); - break; - case 'Thu' : - for ($i = -3; $i < 4; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+4 days")); - $this->assertFalse($this->Time->isThisWeek("-4 days")); - break; - case 'Fri' : - for ($i = -4; $i < 3; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+3 days")); - $this->assertFalse($this->Time->isThisWeek("-5 days")); - break; - case 'Sat' : - for ($i = -5; $i < 2; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+2 days")); - $this->assertFalse($this->Time->isThisWeek("-6 days")); - break; - case 'Sun' : - for ($i = -6; $i < 1; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+1 days")); - $this->assertFalse($this->Time->isThisWeek("-7 days")); - break; + // A map of days which goes from -1 day of week to +1 day of week + $map = array( + 'Mon' => array(-1, 7), 'Tue' => array(-2, 6), 'Wed' => array(-3, 5), + 'Thu' => array(-4, 4), 'Fri' => array(-5, 3), 'Sat' => array(-6, 2), + 'Sun' => array(-7, 1) + ); + $days = $map[date('D')]; + + for ($day = $days[0] + 1; $day < $days[1]; $day++) { + $this->assertTrue($this->Time->isThisWeek(($day > 0 ? '+' : '') . $day . ' days')); } + $this->assertFalse($this->Time->isThisWeek($days[0] . ' days')); + $this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days')); } /** * testIsThisMonth method