493 |
ddelon |
1 |
<?php
|
|
|
2 |
// $Id: peardate_engine_test.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
|
|
|
3 |
|
|
|
4 |
require_once('simple_include.php');
|
|
|
5 |
require_once('calendar_include.php');
|
|
|
6 |
|
|
|
7 |
class TestOfPearDateEngine extends UnitTestCase {
|
|
|
8 |
var $engine;
|
|
|
9 |
function TestOfPearDateEngine() {
|
|
|
10 |
$this->UnitTestCase('Test of Calendar_Engine_PearDate');
|
|
|
11 |
}
|
|
|
12 |
function setUp() {
|
|
|
13 |
$this->engine = new Calendar_Engine_PearDate();
|
|
|
14 |
}
|
|
|
15 |
function testGetSecondsInMinute() {
|
|
|
16 |
$this->assertEqual($this->engine->getSecondsInMinute(),60);
|
|
|
17 |
}
|
|
|
18 |
function testGetMinutesInHour() {
|
|
|
19 |
$this->assertEqual($this->engine->getMinutesInHour(),60);
|
|
|
20 |
}
|
|
|
21 |
function testGetHoursInDay() {
|
|
|
22 |
$this->assertEqual($this->engine->getHoursInDay(),24);
|
|
|
23 |
}
|
|
|
24 |
function testGetFirstDayOfWeek() {
|
|
|
25 |
$this->assertEqual($this->engine->getFirstDayOfWeek(),1);
|
|
|
26 |
}
|
|
|
27 |
function testGetWeekDays() {
|
|
|
28 |
$this->assertEqual($this->engine->getWeekDays(),array(0,1,2,3,4,5,6));
|
|
|
29 |
}
|
|
|
30 |
function testGetDaysInWeek() {
|
|
|
31 |
$this->assertEqual($this->engine->getDaysInWeek(),7);
|
|
|
32 |
}
|
|
|
33 |
function testGetWeekNInYear() {
|
|
|
34 |
$this->assertEqual($this->engine->getWeekNInYear(2003, 11, 3), 45);
|
|
|
35 |
}
|
|
|
36 |
function testGetWeekNInMonth() {
|
|
|
37 |
$this->assertEqual($this->engine->getWeekNInMonth(2003, 11, 3), 2);
|
|
|
38 |
}
|
|
|
39 |
function testGetWeeksInMonth0() {
|
|
|
40 |
$this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 0), 6); //week starts on sunday
|
|
|
41 |
}
|
|
|
42 |
function testGetWeeksInMonth1() {
|
|
|
43 |
$this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 1), 5); //week starts on monday
|
|
|
44 |
}
|
|
|
45 |
function testGetWeeksInMonth2() {
|
|
|
46 |
$this->assertEqual($this->engine->getWeeksInMonth(2003, 2, 6), 4); //week starts on saturday
|
|
|
47 |
}
|
|
|
48 |
function testGetWeeksInMonth3() {
|
|
|
49 |
// Unusual cases that can cause fails (shows up with example 21.php)
|
|
|
50 |
$this->assertEqual($this->engine->getWeeksInMonth(2004,2,1),5);
|
|
|
51 |
$this->assertEqual($this->engine->getWeeksInMonth(2004,8,1),6);
|
|
|
52 |
}
|
|
|
53 |
function testGetDayOfWeek() {
|
|
|
54 |
$this->assertEqual($this->engine->getDayOfWeek(2003, 11, 18), 2);
|
|
|
55 |
}
|
|
|
56 |
function testGetFirstDayInMonth() {
|
|
|
57 |
$this->assertEqual($this->engine->getFirstDayInMonth(2003,10),3);
|
|
|
58 |
}
|
|
|
59 |
function testGetDaysInMonth() {
|
|
|
60 |
$this->assertEqual($this->engine->getDaysInMonth(2003,10),31);
|
|
|
61 |
}
|
|
|
62 |
function testGetMinYears() {
|
|
|
63 |
$this->assertEqual($this->engine->getMinYears(),0);
|
|
|
64 |
}
|
|
|
65 |
function testGetMaxYears() {
|
|
|
66 |
$this->assertEqual($this->engine->getMaxYears(),9999);
|
|
|
67 |
}
|
|
|
68 |
function testDateToStamp() {
|
|
|
69 |
$stamp = '2003-10-15 13:30:45';
|
|
|
70 |
$this->assertEqual($this->engine->dateToStamp(2003,10,15,13,30,45),$stamp);
|
|
|
71 |
}
|
|
|
72 |
function testStampToSecond() {
|
|
|
73 |
$stamp = '2003-10-15 13:30:45';
|
|
|
74 |
$this->assertEqual($this->engine->stampToSecond($stamp),45);
|
|
|
75 |
}
|
|
|
76 |
function testStampToMinute() {
|
|
|
77 |
$stamp = '2003-10-15 13:30:45';
|
|
|
78 |
$this->assertEqual($this->engine->stampToMinute($stamp),30);
|
|
|
79 |
}
|
|
|
80 |
function testStampToHour() {
|
|
|
81 |
$stamp = '2003-10-15 13:30:45';
|
|
|
82 |
$this->assertEqual($this->engine->stampToHour($stamp),13);
|
|
|
83 |
}
|
|
|
84 |
function testStampToDay() {
|
|
|
85 |
$stamp = '2003-10-15 13:30:45';
|
|
|
86 |
$this->assertEqual($this->engine->stampToDay($stamp),15);
|
|
|
87 |
}
|
|
|
88 |
function testStampToMonth() {
|
|
|
89 |
$stamp = '2003-10-15 13:30:45';
|
|
|
90 |
$this->assertEqual($this->engine->stampToMonth($stamp),10);
|
|
|
91 |
}
|
|
|
92 |
function testStampToYear() {
|
|
|
93 |
$stamp = '2003-10-15 13:30:45';
|
|
|
94 |
$this->assertEqual($this->engine->stampToYear($stamp),2003);
|
|
|
95 |
}
|
|
|
96 |
function testAdjustDate() {
|
|
|
97 |
$stamp = '2004-01-01 13:30:45';
|
|
|
98 |
$y = $this->engine->stampToYear($stamp);
|
|
|
99 |
$m = $this->engine->stampToMonth($stamp);
|
|
|
100 |
$d = $this->engine->stampToDay($stamp);
|
|
|
101 |
|
|
|
102 |
//the first day of the month should be thursday
|
|
|
103 |
$this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 4);
|
|
|
104 |
|
|
|
105 |
$m--; // 2004-00-01 => 2003-12-01
|
|
|
106 |
$this->engine->adjustDate($y, $m, $d, $dummy, $dummy, $dummy);
|
|
|
107 |
|
|
|
108 |
$this->assertEqual($y, 2003);
|
|
|
109 |
$this->assertEqual($m, 12);
|
|
|
110 |
$this->assertEqual($d, 1);
|
|
|
111 |
|
|
|
112 |
// get last day and check if it's wednesday
|
|
|
113 |
$d = $this->engine->getDaysInMonth($y, $m);
|
|
|
114 |
|
|
|
115 |
$this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 3);
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
if (!defined('TEST_RUNNING')) {
|
|
|
120 |
define('TEST_RUNNING', true);
|
|
|
121 |
$test = &new TestOfPearDateEngine();
|
|
|
122 |
$test->run(new HtmlReporter());
|
|
|
123 |
}
|
|
|
124 |
?>
|