mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making the test more clear by avoind +-2 days thing. Fixes #186.
This commit is contained in:
parent
1ee9771efb
commit
4e8c268536
1 changed files with 12 additions and 50 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue