| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/datetime/src/lmbMonth.class.php'); 10 lmb_require('limb/datetime/src/lmbDate.class.php'); 11 12 class lmbMonthTest extends UnitTestCase 13 { 14 function testCreateCurrent() 15 { 16 $date = new lmbDate(); 17 18 $c = new lmbMonth(); 19 $this->assertEqual($c->getYear(), $date->getYear()); 20 $this->assertEqual($c->getMonth(), $date->getMonth()); 21 } 22 23 function testCreate() 24 { 25 $c = new lmbMonth(2007, 5); 26 $this->assertEqual($c->getYear(), 2007); 27 $this->assertEqual($c->getMonth(), 5); 28 } 29 30 function testCreateByDate() 31 { 32 $c = new lmbMonth(new lmbDate('2007-05-01')); 33 $this->assertEqual($c->getYear(), 2007); 34 $this->assertEqual($c->getMonth(), 5); 35 } 36 37 function testCreateByString() 38 { 39 $c = new lmbMonth('2007-05-01'); 40 $this->assertEqual($c->getYear(), 2007); 41 $this->assertEqual($c->getMonth(), 5); 42 } 43 44 function testGetBoundaries() 45 { 46 $c = new lmbMonth(2007, 5); 47 $this->assertEqual(new lmbDate('2007-05-01 00:00:00'), $c->getStartDate()); 48 $this->assertEqual(new lmbDate('2007-05-31 23:59:59'), $c->getEndDate()); 49 } 50 51 function testGetMonthName() 52 { 53 $c = new lmbMonth(2007, 5); 54 $this->assertEqual($c->getMonthName(), 'May'); 55 } 56 57 function testGetMonthShortName() 58 { 59 $c = new lmbMonth(2007, 1); 60 $this->assertEqual($c->getMonthName(), 'Jan'); 61 } 62 63 function testGetNumberOfDays() 64 { 65 $c = new lmbMonth(2007, 5); 66 $this->assertEqual($c->getNumberOfDays(), 31); 67 } 68 69 function testGetNumberOfDaysForLeapYear() 70 { 71 $c1 = new lmbMonth(2005, 2); 72 $this->assertEqual($c1->getNumberOfDays(), 28); 73 74 $c2 = new lmbMonth(2004, 2); 75 $this->assertEqual($c2->getNumberOfDays(), 29); 76 } 77 78 function testGetNumberOfWeeks() 79 { 80 $c1 = new lmbMonth(1999, 2); 81 $this->assertEqual($c1->getNumberOfWeeks(), 4); 82 83 $c2 = new lmbMonth(2007, 2); 84 $this->assertEqual($c2->getNumberOfWeeks(), 5); 85 86 $c3 = new lmbMonth(2010, 5); 87 $this->assertEqual($c3->getNumberOfWeeks(), 6); 88 } 89 90 function testGetWeekFailed() 91 { 92 $c = new lmbMonth(1999, 2); 93 $this->assertNull($c->getWeek(4)); 94 $this->assertNull($c->getWeek(10)); 95 $this->assertNull($c->getWeek(-1)); 96 } 97 98 function testGetIdealWeek() 99 { 100 $c = new lmbMonth(1999, 2); 101 $week0 = $c->getWeek(0); 102 $week1 = $c->getWeek(1); 103 $week2 = $c->getWeek(2); 104 $week3 = $c->getWeek(3); 105 106 $expected0 = array(); 107 $expected1 = array(); 108 $expected2 = array(); 109 $expected3 = array(); 110 111 for($i=0;$i<7;$i++) 112 $expected0[] = new lmbDate(sprintf("1999-02-%02d", $i+1)); 113 for($i=7;$i<14;$i++) 114 $expected1[] = new lmbDate(sprintf("1999-02-%02d", $i+1)); 115 for($i=14;$i<21;$i++) 116 $expected2[] = new lmbDate(sprintf("1999-02-%02d", $i+1)); 117 for($i=21;$i<28;$i++) 118 $expected3[] = new lmbDate(sprintf("1999-02-%02d", $i+1)); 119 120 $this->assertEqual($week0, $expected0); 121 $this->assertEqual($week1, $expected1); 122 $this->assertEqual($week2, $expected2); 123 $this->assertEqual($week3, $expected3); 124 } 125 126 function testGetWeekWithDaysFromBoundaryMonths() 127 { 128 $c = new lmbMonth(2007, 2); 129 $week0 = $c->getWeek(0); 130 $week1 = $c->getWeek(1); 131 $week2 = $c->getWeek(2); 132 $week3 = $c->getWeek(3); 133 $week4 = $c->getWeek(4); 134 135 $expected0 = array(); 136 $expected1 = array(); 137 $expected2 = array(); 138 $expected3 = array(); 139 $expected4 = array(); 140 141 for($i=29;$i<32;$i++) 142 $expected0[] = new lmbDate(sprintf("2007-01-%02d", $i)); 143 for($i=1;$i<5;$i++) 144 $expected0[] = new lmbDate(sprintf("2007-02-%02d", $i)); 145 146 for($i=5;$i<12;$i++) 147 $expected1[] = new lmbDate(sprintf("2007-02-%02d", $i)); 148 for($i=12;$i<19;$i++) 149 $expected2[] = new lmbDate(sprintf("2007-02-%02d", $i)); 150 for($i=19;$i<26;$i++) 151 $expected3[] = new lmbDate(sprintf("2007-02-%02d", $i)); 152 153 for($i=26;$i<29;$i++) 154 $expected4[] = new lmbDate(sprintf("2007-02-%02d", $i)); 155 for($i=1;$i<5;$i++) 156 $expected4[] = new lmbDate(sprintf("2007-03-%02d", $i)); 157 158 $this->assertEqual($week0, $expected0); 159 $this->assertEqual($week1, $expected1); 160 $this->assertEqual($week2, $expected2); 161 $this->assertEqual($week3, $expected3); 162 $this->assertEqual($week4, $expected4); 163 } 164 165 function testGetAllWeeks() 166 { 167 $c = new lmbMonth(2007, 2); 168 $weeks = $c->getAllWeeks(); 169 $this->assertEqual($weeks, array($c->getWeek(0), $c->getWeek(1), $c->getWeek(2), 170 $c->getWeek(3), $c->getWeek(4))); 171 } 172 173 function testGetNextMonth() 174 { 175 $c = new lmbMonth(2007, 2); 176 $next = $c->getNextMonth(); 177 $this->assertEqual(new lmbMonth(2007, 3), $next); 178 } 179 180 function testGetNextMothFromDecember() 181 { 182 $c = new lmbMonth(2007, 12); 183 $next = $c->getNextMonth(); 184 $this->assertEqual(new lmbMonth(2008, 1), $next); 185 } 186 187 function testGetPrevMonth() 188 { 189 $c = new lmbMonth(2007, 2); 190 $prev = $c->getPrevMonth(); 191 $this->assertEqual(new lmbMonth(2007, 1), $prev); 192 } 193 194 function testGetPrevMonthFromJanuary() 195 { 196 $c = new lmbMonth(2007, 1); 197 $prev = $c->getPrevMonth(); 198 $this->assertEqual(new lmbMonth(2006, 12), $prev); 199 } 200 } 201 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Dec 5 04:05:07 2008 | Cross-referenced by PHPXref 0.7 |