[ZF-8906] Zend_Validate_Identical:
[zend.git] / tests / Zend / Gdata / App / UtilTest.php
blob16dc8affe14ae8b9c7c23ada14e1fc48f54f2aa5
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Gdata_App
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id $
23 require_once 'Zend/Http/Client.php';
24 require_once 'Zend/Gdata/App/Util.php';
25 require_once 'Zend/Gdata/App/Exception.php';
27 /**
28 * @category Zend
29 * @package Zend_Gdata_App
30 * @subpackage UnitTests
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32 * @license http://framework.zend.com/license/new-bsd New BSD License
33 * @group Zend_Gdata
34 * @group Zend_Gdata_App
36 class Zend_Gdata_App_UtilTest extends PHPUnit_Framework_TestCase
39 public function testFormatTimestampFromString()
41 // assert that a correctly formatted timestamp is not modified
42 $date = Zend_Gdata_App_Util::formatTimestamp('2006-12-01');
43 $this->assertEquals('2006-12-01', $date);
46 public function testFormatTimestampFromStringWithTimezone()
48 // assert that a correctly formatted timestamp is not modified
49 $date = Zend_Gdata_App_Util::formatTimestamp('2007-01-10T13:31:12-04:00');
50 $this->assertEquals('2007-01-10T13:31:12-04:00', $date);
53 public function testFormatTimestampWithMilliseconds()
55 // assert that a correctly formatted timestamp is not modified
56 $date = Zend_Gdata_App_Util::formatTimestamp('1956-12-14T43:09:54.52376Z');
57 $this->assertEquals('1956-12-14T43:09:54.52376Z', $date);
60 public function testFormatTimestampUsingZuluAsOffset()
62 // assert that a correctly formatted timestamp is not modified
63 $date = Zend_Gdata_App_Util::formatTimestamp('2024-03-19T01:38:12Z');
64 $this->assertEquals('2024-03-19T01:38:12Z', $date);
67 public function testFormatTimestampUsingLowercaseTAndZ()
69 // assert that a correctly formatted timestamp is not modified
70 $date = Zend_Gdata_App_Util::formatTimestamp('1945-07-19t12:19:08z');
71 $this->assertEquals('1945-07-19t12:19:08z', $date);
74 public function testFormatTimestampFromStringWithNonCompliantDate()
76 // assert that a non-compliant date is converted to RFC 3339
77 $date = Zend_Gdata_App_Util::formatTimestamp('2007/07/13');
78 $this->assertEquals('2007-07-13T00:00:00', $date);
81 public function testFormatTimestampFromInteger()
83 $ts = 1164960000; // Fri Dec 1 00:00:00 PST 2006
84 $date = Zend_Gdata_App_Util::formatTimestamp($ts);
85 $this->assertEquals('2006-12-01T08:00:00+00:00', $date);
88 public function testExceptionFormatTimestampNonsense()
90 $util = new Zend_Gdata_App_Util();
91 try {
92 $ts = Zend_Gdata_App_Util::formatTimestamp('nonsense string');
93 } catch (Zend_Gdata_App_Exception $e) {
94 $this->assertEquals('Invalid timestamp: nonsense string.', $e->getMessage());
95 return;
97 // Excetion not thrown, this is bad.
98 $this->fail("Exception not thrown.");
101 public function testExceptionFormatTimestampSemiInvalid()
103 $util = new Zend_Gdata_App_Util();
104 try {
105 $ts = Zend_Gdata_App_Util::formatTimestamp('2007-06-05adslfkja');
106 } catch (Zend_Gdata_App_Exception $e) {
107 $this->assertEquals('Invalid timestamp: 2007-06-05adslfkja.', $e->getMessage());
108 return;
110 // Excetion not thrown, this is bad.
111 $this->fail("Exception not thrown.");
114 public function testExceptionFormatTimestampInvalidTime()
116 $util = new Zend_Gdata_App_Util();
117 try {
118 $ts = Zend_Gdata_App_Util::formatTimestamp('2007-06-05Tadslfkja');
119 } catch (Zend_Gdata_App_Exception $e) {
120 $this->assertEquals('Invalid timestamp: 2007-06-05Tadslfkja.', $e->getMessage());
121 return;
123 // Excetion not thrown, this is bad.
124 $this->fail("Exception not thrown.");
127 public function testExceptionFormatTimestampInvalidOffset()
129 $util = new Zend_Gdata_App_Util();
130 try {
131 $ts = Zend_Gdata_App_Util::formatTimestamp('2007-06-05T02:51:12+egg');
132 } catch (Zend_Gdata_App_Exception $e) {
133 $this->assertEquals('Invalid timestamp: 2007-06-05T02:51:12+egg.', $e->getMessage());
134 return;
136 // Excetion not thrown, this is bad.
137 $this->fail("Exception not thrown.");
140 public function testExceptionFormatTimestampInvalidOffsetHours()
142 $util = new Zend_Gdata_App_Util();
143 try {
144 $ts = Zend_Gdata_App_Util::formatTimestamp('2007-06-05T02:51:12-ab:00');
145 } catch (Zend_Gdata_App_Exception $e) {
146 $this->assertEquals('Invalid timestamp: 2007-06-05T02:51:12-ab:00.', $e->getMessage());
147 return;
149 // Excetion not thrown, this is bad.
150 $this->fail("Exception not thrown.");
153 public function testFindGreatestBoundedValueReturnsMax() {
154 $data = array(-1 => null,
155 0 => null,
156 1 => null,
157 2 => null,
158 3 => null,
159 5 => null,
160 -2 => null);
161 $result = Zend_Gdata_App_Util::findGreatestBoundedValue(99, $data);
162 $this->assertEquals(5, $result);
165 public function testFindGreatestBoundedValueReturnsMaxWhenBounded() {
166 $data = array(-1 => null,
167 0 => null,
168 1 => null,
169 2 => null,
170 3 => null,
171 5 => null,
172 -2 => null);
173 $result = Zend_Gdata_App_Util::findGreatestBoundedValue(4, $data);
174 $this->assertEquals(3, $result);
177 public function testFindGreatestBoundedValueReturnsMaxWhenUnbounded() {
178 $data = array(-1 => null,
179 0 => null,
180 1 => null,
181 2 => null,
182 3 => null,
183 5 => null,
184 -2 => null);
185 $result = Zend_Gdata_App_Util::findGreatestBoundedValue(null, $data);
186 $this->assertEquals(5, $result);
189 public function testFindGreatestBoundedValueReturnsZeroWhenZeroBounded() {
190 $data = array(-1 => null,
191 0 => null,
192 1 => null,
193 2 => null,
194 3 => null,
195 5 => null,
196 -2 => null);
197 $result = Zend_Gdata_App_Util::findGreatestBoundedValue(0, $data);
198 $this->assertEquals(0, $result);
201 public function testFindGreatestBoundedValueFailsWhenNegativelyBounded() {
202 $data = array(-1 => null,
203 0 => null,
204 1 => null,
205 2 => null,
206 3 => null,
207 5 => null,
208 -2 => null);
209 try {
210 $result = Zend_Gdata_App_Util::findGreatestBoundedValue(-1, $data);
211 $failed = true;
212 } catch (Zend_Gdata_App_Exception $e) {
213 $failed = false;
215 $this->assertFalse($failed, 'Exception not raised.');