Permalink
Browse files

Merge branch '1.2' of dev@code.cakephp.org:cakephp into 1.2

  • Loading branch information...
2 parents 3dbae37 + 4e8c268 commit 61c1c47c936f263eb6ad797d266853bea8893233 @markstory markstory committed Oct 22, 2009
Showing with 12 additions and 50 deletions.
  1. +12 −50 cake/tests/cases/libs/view/helpers/time.test.php
@@ -470,57 +470,19 @@ function testIsToday() {
* @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

0 comments on commit 61c1c47

Please sign in to comment.