| | 1 | <?php |
| | 2 | if(!defined("PIWIK_PATH_TEST_TO_ROOT")) { |
| | 3 | define('PIWIK_PATH_TEST_TO_ROOT', getcwd().'/../..'); |
| | 4 | } |
| | 5 | if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) |
| | 6 | { |
| | 7 | require_once PIWIK_PATH_TEST_TO_ROOT . "/tests/config_test.php"; |
| | 8 | } |
| | 9 | |
| | 10 | require_once 'ScheduledTime.php'; |
| | 11 | require_once 'ScheduledTime/Hourly.php'; |
| | 12 | require_once 'ScheduledTime/Daily.php'; |
| | 13 | require_once 'ScheduledTime/Weekly.php'; |
| | 14 | require_once 'ScheduledTime/Monthly.php'; |
| | 15 | |
| | 16 | Mock::generatePartial('Piwik_ScheduledTime_Hourly', 'Piwik_ScheduledTime_Hourly_Test', array('getTime')); |
| | 17 | Mock::generatePartial('Piwik_ScheduledTime_Daily', 'Piwik_ScheduledTime_Daily_Test', array('getTime')); |
| | 18 | Mock::generatePartial('Piwik_ScheduledTime_Weekly', 'Piwik_ScheduledTime_Weekly_Test', array('getTime')); |
| | 19 | Mock::generatePartial('Piwik_ScheduledTime_Monthly', 'Piwik_ScheduledTime_Monthly_Test', array('getTime')); |
| | 20 | |
| | 21 | class Test_Piwik_ScheduledTime extends UnitTestCase |
| | 22 | { |
| | 23 | private $JANUARY_01_1971_09_00_00; |
| | 24 | private $JANUARY_01_1971_09_10_00; |
| | 25 | private $JANUARY_01_1971_10_00_00; |
| | 26 | private $JANUARY_01_1971_10_10_00; |
| | 27 | private $JANUARY_01_1971_11_00_00; |
| | 28 | private $JANUARY_01_1971_12_00_00; |
| | 29 | private $JANUARY_01_1971_12_10_00; |
| | 30 | |
| | 31 | private $JANUARY_02_1971_09_00_00; |
| | 32 | private $JANUARY_02_1971_09_10_00; |
| | 33 | private $JANUARY_02_1971_12_10_00; |
| | 34 | |
| | 35 | private $JANUARY_03_1971_12_10_00; |
| | 36 | |
| | 37 | private $JANUARY_04_1971_09_00_00; |
| | 38 | private $JANUARY_04_1971_09_10_00; |
| | 39 | private $JANUARY_04_1971_12_10_00; |
| | 40 | |
| | 41 | private $JANUARY_05_1971_09_00_00; |
| | 42 | private $JANUARY_05_1971_09_10_00; |
| | 43 | private $JANUARY_05_1971_12_00_00; |
| | 44 | |
| | 45 | private $JANUARY_08_1971_09_00_00; |
| | 46 | private $JANUARY_08_1971_09_10_00; |
| | 47 | |
| | 48 | private $JANUARY_09_1971_09_00_00; |
| | 49 | private $JANUARY_09_1971_09_10_00; |
| | 50 | |
| | 51 | private $JANUARY_11_1971_09_00_00; |
| | 52 | private $JANUARY_11_1971_09_10_00; |
| | 53 | |
| | 54 | private $JANUARY_12_1971_09_00_00; |
| | 55 | private $JANUARY_18_1971_09_00_00; |
| | 56 | private $JANUARY_19_1971_09_00_00; |
| | 57 | |
| | 58 | private $JANUARY_25_1971_09_00_00; |
| | 59 | private $JANUARY_26_1971_09_00_00; |
| | 60 | |
| | 61 | private $FEBRUARY_01_1971_09_00_00; |
| | 62 | private $FEBRUARY_02_1971_09_00_00; |
| | 63 | private $FEBRUARY_03_1971_09_00_00; |
| | 64 | private $FEBRUARY_03_1971_12_10_00; |
| | 65 | private $FEBRUARY_04_1971_09_00_00; |
| | 66 | private $FEBRUARY_04_1971_12_10_00; |
| | 67 | private $FEBRUARY_05_1971_09_00_00; |
| | 68 | private $FEBRUARY_08_1971_09_00_00; |
| | 69 | private $FEBRUARY_15_1971_09_00_00; |
| | 70 | private $FEBRUARY_16_1971_09_00_00; |
| | 71 | private $FEBRUARY_17_1971_09_00_00; |
| | 72 | |
| | 73 | private $MARCH_05_1971_09_00_00; |
| | 74 | |
| | 75 | function __construct( $title = '') |
| | 76 | { |
| | 77 | $this->JANUARY_01_1971_09_00_00 = mktime(9,00,00,1,1,1971); |
| | 78 | $this->JANUARY_01_1971_09_10_00 = mktime(9,10,00,1,1,1971); |
| | 79 | $this->JANUARY_01_1971_10_00_00 = mktime(10,00,00,1,1,1971); |
| | 80 | $this->JANUARY_01_1971_10_10_00 = mktime(10,10,00,1,1,1971); |
| | 81 | $this->JANUARY_01_1971_11_00_00 = mktime(11,00,00,1,1,1971); |
| | 82 | $this->JANUARY_01_1971_12_00_00 = mktime(12,00,00,1,1,1971); |
| | 83 | $this->JANUARY_01_1971_12_10_00 = mktime(12,10,00,1,1,1971); |
| | 84 | |
| | 85 | $this->JANUARY_02_1971_09_00_00 = mktime(9,00,00,1,2,1971); |
| | 86 | $this->JANUARY_02_1971_09_10_00 = mktime(9,10,00,1,2,1971); |
| | 87 | $this->JANUARY_02_1971_12_10_00 = mktime(12,10,00,1,2,1971); |
| | 88 | |
| | 89 | $this->JANUARY_03_1971_12_10_00 = mktime(12,10,00,1,3,1971); |
| | 90 | |
| | 91 | $this->JANUARY_04_1971_09_00_00 = mktime(9,00,00,1,4,1971); |
| | 92 | $this->JANUARY_04_1971_09_10_00 = mktime(9,10,00,1,4,1971); |
| | 93 | $this->JANUARY_04_1971_12_10_00 = mktime(12,10,00,1,4,1971); |
| | 94 | |
| | 95 | $this->JANUARY_05_1971_09_00_00 = mktime(9,00,00,1,5,1971); |
| | 96 | $this->JANUARY_05_1971_09_10_00 = mktime(9,10,00,1,5,1971); |
| | 97 | $this->JANUARY_05_1971_12_00_00 = mktime(12,00,00,1,5,1971); |
| | 98 | |
| | 99 | $this->JANUARY_08_1971_09_00_00 = mktime(9,00,00,1,8,1971); |
| | 100 | $this->JANUARY_08_1971_09_10_00 = mktime(9,10,00,1,8,1971); |
| | 101 | |
| | 102 | $this->JANUARY_09_1971_09_00_00 = mktime(9,00,00,1,9,1971); |
| | 103 | $this->JANUARY_09_1971_09_10_00 = mktime(9,10,00,1,9,1971); |
| | 104 | |
| | 105 | $this->JANUARY_11_1971_09_00_00 = mktime(9,00,00,1,11,1971); |
| | 106 | $this->JANUARY_11_1971_09_10_00 = mktime(9,10,00,1,11,1971); |
| | 107 | |
| | 108 | $this->JANUARY_12_1971_09_00_00 = mktime(9,00,00,1,12,1971); |
| | 109 | $this->JANUARY_18_1971_09_00_00 = mktime(9,00,00,1,18,1971); |
| | 110 | $this->JANUARY_19_1971_09_00_00 = mktime(9,00,00,1,19,1971); |
| | 111 | |
| | 112 | $this->JANUARY_25_1971_09_00_00 = mktime(9,00,00,1,25,1971); |
| | 113 | $this->JANUARY_26_1971_09_00_00 = mktime(9,00,00,1,26,1971); |
| | 114 | |
| | 115 | $this->FEBRUARY_01_1971_09_00_00 = mktime(9,00,00,2,1,1971); |
| | 116 | $this->FEBRUARY_02_1971_09_00_00 = mktime(9,00,00,2,2,1971); |
| | 117 | $this->FEBRUARY_03_1971_09_00_00 = mktime(9,00,00,2,3,1971); |
| | 118 | $this->FEBRUARY_03_1971_12_10_00 = mktime(12,10,00,2,3,1971); |
| | 119 | $this->FEBRUARY_04_1971_09_00_00 = mktime(9,00,00,2,4,1971); |
| | 120 | $this->FEBRUARY_04_1971_12_10_00 = mktime(12,10,00,2,4,1971); |
| | 121 | $this->FEBRUARY_05_1971_09_00_00 = mktime(9,00,00,2,5,1971); |
| | 122 | $this->FEBRUARY_08_1971_09_00_00 = mktime(9,00,00,2,8,1971); |
| | 123 | $this->FEBRUARY_15_1971_09_00_00 = mktime(9,00,00,2,15,1971); |
| | 124 | $this->FEBRUARY_16_1971_09_00_00 = mktime(9,00,00,2,16,1971); |
| | 125 | $this->FEBRUARY_17_1971_09_00_00 = mktime(9,00,00,2,17,1971); |
| | 126 | |
| | 127 | $this->MARCH_05_1971_09_00_00 = mktime(9,00,00,3,5,1971); |
| | 128 | |
| | 129 | parent::__construct( $title ); |
| | 130 | } |
| | 131 | |
| | 132 | /* |
| | 133 | * Tests forbidden call to setHour on Piwik_ScheduledTime_Hourly |
| | 134 | */ |
| | 135 | public function test_setHour_ScheduledTime_Hourly() |
| | 136 | { |
| | 137 | try { |
| | 138 | $hourlySchedule = new Piwik_ScheduledTime_Hourly(); |
| | 139 | $hourlySchedule->setHour(0); |
| | 140 | $this->fail("Exception not raised."); |
| | 141 | } |
| | 142 | catch (Exception $expected) { |
| | 143 | $this->pass(); |
| | 144 | return; |
| | 145 | } |
| | 146 | } |
| | 147 | |
| | 148 | /* |
| | 149 | * Tests invalid call to setHour on Piwik_ScheduledTime_Daily |
| | 150 | */ |
| | 151 | public function test_setHour_ScheduledTime_Daily_Negative() |
| | 152 | { |
| | 153 | try { |
| | 154 | $dailySchedule = new Piwik_ScheduledTime_Daily(); |
| | 155 | $dailySchedule->setHour(-1); |
| | 156 | $this->fail("Exception not raised."); |
| | 157 | } |
| | 158 | catch (Exception $expected) { |
| | 159 | $this->pass(); |
| | 160 | return; |
| | 161 | } |
| | 162 | } |
| | 163 | |
| | 164 | /* |
| | 165 | * Tests invalid call to setHour on Piwik_ScheduledTime_Daily |
| | 166 | */ |
| | 167 | public function test_setHour_ScheduledTime_Daily_Over_24() |
| | 168 | { |
| | 169 | try { |
| | 170 | $dailySchedule = new Piwik_ScheduledTime_Daily(); |
| | 171 | $dailySchedule->setHour(25); |
| | 172 | $this->fail("Exception not raised."); |
| | 173 | } |
| | 174 | catch (Exception $expected) { |
| | 175 | $this->pass(); |
| | 176 | return; |
| | 177 | } |
| | 178 | } |
| | 179 | |
| | 180 | /* |
| | 181 | * Tests invalid call to setHour on Piwik_ScheduledTime_Weekly |
| | 182 | */ |
| | 183 | public function test_setHour_ScheduledTime_Weekly_Negative() |
| | 184 | { |
| | 185 | try { |
| | 186 | $weeklySchedule = new Piwik_ScheduledTime_Weekly(); |
| | 187 | $weeklySchedule->setHour(-1); |
| | 188 | $this->fail("Exception not raised."); |
| | 189 | } |
| | 190 | catch (Exception $expected) { |
| | 191 | $this->pass(); |
| | 192 | return; |
| | 193 | } |
| | 194 | } |
| | 195 | |
| | 196 | /* |
| | 197 | * Tests invalid call to setHour on Piwik_ScheduledTime_Weekly |
| | 198 | */ |
| | 199 | public function test_setHour_ScheduledTime_Weekly_Over_24() |
| | 200 | { |
| | 201 | try { |
| | 202 | $weeklySchedule = new Piwik_ScheduledTime_Weekly(); |
| | 203 | $weeklySchedule->setHour(25); |
| | 204 | $this->fail("Exception not raised."); |
| | 205 | } |
| | 206 | catch (Exception $expected) { |
| | 207 | $this->pass(); |
| | 208 | return; |
| | 209 | } |
| | 210 | } |
| | 211 | |
| | 212 | /* |
| | 213 | * Tests invalid call to setHour on Piwik_ScheduledTime_Monthly |
| | 214 | */ |
| | 215 | public function test_setHour_ScheduledTime_Monthly_Negative() |
| | 216 | { |
| | 217 | try { |
| | 218 | $monthlySchedule = new Piwik_ScheduledTime_Monthly(); |
| | 219 | $monthlySchedule->setHour(-1); |
| | 220 | $this->fail("Exception not raised."); |
| | 221 | } |
| | 222 | catch (Exception $expected) { |
| | 223 | $this->pass(); |
| | 224 | return; |
| | 225 | } |
| | 226 | } |
| | 227 | |
| | 228 | /* |
| | 229 | * Tests invalid call to setHour on Piwik_ScheduledTime_Monthly |
| | 230 | */ |
| | 231 | public function test_setHour_ScheduledTime_Monthly_Over_24() |
| | 232 | { |
| | 233 | try { |
| | 234 | $monthlySchedule = new Piwik_ScheduledTime_Monthly(); |
| | 235 | $monthlySchedule->setHour(25); |
| | 236 | $this->fail("Exception not raised."); |
| | 237 | } |
| | 238 | catch (Exception $expected) { |
| | 239 | $this->pass(); |
| | 240 | return; |
| | 241 | } |
| | 242 | } |
| | 243 | |
| | 244 | /* |
| | 245 | * Tests forbidden call to setDay on Piwik_ScheduledTime_Hourly |
| | 246 | */ |
| | 247 | public function test_setDay_ScheduledTime_Hourly() |
| | 248 | { |
| | 249 | try { |
| | 250 | $hourlySchedule = new Piwik_ScheduledTime_Hourly(); |
| | 251 | $hourlySchedule->setDay(1); |
| | 252 | $this->fail("Exception not raised."); |
| | 253 | } |
| | 254 | catch (Exception $expected) { |
| | 255 | $this->pass(); |
| | 256 | return; |
| | 257 | } |
| | 258 | } |
| | 259 | |
| | 260 | /* |
| | 261 | * Tests forbidden call to setDay on Piwik_ScheduledTime_Daily |
| | 262 | */ |
| | 263 | public function test_setDay_ScheduledTime_Daily() |
| | 264 | { |
| | 265 | try { |
| | 266 | $dailySchedule = new Piwik_ScheduledTime_Daily(); |
| | 267 | $dailySchedule->setDay(1); |
| | 268 | $this->fail("Exception not raised."); |
| | 269 | } |
| | 270 | catch (Exception $expected) { |
| | 271 | $this->pass(); |
| | 272 | return; |
| | 273 | } |
| | 274 | } |
| | 275 | |
| | 276 | /* |
| | 277 | * Tests invalid call to setDay on Piwik_ScheduledTime_Weekly |
| | 278 | */ |
| | 279 | public function test_setDay_ScheduledTime_Weekly_Day_0() |
| | 280 | { |
| | 281 | try { |
| | 282 | $weeklySchedule = new Piwik_ScheduledTime_Weekly(); |
| | 283 | $weeklySchedule->setDay(0); |
| | 284 | $this->fail("Exception not raised."); |
| | 285 | } |
| | 286 | catch (Exception $expected) { |
| | 287 | $this->pass(); |
| | 288 | return; |
| | 289 | } |
| | 290 | } |
| | 291 | |
| | 292 | /* |
| | 293 | * Tests invalid call to setDay on Piwik_ScheduledTime_Weekly |
| | 294 | */ |
| | 295 | public function test_setDay_ScheduledTime_Weekly_Over_7() |
| | 296 | { |
| | 297 | try { |
| | 298 | $weeklySchedule = new Piwik_ScheduledTime_Weekly(); |
| | 299 | $weeklySchedule->setDay(8); |
| | 300 | $this->fail("Exception not raised."); |
| | 301 | } |
| | 302 | catch (Exception $expected) { |
| | 303 | $this->pass(); |
| | 304 | return; |
| | 305 | } |
| | 306 | } |
| | 307 | |
| | 308 | /* |
| | 309 | * Tests invalid call to setDay on Piwik_ScheduledTime_Monthly |
| | 310 | */ |
| | 311 | public function test_setDay_ScheduledTime_Monthly_Day_0() |
| | 312 | { |
| | 313 | try { |
| | 314 | $monthlySchedule = new Piwik_ScheduledTime_Monthly(); |
| | 315 | $monthlySchedule->setDay(0); |
| | 316 | $this->fail("Exception not raised."); |
| | 317 | } |
| | 318 | catch (Exception $expected) { |
| | 319 | $this->pass(); |
| | 320 | return; |
| | 321 | } |
| | 322 | } |
| | 323 | |
| | 324 | /* |
| | 325 | * Tests invalid call to setDay on Piwik_ScheduledTime_Monthly |
| | 326 | */ |
| | 327 | public function test_setDay_ScheduledTime_Monthly_Over_7() |
| | 328 | { |
| | 329 | try { |
| | 330 | $monthlySchedule = new Piwik_ScheduledTime_Monthly(); |
| | 331 | $monthlySchedule->setDay(8); |
| | 332 | $this->fail("Exception not raised."); |
| | 333 | } |
| | 334 | catch (Exception $expected) { |
| | 335 | $this->pass(); |
| | 336 | return; |
| | 337 | } |
| | 338 | } |
| | 339 | |
| | 340 | /* |
| | 341 | * Tests forbidden call to setWeek on Piwik_ScheduledTime_Hourly |
| | 342 | */ |
| | 343 | public function test_setWeek_ScheduledTime_Hourly() |
| | 344 | { |
| | 345 | try { |
| | 346 | $hourlySchedule = new Piwik_ScheduledTime_Hourly(); |
| | 347 | $hourlySchedule->setWeek(1); |
| | 348 | $this->fail("Exception not raised."); |
| | 349 | } |
| | 350 | catch (Exception $expected) { |
| | 351 | $this->pass(); |
| | 352 | return; |
| | 353 | } |
| | 354 | } |
| | 355 | |
| | 356 | /* |
| | 357 | * Tests forbidden call to setWeek on Piwik_ScheduledTime_Daily |
| | 358 | */ |
| | 359 | public function test_setWeek_ScheduledTime_Daily() |
| | 360 | { |
| | 361 | try { |
| | 362 | $dailySchedule = new Piwik_ScheduledTime_Daily(); |
| | 363 | $dailySchedule->setWeek(1); |
| | 364 | $this->fail("Exception not raised."); |
| | 365 | } |
| | 366 | catch (Exception $expected) { |
| | 367 | $this->pass(); |
| | 368 | return; |
| | 369 | } |
| | 370 | } |
| | 371 | |
| | 372 | /* |
| | 373 | * Tests forbidden call to setWeek on Piwik_ScheduledTime_Weekly |
| | 374 | */ |
| | 375 | public function test_setWeek_ScheduledTime_Weekly() |
| | 376 | { |
| | 377 | try { |
| | 378 | $weeklySchedule = new Piwik_ScheduledTime_Weekly(); |
| | 379 | $weeklySchedule->setWeek(1); |
| | 380 | $this->fail("Exception not raised."); |
| | 381 | } |
| | 382 | catch (Exception $expected) { |
| | 383 | $this->pass(); |
| | 384 | return; |
| | 385 | } |
| | 386 | } |
| | 387 | |
| | 388 | /* |
| | 389 | * Tests invalid call to setWeek on Piwik_ScheduledTime_Monthly |
| | 390 | */ |
| | 391 | public function test_setWeek_ScheduledTime_Monthly_Week_0() |
| | 392 | { |
| | 393 | try { |
| | 394 | $monthlySchedule = new Piwik_ScheduledTime_Monthly(); |
| | 395 | $monthlySchedule->setWeek(0); |
| | 396 | $this->fail("Exception not raised."); |
| | 397 | } |
| | 398 | catch (Exception $expected) { |
| | 399 | $this->pass(); |
| | 400 | return; |
| | 401 | } |
| | 402 | } |
| | 403 | |
| | 404 | /* |
| | 405 | * Tests invalid call to setWeek on Piwik_ScheduledTime_Monthly |
| | 406 | */ |
| | 407 | public function test_setWeek_ScheduledTime_Monthly_Over_4() |
| | 408 | { |
| | 409 | try { |
| | 410 | $monthlySchedule = new Piwik_ScheduledTime_Monthly(); |
| | 411 | $monthlySchedule->setWeek(5); |
| | 412 | $this->fail("Exception not raised."); |
| | 413 | } |
| | 414 | catch (Exception $expected) { |
| | 415 | $this->pass(); |
| | 416 | return; |
| | 417 | } |
| | 418 | } |
| | 419 | |
| | 420 | /* |
| | 421 | * Tests getRescheduledTime on Piwik_ScheduledTime_Hourly |
| | 422 | * |
| | 423 | */ |
| | 424 | public function test_getRescheduledTime_Hourly() |
| | 425 | { |
| | 426 | |
| | 427 | /* |
| | 428 | * Test 1 |
| | 429 | * |
| | 430 | * Context : |
| | 431 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 432 | * - getRescheduledTime is called within the same second as the cron task |
| | 433 | * |
| | 434 | * Expected : |
| | 435 | * getRescheduledTime returns January 1 1971 10:00:00 GMT |
| | 436 | */ |
| | 437 | $hourlySchedule = new Piwik_ScheduledTime_Hourly_Test(); |
| | 438 | $hourlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_00_00); |
| | 439 | $this->assertEqual($hourlySchedule->getRescheduledTime(), $this->JANUARY_01_1971_10_00_00); |
| | 440 | |
| | 441 | /* |
| | 442 | * Test 2 |
| | 443 | * |
| | 444 | * Context : |
| | 445 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 446 | * - getRescheduledTime is called 10 minutes after the cron task to simulate a previous task |
| | 447 | * |
| | 448 | * Expected : |
| | 449 | * getRescheduledTime returns January 1 1971 10:00:00 GMT |
| | 450 | */ |
| | 451 | $hourlySchedule = new Piwik_ScheduledTime_Hourly_Test(); |
| | 452 | $hourlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_10_00); |
| | 453 | $this->assertEqual($hourlySchedule->getRescheduledTime(), $this->JANUARY_01_1971_10_00_00); |
| | 454 | |
| | 455 | /* |
| | 456 | * Test 3 |
| | 457 | * |
| | 458 | * Context : |
| | 459 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 460 | * - getRescheduledTime is called 1 hour and 10 minutes after the cron task to simulate a long previous task |
| | 461 | * |
| | 462 | * Expected : |
| | 463 | * getRescheduledTime returns January 1 1971 11:00:00 GMT |
| | 464 | */ |
| | 465 | $hourlySchedule = new Piwik_ScheduledTime_Hourly_Test(); |
| | 466 | $hourlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_10_10_00); |
| | 467 | $this->assertEqual($hourlySchedule->getRescheduledTime(), $this->JANUARY_01_1971_11_00_00); |
| | 468 | } |
| | 469 | |
| | 470 | /* |
| | 471 | * Tests getRescheduledTime on Piwik_ScheduledTime_Daily with unspecified hour |
| | 472 | * |
| | 473 | */ |
| | 474 | public function test_getRescheduledTime_Daily_Unspecified_Hour() |
| | 475 | { |
| | 476 | |
| | 477 | /* |
| | 478 | * Test 1 |
| | 479 | * |
| | 480 | * Context : |
| | 481 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 482 | * - getRescheduledTime is called within the same second as the cron task |
| | 483 | * - setHour is not called, no need to control the scheduled hour |
| | 484 | * |
| | 485 | * Expected : |
| | 486 | * getRescheduledTime returns January 2 1971 09:00:00 GMT |
| | 487 | */ |
| | 488 | $hourlySchedule = new Piwik_ScheduledTime_Daily_Test(); |
| | 489 | $hourlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_00_00); |
| | 490 | $this->assertEqual($hourlySchedule->getRescheduledTime(), $this->JANUARY_02_1971_09_00_00); |
| | 491 | |
| | 492 | /* |
| | 493 | * Test 2 |
| | 494 | * |
| | 495 | * Context : |
| | 496 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 497 | * - getRescheduledTime is called 10 minutes after the cron task to simulate a previous task |
| | 498 | * - setHour is not called, no need to control the scheduled hour |
| | 499 | * |
| | 500 | * Expected : |
| | 501 | * getRescheduledTime returns January 2 1971 09:10:00 GMT |
| | 502 | * The task would then be executed at January 2 1971 10:00:00 which is ok because setHour has not been called |
| | 503 | */ |
| | 504 | $hourlySchedule = new Piwik_ScheduledTime_Daily_Test(); |
| | 505 | $hourlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_10_00); |
| | 506 | $this->assertEqual($hourlySchedule->getRescheduledTime(), $this->JANUARY_02_1971_09_10_00); |
| | 507 | } |
| | 508 | |
| | 509 | /* |
| | 510 | * Tests getRescheduledTime on Piwik_ScheduledTime_Daily with specified hour |
| | 511 | * |
| | 512 | */ |
| | 513 | public function test_getRescheduledTime_Daily_Specified_Hour() |
| | 514 | { |
| | 515 | |
| | 516 | /* |
| | 517 | * Test 1 |
| | 518 | * |
| | 519 | * Context : |
| | 520 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 521 | * - getRescheduledTime is called within the same second as the cron task |
| | 522 | * - setHour is set to 9 |
| | 523 | * |
| | 524 | * Expected : |
| | 525 | * getRescheduledTime returns January 2 1971 09:00:00 GMT |
| | 526 | */ |
| | 527 | $hourlySchedule = new Piwik_ScheduledTime_Daily_Test(); |
| | 528 | $hourlySchedule->setHour(9); |
| | 529 | $hourlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_00_00); |
| | 530 | $this->assertEqual($hourlySchedule->getRescheduledTime(), $this->JANUARY_02_1971_09_00_00); |
| | 531 | |
| | 532 | /* |
| | 533 | * Test 2 |
| | 534 | * |
| | 535 | * Context : |
| | 536 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 537 | * - getRescheduledTime is called 10 minutes after the cron task to simulate a previous task |
| | 538 | * - setHour is set to 9 |
| | 539 | * |
| | 540 | * Expected : |
| | 541 | * getRescheduledTime returns January 2 1971 09:00:00 GMT |
| | 542 | */ |
| | 543 | $hourlySchedule = new Piwik_ScheduledTime_Daily_Test(); |
| | 544 | $hourlySchedule->setHour(9); |
| | 545 | $hourlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_10_00); |
| | 546 | $this->assertEqual($hourlySchedule->getRescheduledTime(), $this->JANUARY_02_1971_09_00_00); |
| | 547 | |
| | 548 | /* |
| | 549 | * Test 3 |
| | 550 | * |
| | 551 | * Context : |
| | 552 | * - Cron fails to run at January 1 1971 09:00:00 GMT, runs at January 1 1971 12:00:00 GMT |
| | 553 | * - getRescheduledTime is called within the same second as the cron task |
| | 554 | * - setHour is set to 9 |
| | 555 | * |
| | 556 | * Expected : |
| | 557 | * getRescheduledTime returns January 2 1971 09:00:00 GMT |
| | 558 | */ |
| | 559 | $hourlySchedule = new Piwik_ScheduledTime_Daily_Test(); |
| | 560 | $hourlySchedule->setHour(9); |
| | 561 | $hourlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_12_00_00); |
| | 562 | $this->assertEqual($hourlySchedule->getRescheduledTime(), $this->JANUARY_02_1971_09_00_00); |
| | 563 | |
| | 564 | /* |
| | 565 | * Test 4 |
| | 566 | * |
| | 567 | * Context : |
| | 568 | * - Cron fails to run at January 1 1971 09:00:00 GMT, runs at January 1 1971 12:00:00 GMT |
| | 569 | * - getRescheduledTime is called 10 minutes after the cron task to simulate a previous task |
| | 570 | * - setHour is set to 9 |
| | 571 | * |
| | 572 | * Expected : |
| | 573 | * getRescheduledTime returns January 2 1971 09:00:00 GMT |
| | 574 | */ |
| | 575 | $hourlySchedule = new Piwik_ScheduledTime_Daily_Test(); |
| | 576 | $hourlySchedule->setHour(9); |
| | 577 | $hourlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_12_10_00); |
| | 578 | $this->assertEqual($hourlySchedule->getRescheduledTime(), $this->JANUARY_02_1971_09_00_00); |
| | 579 | } |
| | 580 | |
| | 581 | /* |
| | 582 | * Tests getRescheduledTime on Piwik_ScheduledTime_Weekly with unspecified hour and unspecified day |
| | 583 | * |
| | 584 | */ |
| | 585 | public function test_getRescheduledTime_Weekly_Unspecified_Hour_Unspecified_Day() |
| | 586 | { |
| | 587 | |
| | 588 | /* |
| | 589 | * Test 1 |
| | 590 | * |
| | 591 | * Context : |
| | 592 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 593 | * - getRescheduledTime is called within the same second as the cron task |
| | 594 | * - setHour is not called, no need to control the scheduled hour |
| | 595 | * - setDay is not called, no need to control the scheduled day |
| | 596 | * |
| | 597 | * Expected : |
| | 598 | * getRescheduledTime returns January 8 1971 09:00:00 GMT |
| | 599 | */ |
| | 600 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 601 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_00_00); |
| | 602 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_08_1971_09_00_00); |
| | 603 | |
| | 604 | /* |
| | 605 | * Test 2 |
| | 606 | * |
| | 607 | * Context : |
| | 608 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 609 | * - getRescheduledTime is called 10 minutes after the cron task to simulate a previous task |
| | 610 | * - setHour is not called, no need to control the scheduled hour |
| | 611 | * - setDay is not called, no need to control the scheduled day |
| | 612 | * |
| | 613 | * Expected : |
| | 614 | * getRescheduledTime returns January 8 1971 09:10:00 GMT |
| | 615 | * The task would then be executed at January 8 1971 10:00:00 which is ok because setHour has not been called |
| | 616 | */ |
| | 617 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 618 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_10_00); |
| | 619 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_08_1971_09_10_00); |
| | 620 | |
| | 621 | /* |
| | 622 | * Test 3 |
| | 623 | * |
| | 624 | * Context : |
| | 625 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 626 | * - getRescheduledTime is called 1 day and 10 minutes after the cron task to simulate a long previous task |
| | 627 | * - setHour is not called, no need to control the scheduled hour |
| | 628 | * - setDay is not called, no need to control the scheduled day |
| | 629 | * |
| | 630 | * Expected : |
| | 631 | * getRescheduledTime returns January 9 1971 09:10:00 GMT |
| | 632 | * The task would then be executed at January 9 1971 10:00:00 which is ok because setHour and setDay |
| | 633 | * have not been called. |
| | 634 | */ |
| | 635 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 636 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_09_10_00); |
| | 637 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_09_1971_09_10_00); |
| | 638 | |
| | 639 | } |
| | 640 | |
| | 641 | /* |
| | 642 | * Tests getRescheduledTime on Piwik_ScheduledTime_Weekly with specified hour and unspecified day |
| | 643 | * |
| | 644 | */ |
| | 645 | public function test_getRescheduledTime_Weekly_Specified_Hour_Unspecified_Day() |
| | 646 | { |
| | 647 | |
| | 648 | /* |
| | 649 | * Test 1 |
| | 650 | * |
| | 651 | * Context : |
| | 652 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 653 | * - getRescheduledTime is called within the same second as the cron task |
| | 654 | * - setHour is set to 9 |
| | 655 | * - setDay is not called, no need to control the scheduled day |
| | 656 | * |
| | 657 | * Expected : |
| | 658 | * getRescheduledTime returns January 8 1971 09:00:00 GMT |
| | 659 | */ |
| | 660 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 661 | $weeklySchedule->setHour(9); |
| | 662 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_00_00); |
| | 663 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_08_1971_09_00_00); |
| | 664 | |
| | 665 | /* |
| | 666 | * Test 2 |
| | 667 | * |
| | 668 | * Context : |
| | 669 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 670 | * - getRescheduledTime is called 10 minutes after the cron task |
| | 671 | * - setHour is set to 9 |
| | 672 | * - setDay is not called, no need to control the scheduled day |
| | 673 | * |
| | 674 | * Expected : |
| | 675 | * getRescheduledTime returns January 8 1971 09:00:00 GMT |
| | 676 | */ |
| | 677 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 678 | $weeklySchedule->setHour(9); |
| | 679 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_10_00); |
| | 680 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_08_1971_09_00_00); |
| | 681 | |
| | 682 | /* |
| | 683 | * Test 3 |
| | 684 | * |
| | 685 | * Context : |
| | 686 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 687 | * - getRescheduledTime is called 1 day and 10 minutes after the cron task to simulate a long previous task |
| | 688 | * - setHour is set to 9 |
| | 689 | * - setDay is not called, no need to control the scheduled day |
| | 690 | * |
| | 691 | * Expected : |
| | 692 | * getRescheduledTime returns January 9 1971 09:00:00 GMT |
| | 693 | * The task would then be executed at January 9 1971 09:00:00 which is ok because setDay |
| | 694 | * has not been called. |
| | 695 | */ |
| | 696 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 697 | $weeklySchedule->setHour(9); |
| | 698 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_09_10_00); |
| | 699 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_09_1971_09_00_00); |
| | 700 | |
| | 701 | /* |
| | 702 | * Test 4 |
| | 703 | * |
| | 704 | * Context : |
| | 705 | * - Cron fails to run at January 1 1971 09:00:00 GMT, runs at January 1 1971 12:00:00 GMT |
| | 706 | * - getRescheduledTime is called within the same second as the cron task |
| | 707 | * - setHour is set to 9 |
| | 708 | * - setDay is not called, no need to control the scheduled day |
| | 709 | * |
| | 710 | * Expected : |
| | 711 | * getRescheduledTime returns January 8 1971 09:00:00 GMT |
| | 712 | */ |
| | 713 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 714 | $weeklySchedule->setHour(9); |
| | 715 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_12_00_00); |
| | 716 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_08_1971_09_00_00); |
| | 717 | } |
| | 718 | |
| | 719 | /* |
| | 720 | * Tests getRescheduledTime on Piwik_ScheduledTime_Weekly with unspecified hour and specified day |
| | 721 | * |
| | 722 | */ |
| | 723 | public function test_getRescheduledTime_Weekly_Unspecified_Hour_Specified_Day() |
| | 724 | { |
| | 725 | |
| | 726 | /* |
| | 727 | * Test 1 |
| | 728 | * |
| | 729 | * Context : |
| | 730 | * - Cron runs at Monday January 4 1971 09:00:00 GMT |
| | 731 | * - getRescheduledTime is called within the same second as the cron task |
| | 732 | * - setDay is set to 1, Monday |
| | 733 | * - setHour is not called, no need to control the scheduled hour |
| | 734 | * |
| | 735 | * Expected : |
| | 736 | * getRescheduledTime returns Monday January 11 1971 09:00:00 GMT |
| | 737 | */ |
| | 738 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 739 | $weeklySchedule->setDay(1); |
| | 740 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_04_1971_09_00_00); |
| | 741 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_11_1971_09_00_00); |
| | 742 | |
| | 743 | /* |
| | 744 | * Test 2 |
| | 745 | * |
| | 746 | * Context : |
| | 747 | * - Cron runs at Monday January 4 1971 09:00:00 GMT |
| | 748 | * - getRescheduledTime is called 10 minutes after the cron task |
| | 749 | * - setDay is set to 1 |
| | 750 | * - setHour is not called, no need to control the scheduled hour |
| | 751 | * |
| | 752 | * Expected : |
| | 753 | * getRescheduledTime returns Monday January 11 1971 09:10:00 GMT |
| | 754 | * The task will run at January 11 1971 10:00:00 GMT which is ok because setHour has not been called |
| | 755 | */ |
| | 756 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 757 | $weeklySchedule->setDay(1); |
| | 758 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_04_1971_09_10_00); |
| | 759 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_11_1971_09_10_00); |
| | 760 | |
| | 761 | /* |
| | 762 | * Test 3 |
| | 763 | * |
| | 764 | * Context : |
| | 765 | * - Cron fails to run at Monday January 4 1971 09:00:00 GMT, cron restarted at January 5 1971 09:00:00 GMT |
| | 766 | * - getRescheduledTime is called within the same second as the cron task |
| | 767 | * - setDay is set to 1 |
| | 768 | * - setHour is not called, no need to control the scheduled hour |
| | 769 | * |
| | 770 | * Expected : |
| | 771 | * getRescheduledTime returns January 11 1971 09:00:00 GMT |
| | 772 | */ |
| | 773 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 774 | $weeklySchedule->setDay(1); |
| | 775 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_05_1971_09_00_00); |
| | 776 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_11_1971_09_00_00); |
| | 777 | |
| | 778 | } |
| | 779 | |
| | 780 | /* |
| | 781 | * Tests getRescheduledTime on Piwik_ScheduledTime_Weekly with specified hour and specified day |
| | 782 | * |
| | 783 | */ |
| | 784 | public function test_getRescheduledTime_Weekly_Specified_Hour_Specified_Day() |
| | 785 | { |
| | 786 | |
| | 787 | /* |
| | 788 | * Test 1 |
| | 789 | * |
| | 790 | * Context : |
| | 791 | * - Cron runs at Monday January 4 1971 09:00:00 GMT |
| | 792 | * - getRescheduledTime is called within the same second as the cron task |
| | 793 | * - setDay is set to 1, Monday |
| | 794 | * - setHour is set to 9 |
| | 795 | * |
| | 796 | * Expected : |
| | 797 | * getRescheduledTime returns Monday January 11 1971 09:00:00 GMT |
| | 798 | */ |
| | 799 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 800 | $weeklySchedule->setDay(1); |
| | 801 | $weeklySchedule->setHour(9); |
| | 802 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_04_1971_09_00_00); |
| | 803 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_11_1971_09_00_00); |
| | 804 | |
| | 805 | /* |
| | 806 | * Test 2 |
| | 807 | * |
| | 808 | * Context : |
| | 809 | * - Cron runs at Monday January 4 1971 09:00:00 GMT |
| | 810 | * - getRescheduledTime is called 10 minutes after the cron task |
| | 811 | * - setDay is set to 1, Monday |
| | 812 | * - setHour is set to 9 |
| | 813 | * |
| | 814 | * Expected : |
| | 815 | * getRescheduledTime returns Monday January 11 1971 09:00:00 GMT |
| | 816 | */ |
| | 817 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 818 | $weeklySchedule->setDay(1); |
| | 819 | $weeklySchedule->setHour(9); |
| | 820 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_04_1971_09_10_00); |
| | 821 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_11_1971_09_00_00); |
| | 822 | |
| | 823 | /* |
| | 824 | * Test 3 |
| | 825 | * |
| | 826 | * Context : |
| | 827 | * - Cron fails to run at Monday January 4 1971 09:00:00 GMT, cron restarted at January 5 1971 09:00:00 GMT |
| | 828 | * - getRescheduledTime is called within the same second as the cron task |
| | 829 | * - setDay is set to 1, Monday |
| | 830 | * - setHour is set to 9 |
| | 831 | * |
| | 832 | * Expected : |
| | 833 | * getRescheduledTime returns Monday January 11 1971 09:00:00 GMT |
| | 834 | */ |
| | 835 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 836 | $weeklySchedule->setDay(1); |
| | 837 | $weeklySchedule->setHour(9); |
| | 838 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_05_1971_09_00_00); |
| | 839 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_11_1971_09_00_00); |
| | 840 | |
| | 841 | /* |
| | 842 | * Test 4 |
| | 843 | * |
| | 844 | * Context : |
| | 845 | * - Cron fails to run at Monday January 4 1971 09:00:00 GMT, cron restarted at January 5 1971 09:00:00 GMT |
| | 846 | * - getRescheduledTime is called 10 minutes after the cron task |
| | 847 | * - setDay is set to 1, Monday |
| | 848 | * - setHour is set to 9 |
| | 849 | * |
| | 850 | * Expected : |
| | 851 | * getRescheduledTime returns Monday January 11 1971 09:00:00 GMT |
| | 852 | */ |
| | 853 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 854 | $weeklySchedule->setDay(1); |
| | 855 | $weeklySchedule->setHour(9); |
| | 856 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_05_1971_09_10_00); |
| | 857 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_11_1971_09_00_00); |
| | 858 | |
| | 859 | /* |
| | 860 | * Test 5 |
| | 861 | * |
| | 862 | * Context : |
| | 863 | * - Cron fails to run at Monday January 4 1971 09:00:00 GMT, cron restarted at January 5 1971 12:00:00 GMT |
| | 864 | * - getRescheduledTime is called within the same second as the cron task |
| | 865 | * - setDay is set to 1, Monday |
| | 866 | * - setHour is set to 9 |
| | 867 | * |
| | 868 | * Expected : |
| | 869 | * getRescheduledTime returns Monday January 11 1971 09:00:00 GMT |
| | 870 | */ |
| | 871 | $weeklySchedule = new Piwik_ScheduledTime_Weekly_Test(); |
| | 872 | $weeklySchedule->setDay(1); |
| | 873 | $weeklySchedule->setHour(9); |
| | 874 | $weeklySchedule->setReturnValue('getTime', $this->JANUARY_05_1971_12_00_00); |
| | 875 | $this->assertEqual($weeklySchedule->getRescheduledTime(), $this->JANUARY_11_1971_09_00_00); |
| | 876 | } |
| | 877 | |
| | 878 | /* |
| | 879 | * Tests getRescheduledTime on Piwik_ScheduledTime_Monthly with unspecified hour, unspecified day and unspecified week |
| | 880 | * |
| | 881 | */ |
| | 882 | public function test_getRescheduledTime_Monthly_Unspecified_Hour_Unspecified_Day_Unspecified_Week() |
| | 883 | { |
| | 884 | /* |
| | 885 | * Test 1 |
| | 886 | * |
| | 887 | * Context : |
| | 888 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 889 | * - getRescheduledTime is called within the same second as the cron task |
| | 890 | * - setHour is not called, no need to control the scheduled hour |
| | 891 | * - setDay is not called, no need to control the scheduled day |
| | 892 | * - setWeek is not called, no need to control the scheduled week |
| | 893 | * |
| | 894 | * Expected : |
| | 895 | * getRescheduledTime returns February 1 1971 09:00:00 GMT |
| | 896 | */ |
| | 897 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 898 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_00_00); |
| | 899 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_01_1971_09_00_00); |
| | 900 | |
| | 901 | /* |
| | 902 | * Test 2 |
| | 903 | * |
| | 904 | * Context : |
| | 905 | * - Cron runs at January 5 1971 09:00:00 GMT |
| | 906 | * - getRescheduledTime is called within the same second as the cron task |
| | 907 | * - setHour is not called, no need to control the scheduled hour |
| | 908 | * - setDay is not called, no need to control the scheduled day |
| | 909 | * - setWeek is not called, no need to control the scheduled week |
| | 910 | * |
| | 911 | * Expected : |
| | 912 | * getRescheduledTime returns February 5 1971 09:00:00 GMT |
| | 913 | */ |
| | 914 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 915 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_05_1971_09_00_00); |
| | 916 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_05_1971_09_00_00); |
| | 917 | |
| | 918 | /* |
| | 919 | * Test 3 |
| | 920 | * |
| | 921 | * Context : |
| | 922 | * - Cron runs at February 5 1971 09:00:00 GMT |
| | 923 | * - getRescheduledTime is called within the same second as the cron task |
| | 924 | * - setHour is not called, no need to control the scheduled hour |
| | 925 | * - setDay is not called, no need to control the scheduled day |
| | 926 | * - setWeek is not called, no need to control the scheduled week |
| | 927 | * |
| | 928 | * Expected : |
| | 929 | * getRescheduledTime returns March 5 1971 09:00:00 GMT |
| | 930 | */ |
| | 931 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 932 | $monthlySchedule->setReturnValue('getTime', $this->FEBRUARY_05_1971_09_00_00); |
| | 933 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->MARCH_05_1971_09_00_00); |
| | 934 | } |
| | 935 | |
| | 936 | /* |
| | 937 | * Tests getRescheduledTime on Piwik_ScheduledTime_Monthly with unspecified hour, unspecified day and specified week |
| | 938 | * |
| | 939 | */ |
| | 940 | public function test_getRescheduledTime_Monthly_Unspecified_Hour_Unspecified_Day_Specified_Week() |
| | 941 | { |
| | 942 | /* |
| | 943 | * Test 1 |
| | 944 | * |
| | 945 | * Context : |
| | 946 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 947 | * - getRescheduledTime is called within the same second as the cron task |
| | 948 | * - setHour is not called, no need to control the scheduled hour |
| | 949 | * - setDay is not called, no need to control the scheduled day |
| | 950 | * - setWeek is set to 1 |
| | 951 | * |
| | 952 | * Expected : |
| | 953 | * getRescheduledTime returns Monday February 1 1971 09:00:00 GMT |
| | 954 | */ |
| | 955 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 956 | $monthlySchedule->setWeek(1); |
| | 957 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_00_00); |
| | 958 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_01_1971_09_00_00); |
| | 959 | |
| | 960 | /* |
| | 961 | * Test 2 |
| | 962 | * |
| | 963 | * Context : |
| | 964 | * - Cron fails to run at January 1 1971 09:00:00 GMT, cron restarts at January 3 1971 12:00:00 GMT |
| | 965 | * - getRescheduledTime is called 10 minutes after the cron task |
| | 966 | * - setHour is not called, no need to control the scheduled hour |
| | 967 | * - setDay is not called, no need to control the scheduled day |
| | 968 | * - setWeek is set to 1 |
| | 969 | * |
| | 970 | * Expected : |
| | 971 | * getRescheduledTime returns February 3 1971 12:10:00 GMT |
| | 972 | */ |
| | 973 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 974 | $monthlySchedule->setWeek(1); |
| | 975 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_03_1971_12_10_00); |
| | 976 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_03_1971_12_10_00); |
| | 977 | |
| | 978 | /* |
| | 979 | * Test 3 |
| | 980 | * |
| | 981 | * Context : |
| | 982 | * - Cron fails to run at January 1 1971 09:00:00 GMT, cron restarts at January 4 1971 09:00:00 GMT |
| | 983 | * - getRescheduledTime is called within the same second as the cron task |
| | 984 | * - setHour is not called, no need to control the scheduled hour |
| | 985 | * - setDay is not called, no need to control the scheduled day |
| | 986 | * - setWeek is set to 1 |
| | 987 | * |
| | 988 | * Expected : |
| | 989 | * getRescheduledTime returns Monday February 4 1971 09:00:00 GMT |
| | 990 | */ |
| | 991 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 992 | $monthlySchedule->setWeek(1); |
| | 993 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_04_1971_09_00_00); |
| | 994 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_04_1971_09_00_00); |
| | 995 | |
| | 996 | /* |
| | 997 | * Test 4 |
| | 998 | * |
| | 999 | * Context : |
| | 1000 | * - Cron fails to run at January 1 1971 09:00:00 GMT, cron restarts at January 11 1971 09:00:00 GMT |
| | 1001 | * - getRescheduledTime is called within the same second as the cron task |
| | 1002 | * - setHour is not called, no need to control the scheduled hour |
| | 1003 | * - setDay is not called, no need to control the scheduled day |
| | 1004 | * - setWeek is set to 1 |
| | 1005 | * |
| | 1006 | * Expected : |
| | 1007 | * getRescheduledTime returns February 4 1971 09:00:00 GMT |
| | 1008 | */ |
| | 1009 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1010 | $monthlySchedule->setWeek(1); |
| | 1011 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_11_1971_09_00_00); |
| | 1012 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_04_1971_09_00_00); |
| | 1013 | |
| | 1014 | /* |
| | 1015 | * Test 5 |
| | 1016 | * |
| | 1017 | * Context : |
| | 1018 | * - Cron fails to run at January 1 1971 09:00:00 GMT, cron restarts at January 18 1971 09:00:00 GMT |
| | 1019 | * - getRescheduledTime is called within the same second as the cron task |
| | 1020 | * - setHour is not called, no need to control the scheduled hour |
| | 1021 | * - setDay is not called, no need to control the scheduled day |
| | 1022 | * - setWeek is set to 1 |
| | 1023 | * |
| | 1024 | * Expected : |
| | 1025 | * getRescheduledTime returns February 4 1971 09:00:00 GMT |
| | 1026 | */ |
| | 1027 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1028 | $monthlySchedule->setWeek(1); |
| | 1029 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_18_1971_09_00_00); |
| | 1030 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_04_1971_09_00_00); |
| | 1031 | |
| | 1032 | /* |
| | 1033 | * Test 6 |
| | 1034 | * |
| | 1035 | * Context : |
| | 1036 | * - Cron fails to run at January 1 1971 09:00:00 GMT, cron restarts at January 25 1971 09:00:00 GMT |
| | 1037 | * - getRescheduledTime is called within the same second as the cron task |
| | 1038 | * - setHour is not called, no need to control the scheduled hour |
| | 1039 | * - setDay is not called, no need to control the scheduled day |
| | 1040 | * - setWeek is set to 1 |
| | 1041 | * |
| | 1042 | * Expected : |
| | 1043 | * getRescheduledTime returns February 4 1971 09:00:00 GMT |
| | 1044 | */ |
| | 1045 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1046 | $monthlySchedule->setWeek(1); |
| | 1047 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_25_1971_09_00_00); |
| | 1048 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_04_1971_09_00_00); |
| | 1049 | |
| | 1050 | /* |
| | 1051 | * Test 7 |
| | 1052 | * |
| | 1053 | * Context : |
| | 1054 | * - Cron fails to run at January 1 1971 09:00:00 GMT, cron restarts at January 26 1971 09:00:00 GMT |
| | 1055 | * - getRescheduledTime is called within the same second as the cron task |
| | 1056 | * - setHour is not called, no need to control the scheduled hour |
| | 1057 | * - setDay is not called, no need to control the scheduled day |
| | 1058 | * - setWeek is set to 1 |
| | 1059 | * |
| | 1060 | * Expected : |
| | 1061 | * getRescheduledTime returns February 5 1971 09:00:00 GMT |
| | 1062 | */ |
| | 1063 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1064 | $monthlySchedule->setWeek(1); |
| | 1065 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_26_1971_09_00_00); |
| | 1066 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_05_1971_09_00_00); |
| | 1067 | |
| | 1068 | /* |
| | 1069 | * Test 8 |
| | 1070 | * |
| | 1071 | * Context : |
| | 1072 | * - Cron to runs at January 1 1971 09:00:00 GMT |
| | 1073 | * - getRescheduledTime is called within the same second as the cron task |
| | 1074 | * - setHour is not called, no need to control the scheduled hour |
| | 1075 | * - setDay is not called, no need to control the scheduled day |
| | 1076 | * - setWeek is set to 2 |
| | 1077 | * |
| | 1078 | * Expected : |
| | 1079 | * getRescheduledTime returns February 8 1971 09:00:00 GMT |
| | 1080 | */ |
| | 1081 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1082 | $monthlySchedule->setWeek(2); |
| | 1083 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_00_00); |
| | 1084 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_08_1971_09_00_00); |
| | 1085 | } |
| | 1086 | |
| | 1087 | /* |
| | 1088 | * Tests getRescheduledTime on Piwik_ScheduledTime_Monthly with unspecified hour, specified day and unspecified week |
| | 1089 | * |
| | 1090 | */ |
| | 1091 | public function test_getRescheduledTime_Monthly_Unspecified_Hour_Specified_Day_Unspecified_Week() |
| | 1092 | { |
| | 1093 | /* |
| | 1094 | * Test 1 |
| | 1095 | * |
| | 1096 | * Context : |
| | 1097 | * - Cron runs at January 1 1971 09:00:00 GMT |
| | 1098 | * - getRescheduledTime is called within the same second as the cron task |
| | 1099 | * - setHour is not called, no need to control the scheduled hour |
| | 1100 | * - setDay is set to 1 |
| | 1101 | * - setWeek is not called, no need to control the scheduled week |
| | 1102 | * |
| | 1103 | * Expected : |
| | 1104 | * getRescheduledTime returns Monday February 1 1971 09:00:00 GMT |
| | 1105 | */ |
| | 1106 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1107 | $monthlySchedule->setDay(1); |
| | 1108 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_01_1971_09_00_00); |
| | 1109 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_01_1971_09_00_00); |
| | 1110 | |
| | 1111 | /* |
| | 1112 | * Test 2 |
| | 1113 | * |
| | 1114 | * Context : |
| | 1115 | * - Cron runs at Saturday January 2 1971 09:00:00 GMT |
| | 1116 | * - getRescheduledTime is called within the same second as the cron task |
| | 1117 | * - setHour is not called, no need to control the scheduled hour |
| | 1118 | * - setDay is set to 2 |
| | 1119 | * - setWeek is not called, no need to control the scheduled week |
| | 1120 | * |
| | 1121 | * Expected : |
| | 1122 | * getRescheduledTime returns Tuesday February 2 1971 09:00:00 GMT |
| | 1123 | */ |
| | 1124 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1125 | $monthlySchedule->setDay(2); |
| | 1126 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_09_00_00); |
| | 1127 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_02_1971_09_00_00); |
| | 1128 | |
| | 1129 | /* |
| | 1130 | * Test 3 |
| | 1131 | * |
| | 1132 | * Context : |
| | 1133 | * - Cron runs at Saturday January 2 1971 09:00:00 GMT |
| | 1134 | * - getRescheduledTime is called within the same second as the cron task |
| | 1135 | * - setHour is not called, no need to control the scheduled hour |
| | 1136 | * - setDay is set to 3 |
| | 1137 | * - setWeek is not called, no need to control the scheduled week |
| | 1138 | * |
| | 1139 | * Expected : |
| | 1140 | * getRescheduledTime returns Wednesday February 3 1971 09:00:00 GMT |
| | 1141 | */ |
| | 1142 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1143 | $monthlySchedule->setDay(3); |
| | 1144 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_09_00_00); |
| | 1145 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_03_1971_09_00_00); |
| | 1146 | } |
| | 1147 | |
| | 1148 | /* |
| | 1149 | * Tests getRescheduledTime on Piwik_ScheduledTime_Monthly with specified hour, specified day and specified week |
| | 1150 | * |
| | 1151 | */ |
| | 1152 | public function test_getRescheduledTime_Monthly_Specified_Hour_Specified_Day_Specified_Week() |
| | 1153 | { |
| | 1154 | /* |
| | 1155 | * Test 1 |
| | 1156 | * |
| | 1157 | * Context : |
| | 1158 | * - Cron fails to run at January 1 1971 09:00:00 GMT, runs at January 2 1971 12:10:00 GMT |
| | 1159 | * - getRescheduledTime is called within the same second as the cron task |
| | 1160 | * - setHour is set to 9 |
| | 1161 | * - setDay is set to 1 |
| | 1162 | * - setWeek is set to 1 |
| | 1163 | * |
| | 1164 | * Expected : |
| | 1165 | * getRescheduledTime returns Monday February 1 1971 09:00:00 GMT |
| | 1166 | */ |
| | 1167 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1168 | $monthlySchedule->setHour(9); |
| | 1169 | $monthlySchedule->setDay(1); |
| | 1170 | $monthlySchedule->setWeek(1); |
| | 1171 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_12_10_00); |
| | 1172 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_01_1971_09_00_00); |
| | 1173 | |
| | 1174 | /* |
| | 1175 | * Test 2 |
| | 1176 | * |
| | 1177 | * Context : |
| | 1178 | * - Cron fails to run at January 1 1971 09:00:00 GMT, runs at January 2 1971 12:10:00 GMT |
| | 1179 | * - getRescheduledTime is called within the same second as the cron task |
| | 1180 | * - setHour is set to 9 |
| | 1181 | * - setDay is set to 2 |
| | 1182 | * - setWeek is set to 1 |
| | 1183 | * |
| | 1184 | * Expected : |
| | 1185 | * getRescheduledTime returns Tuesday February 2 1971 09:00:00 GMT |
| | 1186 | */ |
| | 1187 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1188 | $monthlySchedule->setHour(9); |
| | 1189 | $monthlySchedule->setDay(2); |
| | 1190 | $monthlySchedule->setWeek(1); |
| | 1191 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_12_10_00); |
| | 1192 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_02_1971_09_00_00); |
| | 1193 | |
| | 1194 | /* |
| | 1195 | * Test 3 |
| | 1196 | * |
| | 1197 | * Context : |
| | 1198 | * - Cron fails to run at January 1 1971 09:00:00 GMT, runs at January 2 1971 12:10:00 GMT |
| | 1199 | * - getRescheduledTime is called within the same second as the cron task |
| | 1200 | * - setHour is set to 9 |
| | 1201 | * - setDay is set to 3 |
| | 1202 | * - setWeek is set to 1 |
| | 1203 | * |
| | 1204 | * Expected : |
| | 1205 | * getRescheduledTime returns Wednesday February 3 1971 09:00:00 GMT |
| | 1206 | */ |
| | 1207 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1208 | $monthlySchedule->setHour(9); |
| | 1209 | $monthlySchedule->setDay(3); |
| | 1210 | $monthlySchedule->setWeek(1); |
| | 1211 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_12_10_00); |
| | 1212 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_03_1971_09_00_00); |
| | 1213 | |
| | 1214 | /* |
| | 1215 | * Test 4 |
| | 1216 | * |
| | 1217 | * Context : |
| | 1218 | * - Cron fails to run at January 1 1971 09:00:00 GMT, runs at January 2 1971 12:10:00 GMT |
| | 1219 | * - getRescheduledTime is called within the same second as the cron task |
| | 1220 | * - setHour is set to 9 |
| | 1221 | * - setDay is set to 1 |
| | 1222 | * - setWeek is set to 3 |
| | 1223 | * |
| | 1224 | * Expected : |
| | 1225 | * getRescheduledTime returns Monday February 15 1971 09:00:00 GMT |
| | 1226 | */ |
| | 1227 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1228 | $monthlySchedule->setHour(9); |
| | 1229 | $monthlySchedule->setDay(1); |
| | 1230 | $monthlySchedule->setWeek(3); |
| | 1231 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_12_10_00); |
| | 1232 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_15_1971_09_00_00); |
| | 1233 | |
| | 1234 | /* |
| | 1235 | * Test 5 |
| | 1236 | * |
| | 1237 | * Context : |
| | 1238 | * - Cron fails to run at January 1 1971 09:00:00 GMT, runs at January 2 1971 12:10:00 GMT |
| | 1239 | * - getRescheduledTime is called within the same second as the cron task |
| | 1240 | * - setHour is set to 9 |
| | 1241 | * - setDay is set to 2 |
| | 1242 | * - setWeek is set to 3 |
| | 1243 | * |
| | 1244 | * Expected : |
| | 1245 | * getRescheduledTime returns Tuesday February 16 1971 09:00:00 GMT |
| | 1246 | */ |
| | 1247 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1248 | $monthlySchedule->setHour(9); |
| | 1249 | $monthlySchedule->setDay(2); |
| | 1250 | $monthlySchedule->setWeek(3); |
| | 1251 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_12_10_00); |
| | 1252 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_16_1971_09_00_00); |
| | 1253 | |
| | 1254 | /* |
| | 1255 | * Test 6 |
| | 1256 | * |
| | 1257 | * Context : |
| | 1258 | * - Cron fails to run at January 1 1971 09:00:00 GMT, runs at January 2 1971 12:10:00 GMT |
| | 1259 | * - getRescheduledTime is called within the same second as the cron task |
| | 1260 | * - setHour is set to 9 |
| | 1261 | * - setDay is set to 3 |
| | 1262 | * - setWeek is set to 3 |
| | 1263 | * |
| | 1264 | * Expected : |
| | 1265 | * getRescheduledTime returns Wednesday February 17 1971 09:00:00 GMT |
| | 1266 | */ |
| | 1267 | $monthlySchedule = new Piwik_ScheduledTime_Monthly_Test(); |
| | 1268 | $monthlySchedule->setHour(9); |
| | 1269 | $monthlySchedule->setDay(3); |
| | 1270 | $monthlySchedule->setWeek(3); |
| | 1271 | $monthlySchedule->setReturnValue('getTime', $this->JANUARY_02_1971_12_10_00); |
| | 1272 | $this->assertEqual($monthlySchedule->getRescheduledTime(), $this->FEBRUARY_17_1971_09_00_00); |
| | 1273 | } |
| | 1274 | } |
| | 1275 | No newline at end of file |