Adding tests for securing private variable inclussion on templates.
[akelos.git] / test / unit / lib / AkLocalize / AkTimeZone.php
blobef7c7149b99d9ab454130f2e974ed82c53ec3faf
1 <?php
3 include_once(AK_LIB_DIR.DS.'AkLocalize'.DS.'AkTimeZone.php');
5 class AkTestTime { function now(){} }
6 ak_generate_mock('AkTestTime');
9 class TimeZoneTestCase extends AkUnitTest
11 function setup()
13 $this->MockTime = new MockAkTestTime($this);
14 $this->MockTime->setReturnValue('now','Sun Jul 25 14:49:00 UTC 2004');
15 $this->timestamp = gmmktime(14,49,00,7,25,2004);
18 function test_should_return_positive_formatted_offset()
20 $zone = $this->_createTimeZone("Test", 4200);
21 $this->assertEqual("+01:10", $zone->getFormattedOffset());
24 function test_should_return_negative_formatted_offset()
26 $zone = $this->_createTimeZone("Test", -4200);
27 $this->assertEqual("-01:10", $zone->getFormattedOffset());
30 function test_now()
32 $Zone = $this->_createTimeZone("Test", 4200);
33 $Zone->_timestamp = $this->timestamp;
34 $this->assertEqual(gmmktime(15, 59,00,7,25,2004), $Zone->now());
37 function test_now_with_dst_on_winter()
39 $Zone = $this->_createTimeZone("Australia/Sydney");
40 $Zone->_timestamp = $this->timestamp;
41 $this->assertEqual($Zone->dateTime(), '2004-07-26 00:49:00');
44 function test_now_with_dst_on_summer()
46 $Zone = $this->_createTimeZone("Europe/Madrid");
47 $Zone->_timestamp = $this->timestamp;
48 $this->assertEqual($Zone->time(), '16:49');
51 function test_now_with_dst_on_summer_on_Canada_Saskatchewan()
53 $Zone = $this->_createTimeZone("Canada/Saskatchewan");
54 $Zone->_timestamp = $this->timestamp;
55 $this->assertEqual($Zone->dateTime(), '2004-07-25 08:49:00');
58 function test_now_with_dst_on_summer_on_America_Chicago()
60 $Zone = $this->_createTimeZone("America/Chicago");
61 $Zone->_timestamp = $this->timestamp;
62 $this->assertEqual($Zone->dateTime(), '2004-07-25 09:49:00');
65 function test_today()
67 $Zone = $this->_createTimeZone("Test", 43200);
68 $Zone->_timestamp = $this->timestamp;
69 $this->assertEqual(Ak::getDate(mktime(0,0,0,7,26,2004), Ak::locale('date_format')), $Zone->today());
72 function test_should_adjust_negative()
74 $Zone = $this->_createTimeZone("Test", -4200);
75 $Zone->_timestamp = $this->timestamp;
76 $this->assertEqual(mktime(23,55,0,7,24,2004), $Zone->adjust(mktime(1,5,0,7,25,2004)));
79 function test_should_adjust_positive()
81 $Zone = $this->_createTimeZone("Test", 4200);
82 $Zone->_timestamp = $this->timestamp;
83 $this->assertEqual(mktime(1,5,0,7,26,2004), $Zone->adjust(mktime(23,55,0,7,25,2004)));
86 function test_should_unadjust()
88 $Zone = $this->_createTimeZone("Test", 4200);
89 $Zone->_timestamp = $this->timestamp;
90 $this->assertEqual(mktime(23,55,0,7,24,2004), $Zone->unadjust(mktime(1,5,0,7,25,2004)));
94 function test_should_unadjust_with_dst_on_summer()
96 $Zone = $this->_createTimeZone("Europe/Madrid");
97 $Zone->_timestamp = $this->timestamp;
98 $this->assertEqual(mktime(14,49,00,7,25,2004), $Zone->unadjust(mktime(16,49,00,7,25,2004)));
102 function test_should_unadjust_with_dst_on_winter()
104 $Zone = $this->_createTimeZone("Australia/Sydney");
105 $Zone->_timestamp = $this->timestamp;
106 $this->assertEqual(mktime(14,49,00,7,25,2004), $Zone->unadjust(mktime(00,49,00,7,26,2004)));
109 function test_should_compare_timezones()
111 $Zone1 = $this->_createTimeZone("Test", 4200);
112 $Zone2 = $this->_createTimeZone("Test", 5600);
113 $Zone1->_timestamp = $Zone2->_timestamp = $this->timestamp;
114 $this->assertTrue($Zone1->now() < $Zone2->now());
116 $Zone1 = $this->_createTimeZone("Able", 10000);
117 $Zone2 = $this->_createTimeZone("Zone", 10000);
118 $Zone1->_timestamp = $Zone2->_timestamp = $this->timestamp;
119 $this->assertTrue($Zone1->compare($Zone2) == -1);
121 $this->assertTrue($Zone1->compare($Zone1) == 0);
124 function test_should_compare_zones_at_the_same_offset_one_of_them_using_dst()
126 $Zone1 = $this->_createTimeZone("Africa/Ceuta"); // has dst
127 $Zone2 = $this->_createTimeZone("Africa/Malabo");
128 $Zone1->_timestamp = $Zone2->_timestamp = $this->timestamp;
129 $this->assertTrue($Zone1->now() > $Zone2->now());
130 $this->assertTrue($Zone1->compare($Zone2) == -1);
133 function test_to_string()
135 $Zone = $this->_createTimeZone("Test", 4200);
136 $Zone->_timestamp = $this->timestamp;
137 $this->assertEqual("(GMT+01:10) Test", $Zone->toString());
140 function test_should_be_sorted()
142 $Zones =& AkTimeZone::all();
143 foreach (range(1,count($Zones)-1) as $i){
144 $this->assertTrue($Zones[$i-1]->compare($Zones[$i]) == -1);
148 function _createTimeZone()
150 $args = func_get_args();
151 $TimeZone = new AkTimeZone();
152 return call_user_func_array(array($TimeZone,'create'), $args);