Making the test more clear by avoind +-2 days thing. Fixes #186.

This commit is contained in:
renan.saddam 2009-10-21 19:19:21 -02:00
parent 1ee9771efb
commit 4e8c268536

View file

@ -470,57 +470,19 @@ class TimeHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testIsThisWeek() { function testIsThisWeek() {
switch (date('D')) { // A map of days which goes from -1 day of week to +1 day of week
case 'Mon' : $map = array(
for ($i = 0; $i < 6; $i++) { 'Mon' => array(-1, 7), 'Tue' => array(-2, 6), 'Wed' => array(-3, 5),
$this->assertTrue($this->Time->isThisWeek("+$i days")); 'Thu' => array(-4, 4), 'Fri' => array(-5, 3), 'Sat' => array(-6, 2),
} 'Sun' => array(-7, 1)
$this->assertFalse($this->Time->isThisWeek("+7 days")); );
$this->assertFalse($this->Time->isThisWeek("-1 days")); $days = $map[date('D')];
break;
case 'Tue' : for ($day = $days[0] + 1; $day < $days[1]; $day++) {
for ($i = -1; $i < 5; $i++) { $this->assertTrue($this->Time->isThisWeek(($day > 0 ? '+' : '') . $day . ' days'));
$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;
} }
$this->assertFalse($this->Time->isThisWeek($days[0] . ' days'));
$this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days'));
} }
/** /**
* testIsThisMonth method * testIsThisMonth method