1<?php 2/** 3 * Test class for running unit tests related to the driver for holidays in USA 4 * 5 * PHP Versions 4 and 5 6 * 7 * @category Date 8 * @package Date_Holidays 9 * @author Carsten Lucke <luckec@tool-garage.de> 10 * @license http://www.php.net/license/3_01.txt PHP License 3.0.1 11 * @version CVS: $Id: Date_Holidays_Driver_USA_TestSuite.php,v 1.9 2008/08/23 09:12:59 kguest Exp $ 12 * @link http://pear.php.net/package/Date_Holidays 13 */ 14if (!defined("PHPUnit_MAIN_METHOD")) { 15 define("PHPUnit_MAIN_METHOD", "Date_HolidaysTest::main"); 16} 17 18require_once 'Date/Holidays.php'; 19 20/** 21 * Test class for running unit tests related to the driver for holidays in USA 22 * 23 * @uses PHPUnit_Framework_TestCase 24 * @category Date 25 * @package Date_Holidays 26 * @author Carsten Lucke <luckec@tool-garage.de> 27 * @license http://www.php.net/license/3_01.txt PHP License 3.0.1 28 * @version CVS: $Id: Date_Holidays_Driver_USA_TestSuite.php,v 1.9 2008/08/23 09:12:59 kguest Exp $ 29 * @link http://pear.php.net/package/Date_Holidays 30 */ 31class Date_Holidays_Driver_USA_TestSuite extends PHPUnit_Framework_TestCase 32{ 33 34 /** 35 * setUp 36 * 37 * @access public 38 * @return void 39 */ 40 function setUp() 41 { 42 43 } 44 /** 45 * tests for holidays in 2005 46 * 47 * @access public 48 * @return void 49 */ 50 function testHolidays2005() 51 { 52 53 $holidays = Date_Holidays::factory('USA', 2005, 'en_EN'); 54 if (Date_Holidays::isError($holidays)) { 55 die('Factory was unable to produce driver-object'); 56 } 57 58 // Test New Year Day -- it comes a day early this year 59 $day = $holidays->getHolidayDate('newYearsDay'); 60 if (Date_Holidays::isError($day)) { 61 die('Factory was unable to make newYearsDay'); 62 } 63 $this->assertEquals(12, $day->getMonth()); 64 $this->assertEquals(31, $day->getDay()); 65 $this->assertEquals(2004, $day->getYear()); 66 67 // Test Martin Luther King Day 68 $day = $holidays->getHolidayDate('mlkDay'); 69 if (Date_Holidays::isError($day)) { 70 die('Factory was unable to that day'); 71 } 72 73 $this->assertEquals(1, $day->getMonth()); 74 $this->assertEquals(17, $day->getDay()); 75 76 // Test Prez Day Luther King Day 77 $day = $holidays->getHolidayDate('presidentsDay'); 78 if (Date_Holidays::isError($day)) { 79 die('Factory was unable to that day'); 80 } 81 $this->assertEquals(2, $day->getMonth()); 82 $this->assertEquals(21, $day->getDay()); 83 84 // Test Memorial Day Luther King Day 85 $day = $holidays->getHolidayDate('memorialDay'); 86 if (Date_Holidays::isError($day)) { 87 die('Factory was unable to create memorialDay day'); 88 } 89 $this->assertEquals(5, $day->getMonth()); 90 $this->assertEquals(30, $day->getDay()); 91 92 // Test 4th of July, It was on sunday this year 93 $day = $holidays->getHolidayDate('independenceDay'); 94 if (Date_Holidays::isError($day)) { 95 die('Factory was unable to create independenceDay day'); 96 } 97 $this->assertEquals(7, $day->getMonth()); 98 $this->assertEquals(4, $day->getDay()); 99 100 // Test Labor Day, end of summer 101 $day = $holidays->getHolidayDate('laborDay'); 102 if (Date_Holidays::isError($day)) { 103 die('Factory was unable to create laborDay day'); 104 } 105 $this->assertEquals(9, $day->getMonth()); 106 $this->assertEquals(5, $day->getDay()); 107 108 // Test Columbus Day, end of summer 109 $day = $holidays->getHolidayDate('columbusDay'); 110 if (Date_Holidays::isError($day)) { 111 die('Factory was unable to create columbusDay day'); 112 } 113 $this->assertEquals(10, $day->getMonth()); 114 $this->assertEquals(10, $day->getDay()); 115 116 // Test Veteran's Day 117 $day = $holidays->getHolidayDate('veteransDay'); 118 if (Date_Holidays::isError($day)) { 119 die('Factory was unable to create veteransDay day'); 120 } 121 $this->assertEquals(11, $day->getMonth()); 122 $this->assertEquals(11, $day->getDay()); 123 124 // Test Thanksgiving Day 125 $day = $holidays->getHolidayDate('thanksgivingDay'); 126 if (Date_Holidays::isError($day)) { 127 die('Factory was unable to create thanksgivingDay day'); 128 } 129 $this->assertEquals(11, $day->getMonth()); 130 $this->assertEquals(24, $day->getDay()); 131 132 // Test Christmas Day 133 $day = $holidays->getHolidayDate('christmasDay'); 134 if (Date_Holidays::isError($day)) { 135 die('Factory was unable to create christmasDay day'); 136 } 137 $this->assertEquals(12, $day->getMonth()); 138 $this->assertEquals(26, $day->getDay()); 139 $this->assertFalse($day->getDay() == 25); 140 141 } 142 143 /** 144 * tests for holidays in 2004 145 * 146 * @access public 147 * @return void 148 */ 149 function testHolidays2004() 150 { 151 152 $holidays = Date_Holidays::factory('USA', 2004, 'en_EN'); 153 if (Date_Holidays::isError($holidays)) { 154 die('Factory was unable to produce driver-object'); 155 } 156 157 158 // Test Martin Luther King Day 159 $day = $holidays->getHolidayDate('mlkDay'); 160 if (Date_Holidays::isError($day)) { 161 die('Factory was unable to that day'); 162 } 163 164 $this->assertTrue($day->getMonth()==1 && $day->getDay()==19); 165 $this->assertEquals(1, $day->getMonth()); 166 $this->assertEquals(19, $day->getDay()); 167 168 // Test Prez Day Luther King Day 169 $day = $holidays->getHolidayDate('presidentsDay'); 170 if (Date_Holidays::isError($day)) { 171 die('Factory was unable to that day'); 172 } 173 $this->assertEquals(2, $day->getMonth()); 174 $this->assertEquals(16, $day->getDay()); 175 176 // Test Memorial Day Luther King Day 177 $day = $holidays->getHolidayDate('memorialDay'); 178 if (Date_Holidays::isError($day)) { 179 die('Factory was unable to create memorialDay day'); 180 } 181 $this->assertEquals(5, $day->getMonth()); 182 $this->assertEquals(31, $day->getDay()); 183 184 // Test 4th of July, It was on sunday this year 185 $day = $holidays->getHolidayDate('independenceDay'); 186 if (Date_Holidays::isError($day)) { 187 die('Factory was unable to create independenceDay day'); 188 } 189 $this->assertEquals(7, $day->getMonth()); 190 $this->assertEquals(5, $day->getDay()); 191 192 // Test Labor Day, end of summer 193 $day = $holidays->getHolidayDate('laborDay'); 194 if (Date_Holidays::isError($day)) { 195 die('Factory was unable to create laborDay day'); 196 } 197 $this->assertEquals(9, $day->getMonth()); 198 $this->assertEquals(6, $day->getDay()); 199 200 // Test Columbus Day, end of summer 201 $day = $holidays->getHolidayDate('columbusDay'); 202 if (Date_Holidays::isError($day)) { 203 die('Factory was unable to create columbusDay day'); 204 } 205 $this->assertEquals(10, $day->getMonth()); 206 $this->assertEquals(11, $day->getDay()); 207 208 // Test Veteran's Day 209 $day = $holidays->getHolidayDate('veteransDay'); 210 if (Date_Holidays::isError($day)) { 211 die('Factory was unable to create veteransDay day'); 212 } 213 $this->assertEquals(11, $day->getMonth()); 214 $this->assertEquals(11, $day->getDay()); 215 216 // Test Thanksgiving Day 217 $day = $holidays->getHolidayDate('thanksgivingDay'); 218 if (Date_Holidays::isError($day)) { 219 die('Factory was unable to create thanksgivingDay day'); 220 } 221 $this->assertEquals(11, $day->getMonth()); 222 $this->assertEquals(25, $day->getDay()); 223 224 // Test Christmas Day 225 $day = $holidays->getHolidayDate('christmasDay'); 226 if (Date_Holidays::isError($day)) { 227 die('Factory was unable to create christmasDay day'); 228 } 229 $this->assertEquals(12, $day->getMonth()); 230 $this->assertEquals(24, $day->getDay()); 231 232 } 233 234 /** 235 * tests for holidays in 2006 236 * 237 * @access public 238 * @return void 239 */ 240 function testHolidays2006() 241 { 242 243 $holidays = Date_Holidays::factory('USA', 2006, 'en_EN'); 244 if (Date_Holidays::isError($holidays)) { 245 die('Factory was unable to produce driver-object'); 246 } 247 248 // Test New Year Day -- it comes a day late this year 249 $day = $holidays->getHolidayDate('newYearsDay'); 250 if (Date_Holidays::isError($day)) { 251 die('Factory was unable to make newYearsDay'); 252 } 253 $this->assertEquals(1, $day->getMonth()); 254 $this->assertEquals(2, $day->getDay()); 255 $this->assertEquals(2006, $day->getYear()); 256 257 // Test Martin Luther King Day 258 $day = $holidays->getHolidayDate('mlkDay'); 259 if (Date_Holidays::isError($day)) { 260 die('Factory was unable to that day'); 261 } 262 263 $this->assertEquals(1, $day->getMonth()); 264 $this->assertEquals(16, $day->getDay()); 265 266 // Test Prez Day Luther King Day 267 $day = $holidays->getHolidayDate('presidentsDay'); 268 if (Date_Holidays::isError($day)) { 269 die('Factory was unable to that day'); 270 } 271 $this->assertEquals(2, $day->getMonth()); 272 $this->assertEquals(20, $day->getDay()); 273 274 // Test Memorial Day 275 $day = $holidays->getHolidayDate('memorialDay'); 276 if (Date_Holidays::isError($day)) { 277 die('Factory was unable to create memorialDay day'); 278 } 279 $this->assertEquals(5, $day->getMonth()); 280 $this->assertEquals(29, $day->getDay()); 281 282 // Test 4th of July, It was on sunday this year 283 $day = $holidays->getHolidayDate('independenceDay'); 284 if (Date_Holidays::isError($day)) { 285 die('Factory was unable to create independenceDay day'); 286 } 287 $this->assertEquals(7, $day->getMonth()); 288 $this->assertEquals(4, $day->getDay()); 289 290 // Test Labor Day, end of summer 291 $day = $holidays->getHolidayDate('laborDay'); 292 if (Date_Holidays::isError($day)) { 293 die('Factory was unable to create laborDay day'); 294 } 295 $this->assertEquals(9, $day->getMonth()); 296 $this->assertEquals(4, $day->getDay()); 297 298 // Test Columbus Day, end of summer 299 $day = $holidays->getHolidayDate('columbusDay'); 300 if (Date_Holidays::isError($day)) { 301 die('Factory was unable to create columbusDay day'); 302 } 303 $this->assertEquals(10, $day->getMonth()); 304 $this->assertEquals(9, $day->getDay()); 305 306 // Test Veteran's Day 307 $day = $holidays->getHolidayDate('veteransDay'); 308 if (Date_Holidays::isError($day)) { 309 die('Factory was unable to create veteransDay day'); 310 } 311 $this->assertEquals(11, $day->getMonth()); 312 $this->assertEquals(11, $day->getDay()); 313 314 // Test Thanksgiving Day 315 $day = $holidays->getHolidayDate('thanksgivingDay'); 316 if (Date_Holidays::isError($day)) { 317 die('Factory was unable to create thanksgivingDay day'); 318 } 319 $this->assertEquals(11, $day->getMonth()); 320 $this->assertEquals(23, $day->getDay()); 321 322 // Test Christmas Day 323 $day = $holidays->getHolidayDate('christmasDay'); 324 if (Date_Holidays::isError($day)) { 325 die('Factory was unable to create christmasDay day'); 326 } 327 $this->assertEquals(12, $day->getMonth()); 328 $this->assertEquals(25, $day->getDay()); 329 $this->assertFalse($day->getDay() == 27); 330 331 } 332 /** 333 * test holidays 334 * 335 * @access public 336 * @return void 337 */ 338 function testHolidays() 339 { 340 $holidays = Date_Holidays::factory('USA', 2004, 'en_EN'); 341 if (Date_Holidays::isError($holidays)) { 342 die('Factory was unable to produce driver-object'); 343 344 } 345 // this was labor day this year 346 $this->assertTrue($holidays->isHoliday(new Date('2004-09-06'))); 347 // this was thanksgiving year 348 $this->assertTrue($holidays->isHoliday(new Date('2004-11-25'))); 349 // Chrismas is on the 24th 350 $this->assertFalse($holidays->isHoliday(new Date('2004-12-25'))); 351 // Chrismas is on the 24th 352 $this->assertTrue($holidays->isHoliday(new Date('2004-12-24'))); 353 } 354 355} 356 357?> 358