EventQueryTest.php 10 KB

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