1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
48: class Date_Test extends PHPUnit_Framework_TestCase {
49:
50: 51: 52: 53: 54: 55:
56: private $date1;
57:
58: 59: 60: 61: 62: 63: 64:
65: protected function setUp() {
66:
67: global $config;
68:
69:
70: $config->set('app.default.datetime', 'now');
71:
72: $this->date1 = new Date();
73: }
74:
75: 76: 77: 78: 79: 80: 81:
82: protected function tearDown() {
83: unset($this->date1);
84: }
85:
86: 87: 88: 89: 90:
91: public function testDefaultDateValue() {
92: $this->assertEquals(date("Y-m-d"), $this->date1->getValue(), "testing the constructor has set the Date to today by default");
93: }
94:
95: 96: 97: 98: 99:
100: public function testSetValuePass() {
101: $this->date1->setDateValue(2000, 1, 1);
102:
103: $this->assertEquals("2000-01-01", $this->date1->getValue(), "testing the setValue method");
104: }
105:
106: 107: 108: 109: 110:
111: public function testSetValueInvalidMonth() {
112: try {
113: $this->date1->setDateValue(2000, 'blah', 1);
114: $this->fail("testing the setValue method with a bad month");
115: }catch (AlphaException $e) {
116: $this->assertEquals('Error: the month value blah provided is invalid!'
117: , $e->getMessage()
118: , "testing the setValue method with a bad month");
119: }
120: }
121:
122: 123: 124: 125: 126:
127: public function testSetValueInvalidValue() {
128: try {
129: $this->date1->setDateValue(2000, 13, 1);
130: $this->fail("testing the setValue method with a bad date value (out of range)");
131: }catch (AlphaException $e) {
132: $this->assertEquals('Error: the day value 2000-13-1 provided is invalid!'
133: , $e->getMessage()
134: , "testing the setValue method with a bad date value (out of range)");
135: }
136: }
137:
138: 139: 140: 141: 142:
143: public function testPopulateFromString() {
144: $this->date1->populateFromString("2007-08-13");
145:
146: $this->assertEquals("2007-08-13", $this->date1->getValue(), "testing the populateFromString method");
147:
148: try {
149: $this->date1->populateFromString("2007-08-40");
150: $this->fail("testing the populateFromString method with a bad date value");
151: }catch (AlphaException $e) {
152: $this->assertEquals('Error: the date value 2007-08-40 provided is invalid!'
153: , $e->getMessage()
154: , "testing the populateFromString method with a bad date value");
155: }
156:
157: try {
158: $this->date1->populateFromString("2007-08-aa");
159: $this->fail("testing the populateFromString method with a bad date value");
160: }catch (AlphaException $e) {
161: $this->assertEquals('Error: the day value aa provided is invalid!'
162: , $e->getMessage()
163: , "testing the populateFromString method with a bad date value");
164: }
165:
166: try {
167: $this->date1->populateFromString("bad");
168: $this->fail("testing the populateFromString method with a bad date value");
169: }catch (AlphaException $e) {
170: $this->assertEquals('Invalid Date value [bad] provided!'
171: , $e->getMessage()
172: , "testing the populateFromString method with a bad date value");
173: }
174: }
175:
176: 177: 178: 179: 180:
181: public function testValidationOnConstructor() {
182: try {
183: $date = new Date("blah");
184: $this->fail("testing that the validation will cause an invalid date to fail on the constructor");
185: }catch (AlphaException $e) {
186: $this->assertTrue(true, "testing that the validation will cause an invalid date to fail on the constructor");
187: }
188: }
189:
190: 191: 192: 193: 194:
195: public function testGetEuroValue() {
196: $this->assertEquals(date("d/m/y"), $this->date1->getEuroValue(), "testing the getEuroValue method for converting to European date format");
197: }
198:
199: 200: 201: 202: 203:
204: public function testGetWeekday() {
205: $this->assertEquals(date('l'), $this->date1->getWeekday(), "testing the getWeekday() method when the default constructor is used");
206: }
207:
208: 209: 210: 211: 212:
213: public function testGetUnixValue() {
214: $date = new Date('2012-12-10');
215:
216: $this->assertEquals('1355097600', $date->getUnixValue(), 'testing the getUnixValue() method');
217: }
218:
219: 220: 221: 222: 223:
224: public function testGetUSValue() {
225: $this->assertEquals(date("m/d/y"), $this->date1->getUSValue(), "testing the getUSValue method for converting to US date format");
226: }
227: }
228:
229: ?>