EventQueryTest.php 11 KB

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