1
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata_Calendar
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id $
*/
require_once 'Zend/Gdata/Calendar.php';
require_once 'Zend/Gdata/Calendar/EventQuery.php';
require_once 'Zend/Http/Client.php';
/**
* @category Zend
* @package Zend_Gdata_Calendar
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Gdata
* @group Zend_Gdata_Calendar
*/
class Zend_Gdata_Calendar_EventQueryTest extends PHPUnit_Framework_TestCase
{
const GOOGLE_DEVELOPER_CALENDAR = 'developer-calendar@google.com';
const ZEND_CONFERENCE_EVENT = 'bn2h4o4mc3a03ci4t48j3m56pg';
const ZEND_CONFERENCE_EVENT_COMMENT = 'i9q87onko1uphfs7i21elnnb4g';
const SAMPLE_RFC3339 = "2007-06-05T18:38:00";
public function setUp()
{
$this->query = new Zend_Gdata_Calendar_EventQuery();
}
public function testDefaultBaseUrlForQuery()
{
$queryUrl = $this->query->getQueryUrl();
$this->assertEquals('https://www.google.com/calendar/feeds/default/public/full',
$queryUrl);
}
public function testAlternateBaseUrlForQuery()
{
$this->query = new Zend_Gdata_Calendar_EventQuery('http://www.foo.com');
$queryUrl = $this->query->getQueryUrl();
// the URL passed in the constructor has the user, visibility
// projection appended for the return value of $query->getQueryUrl()
$this->assertEquals('http://www.foo.com/default/public/full', $queryUrl);
}
public function testUpdatedMinMaxParam()
{
$updatedMin = '2006-09-20';
$updatedMax = '2006-11-05';
$this->query->resetParameters();
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setUpdatedMin($updatedMin);
$this->query->setUpdatedMax($updatedMax);
$this->assertTrue($this->query->updatedMin != null);
$this->assertTrue($this->query->updatedMax != null);
$this->assertTrue($this->query->user != null);
$this->assertEquals(Zend_Gdata_App_Util::formatTimestamp($updatedMin), $this->query->getUpdatedMin());
$this->assertEquals(Zend_Gdata_App_Util::formatTimestamp($updatedMax), $this->query->getUpdatedMax());
$this->assertEquals(self::GOOGLE_DEVELOPER_CALENDAR, $this->query->getUser());
$this->query->updatedMin = null;
$this->assertFalse($this->query->updatedMin != null);
$this->query->updatedMax = null;
$this->assertFalse($this->query->updatedMax != null);
$this->query->user = null;
$this->assertFalse($this->query->user != null);
}
public function testStartMinMaxParam()
{
$this->query->resetParameters();
$startMin = '2006-10-30';
$startMax = '2006-11-01';
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setStartMin($startMin);
$this->query->setStartMax($startMax);
$this->assertTrue($this->query->startMin != null);
$this->assertTrue($this->query->startMax != null);
$this->assertEquals(Zend_Gdata_App_Util::formatTimestamp($startMin), $this->query->getStartMin());
$this->assertEquals(Zend_Gdata_App_Util::formatTimestamp($startMax), $this->query->getStartMax());
$this->query->startMin = null;
$this->assertFalse($this->query->startMin != null);
$this->query->startMax = null;
$this->assertFalse($this->query->startMax != null);
$this->query->user = null;
$this->assertFalse($this->query->user != null);
}
public function testVisibilityParam()
{
$this->query->resetParameters();
$visibility = 'private';
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setVisibility($visibility);
$this->assertTrue($this->query->visibility != null);
$this->assertEquals($visibility, $this->query->getVisibility());
$this->query->visibility = null;
$this->assertFalse($this->query->visibility != null);
}
public function testProjectionParam()
{
$this->query->resetParameters();
$projection = 'composite';
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setProjection($projection);
$this->assertTrue($this->query->projection != null);
$this->assertEquals($projection, $this->query->getProjection());
$this->query->projection = null;
$this->assertFalse($this->query->projection != null);
}
public function testOrderbyParam()
{
$this->query->resetParameters();
$orderby = 'starttime';
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setOrderby($orderby);
$this->assertTrue($this->query->orderby != null);
$this->assertEquals($orderby, $this->query->getOrderby());
$this->query->orderby = null;
$this->assertFalse($this->query->orderby != null);
}
public function testEventParam()
{
$this->query->resetParameters();
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setEvent(self::ZEND_CONFERENCE_EVENT);
$this->assertTrue($this->query->event != null);
$this->assertEquals(self::ZEND_CONFERENCE_EVENT, $this->query->getEvent());
$this->query->event = null;
$this->assertFalse($this->query->event != null);
}
public function testCommentsParam()
{
$this->query->resetParameters();
$comment = 'we need to reschedule';
$this->query->setComments($comment);
$this->assertTrue($this->query->comments != null);
$this->assertEquals($comment, $this->query->getComments());
$this->query->comments = null;
$this->assertFalse(isset($this->query->comments));
}
public function testSortOrder()
{
$this->query->resetParameters();
$sortOrder = 'ascending';
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setSortOrder($sortOrder);
$this->assertTrue($this->query->sortOrder != null);
$this->assertEquals($sortOrder, $this->query->getSortOrder());
$this->query->sortOrder = null;
$this->assertFalse($this->query->sortOrder != null);
}
public function testRecurrenceExpansionStart()
{
$this->query->resetParameters();
$res = self::SAMPLE_RFC3339;
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setRecurrenceExpansionStart($res);
$this->assertTrue($this->query->recurrenceExpansionStart != null);
$this->assertEquals($res, $this->query->getRecurrenceExpansionStart());
$this->query->recurrenceExpansionStart = null;
$this->assertFalse($this->query->recurrenceExpansionStart != null);
}
public function testRecurrenceExpansionEnd()
{
$this->query->resetParameters();
$ree = self::SAMPLE_RFC3339;
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setRecurrenceExpansionEnd($ree);
$this->assertTrue($this->query->recurrenceExpansionEnd != null);
$this->assertEquals($ree, $this->query->getRecurrenceExpansionEnd());
$this->query->recurrenceExpansionEnd = null;
$this->assertFalse($this->query->recurrenceExpansionEnd != null);
}
public function testSingleEvents()
{
$this->query->resetParameters();
// Test string handling
$singleEvents = 'true';
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setSingleEvents($singleEvents);
$this->assertTrue($this->query->singleEvents === true);
// Test bool handling
$singleEvents = false;
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setSingleEvents($singleEvents);
$this->assertTrue($this->query->singleEvents === false);
// Test unsetting
$this->assertEquals($singleEvents, $this->query->getSingleEvents());
$this->query->setSingleEvents(null);
$this->assertFalse($this->query->singleEvents != null);
}
public function testFutureEvents()
{
$this->query->resetParameters();
// Test string handling
$singleEvents = 'true';
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setFutureEvents($singleEvents);
$this->assertTrue($this->query->futureEvents === true);
// Test bool handling
$singleEvents = false;
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setFutureEvents($singleEvents);
$this->assertTrue($this->query->futureEvents === false);
// Test unsetting
$this->query->futureEvents = null;
$this->assertFalse($this->query->futureEvents != null);
}
public function testCustomQueryURIGeneration()
{
$this->query->resetParameters();
$this->query->setUser(self::GOOGLE_DEVELOPER_CALENDAR);
$this->query->setVisibility("private");
$this->query->setProjection("composite");
$this->query->setEvent(self::ZEND_CONFERENCE_EVENT);
$this->query->setComments(self::ZEND_CONFERENCE_EVENT_COMMENT);
$this->assertEquals("https://www.google.com/calendar/feeds/developer-calendar@google.com/private/composite/" .
self::ZEND_CONFERENCE_EVENT . "/comments/" . self::ZEND_CONFERENCE_EVENT_COMMENT,
$this->query->getQueryUrl());
}
public function testDefaultQueryURIGeneration()
{
$this->query->resetParameters();
$this->assertEquals("https://www.google.com/calendar/feeds/default/public/full",
$this->query->getQueryUrl());
}
public function testCanNullifyParameters()
{
$testURI = "http://www.google.com/calendar/feeds/foo%40group.calendar.google.com/private/full";
$this->query = new Zend_Gdata_Calendar_EventQuery($testURI);
$this->query->setUser(null);
$this->query->setVisibility(null);
$this->query->setProjection(null);
$result = $this->query->getQueryUrl();
$this->assertEquals($testURI, $result);
}
}
|