2 // $Id: peardate_engine_test.php 4940 2012-06-06 02:20:28Z fishbone $
4 require_once('simple_include.php');
5 require_once('calendar_include.php');
7 class TestOfPearDateEngine extends UnitTestCase {
9 function TestOfPearDateEngine() {
10 $this->UnitTestCase('Test of Calendar_Engine_PearDate');
13 $this->engine = new Calendar_Engine_PearDate();
15 function testGetSecondsInMinute() {
16 $this->assertEqual($this->engine->getSecondsInMinute(),60);
18 function testGetMinutesInHour() {
19 $this->assertEqual($this->engine->getMinutesInHour(),60);
21 function testGetHoursInDay() {
22 $this->assertEqual($this->engine->getHoursInDay(),24);
24 function testGetFirstDayOfWeek() {
25 $this->assertEqual($this->engine->getFirstDayOfWeek(),1);
27 function testGetWeekDays() {
28 $this->assertEqual($this->engine->getWeekDays(),array(0,1,2,3,4,5,6));
30 function testGetDaysInWeek() {
31 $this->assertEqual($this->engine->getDaysInWeek(),7);
33 function testGetWeekNInYear() {
34 $this->assertEqual($this->engine->getWeekNInYear(2003, 11, 3), 45);
36 function testGetWeekNInMonth() {
37 $this->assertEqual($this->engine->getWeekNInMonth(2003, 11, 3), 2);
39 function testGetWeeksInMonth0() {
40 $this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 0), 6); //week starts on sunday
42 function testGetWeeksInMonth1() {
43 $this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 1), 5); //week starts on monday
45 function testGetWeeksInMonth2() {
46 $this->assertEqual($this->engine->getWeeksInMonth(2003, 2, 6), 4); //week starts on saturday
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);
53 function testGetDayOfWeek() {
54 $this->assertEqual($this->engine->getDayOfWeek(2003, 11, 18), 2);
56 function testGetFirstDayInMonth() {
57 $this->assertEqual($this->engine->getFirstDayInMonth(2003,10),3);
59 function testGetDaysInMonth() {
60 $this->assertEqual($this->engine->getDaysInMonth(2003,10),31);
62 function testGetMinYears() {
63 $this->assertEqual($this->engine->getMinYears(),0);
65 function testGetMaxYears() {
66 $this->assertEqual($this->engine->getMaxYears(),9999);
68 function testDateToStamp() {
69 $stamp = '2003-10-15 13:30:45';
70 $this->assertEqual($this->engine->dateToStamp(2003,10,15,13,30,45),$stamp);
72 function testStampToSecond() {
73 $stamp = '2003-10-15 13:30:45';
74 $this->assertEqual($this->engine->stampToSecond($stamp),45);
76 function testStampToMinute() {
77 $stamp = '2003-10-15 13:30:45';
78 $this->assertEqual($this->engine->stampToMinute($stamp),30);
80 function testStampToHour() {
81 $stamp = '2003-10-15 13:30:45';
82 $this->assertEqual($this->engine->stampToHour($stamp),13);
84 function testStampToDay() {
85 $stamp = '2003-10-15 13:30:45';
86 $this->assertEqual($this->engine->stampToDay($stamp),15);
88 function testStampToMonth() {
89 $stamp = '2003-10-15 13:30:45';
90 $this->assertEqual($this->engine->stampToMonth($stamp),10);
92 function testStampToYear() {
93 $stamp = '2003-10-15 13:30:45';
94 $this->assertEqual($this->engine->stampToYear($stamp),2003);
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);
102 //the first day of the month should be thursday
103 $this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 4);
105 $m--; // 2004-00-01 => 2003-12-01
106 $this->engine->adjustDate($y, $m, $d, $dummy, $dummy, $dummy);
108 $this->assertEqual($y, 2003);
109 $this->assertEqual($m, 12);
110 $this->assertEqual($d, 1);
112 // get last day and check if it's wednesday
113 $d = $this->engine->getDaysInMonth($y, $m);
115 $this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 3);
117 function testIsToday() {
118 $stamp = date('Y-m-d H:i:s');
119 $this->assertTrue($this->engine->isToday($stamp));
120 $stamp = date('Y-m-d H:i:s', time() + 1000000000);
121 $this->assertFalse($this->engine->isToday($stamp));
125 if (!defined('TEST_RUNNING')) {
126 define('TEST_RUNNING', true);
127 $test = &new TestOfPearDateEngine();
128 $test->run(new HtmlReporter());