VideoQueryTest.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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_YouTube
  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/YouTube/VideoQuery.php';
  23. require_once 'Zend/Gdata/YouTube.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_YouTube
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Gdata
  31. * @group Zend_Gdata_YouTube
  32. */
  33. class Zend_Gdata_YouTube_VideoQueryTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function testQueryStringConstruction()
  36. {
  37. $yt = new Zend_Gdata_YouTube();
  38. $query = $yt->newVideoQuery();
  39. $query->setOrderBy('viewCount');
  40. $query->setVideoQuery('foobar');
  41. $expectedString = '?orderby=viewCount&vq=foobar';
  42. $this->assertEquals($expectedString, $query->getQueryString());
  43. }
  44. public function testQueryStringConstructionV2()
  45. {
  46. $yt = new Zend_Gdata_YouTube();
  47. $query = $yt->newVideoQuery();
  48. $query->setOrderBy('viewCount');
  49. $query->setVideoQuery('version2');
  50. $expectedString = '?orderby=viewCount&q=version2';
  51. $this->assertEquals($expectedString, $query->getQueryString(2));
  52. }
  53. public function testSafeSearchQueryV2()
  54. {
  55. $yt = new Zend_Gdata_YouTube();
  56. $query = $yt->newVideoQuery();
  57. $exceptionCaught = false;
  58. $query->setRacy('include');
  59. try {
  60. $query->getQueryString(2);
  61. } catch (Zend_Gdata_App_VersionException $e) {
  62. $exceptionCaught = true;
  63. }
  64. $this->assertTrue($exceptionCaught, 'Zend_Gdata_App_VersionException' .
  65. ' expected but not found');
  66. }
  67. public function testLocationRadiusV1()
  68. {
  69. $yt = new Zend_Gdata_YouTube();
  70. $query = $yt->newVideoQuery();
  71. $exceptionCaught = false;
  72. $query->setLocationRadius('1km');
  73. try {
  74. $query->getQueryString(1);
  75. } catch (Zend_Gdata_App_VersionException $e) {
  76. $exceptionCaught = true;
  77. }
  78. $this->assertTrue($exceptionCaught, 'Zend_Gdata_App_VersionException' .
  79. ' expected but not found');
  80. }
  81. public function testLocationV2()
  82. {
  83. $yt = new Zend_Gdata_YouTube();
  84. $query = $yt->newVideoQuery();
  85. $query->setLocation('-37.122,122.01');
  86. $expectedString = '?location=-37.122%2C122.01';
  87. $this->assertEquals($expectedString, $query->getQueryString(2));
  88. }
  89. public function testLocationExceptionOnNonNumericV2()
  90. {
  91. $yt = new Zend_Gdata_YouTube();
  92. $query = $yt->newVideoQuery();
  93. $exceptionCaught = false;
  94. try {
  95. $query->setLocation('mars');
  96. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  97. $exceptionCaught = true;
  98. }
  99. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  100. 'IllegalArgumentException when using alpha in setLocation');
  101. }
  102. public function testLocationExceptionOnOnlyOneCoordinateV2()
  103. {
  104. $yt = new Zend_Gdata_YouTube();
  105. $query = $yt->newVideoQuery();
  106. $exceptionCaught = false;
  107. try {
  108. $query->setLocation('-25.001');
  109. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  110. $exceptionCaught = true;
  111. }
  112. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  113. 'IllegalArgumentException when using only 1 coordinate ' .
  114. 'in setLocation');
  115. }
  116. public function testUploaderExceptionOnInvalidV2()
  117. {
  118. $yt = new Zend_Gdata_YouTube();
  119. $query = $yt->newVideoQuery();
  120. $exceptionCaught = false;
  121. try {
  122. $query->setUploader('invalid');
  123. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  124. $exceptionCaught = true;
  125. }
  126. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  127. 'IllegalArgumentException when using invalid string in ' .
  128. 'setUploader.');
  129. }
  130. public function testProjectionPresentInV2Query()
  131. {
  132. $yt = new Zend_Gdata_YouTube();
  133. $query = $yt->newVideoQuery();
  134. $query->setVideoQuery('foo');
  135. $expectedString = 'https://gdata.youtube.com/feeds/api/videos?q=foo';
  136. $this->assertEquals($expectedString, $query->getQueryUrl(2));
  137. }
  138. public function testSafeSearchParametersInV2()
  139. {
  140. $yt = new Zend_Gdata_YouTube();
  141. $query = $yt->newVideoQuery();
  142. $exceptionCaught = false;
  143. try {
  144. $query->setSafeSearch('invalid');
  145. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  146. $exceptionCaught = true;
  147. }
  148. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  149. 'InvalidArgumentException when using invalid value for ' .
  150. 'safeSearch.');
  151. }
  152. /**
  153. * @group ZF-8720
  154. * @expectedException Zend_Gdata_App_InvalidArgumentException
  155. */
  156. public function testVideoQuerySetLocationException()
  157. {
  158. $yt = new Zend_Gdata_YouTube();
  159. $query = $yt->newVideoQuery();
  160. $location = 'foobar';
  161. $this->assertNull($query->setLocation($location));
  162. }
  163. /**
  164. * @group ZF-8720
  165. * @expectedException Zend_Gdata_App_InvalidArgumentException
  166. */
  167. public function testVideoQuerySetLocationExceptionV2()
  168. {
  169. $yt = new Zend_Gdata_YouTube();
  170. $query = $yt->newVideoQuery();
  171. $location = '-100x,-200y';
  172. $this->assertNull($query->setLocation($location));
  173. }
  174. /**
  175. * @group ZF-8720
  176. * @expectedException Zend_Gdata_App_InvalidArgumentException
  177. */
  178. public function testVideoQuerySetLocationExceptionV3()
  179. {
  180. $yt = new Zend_Gdata_YouTube();
  181. $query = $yt->newVideoQuery();
  182. $location = '-100x,-200y!';
  183. $this->assertNull($query->setLocation($location));
  184. }
  185. /**
  186. * @group ZF-8720
  187. */
  188. public function testQueryExclamationMarkRemoveBug()
  189. {
  190. $yt = new Zend_Gdata_YouTube();
  191. $query = $yt->newVideoQuery();
  192. $location = '37.42307,-122.08427';
  193. $this->assertNull($query->setLocation($location));
  194. $this->assertEquals($location, $query->getLocation());
  195. $location = '37.42307,-122.08427!';
  196. $this->assertNull($query->setLocation($location));
  197. $this->assertEquals($location, $query->getLocation());
  198. }
  199. /**
  200. * @group ZF-12500
  201. */
  202. public function testQueryUrlForFeedTypRelated()
  203. {
  204. $yt = new Zend_Gdata_YouTube();
  205. // Query
  206. $query = $yt->newVideoQuery();
  207. $query->setFeedType('related', 'foo');
  208. // Test
  209. $this->assertSame(
  210. 'https://gdata.youtube.com/feeds/api/videos/foo/related',
  211. $query->getQueryUrl()
  212. );
  213. }
  214. /**
  215. * @group ZF-12500
  216. */
  217. public function testQueryUrlForFeedTypResponses()
  218. {
  219. $yt = new Zend_Gdata_YouTube();
  220. // Query
  221. $query = $yt->newVideoQuery();
  222. $query->setFeedType('responses', 'foo');
  223. // Test
  224. $this->assertSame(
  225. 'https://gdata.youtube.com/feeds/api/videos/foo/responses',
  226. $query->getQueryUrl()
  227. );
  228. }
  229. /**
  230. * @group ZF-12500
  231. */
  232. public function testQueryUrlForFeedTypComments()
  233. {
  234. $yt = new Zend_Gdata_YouTube();
  235. // Query
  236. $query = $yt->newVideoQuery();
  237. $query->setFeedType('comments', 'foo');
  238. // Test
  239. $this->assertSame(
  240. 'https://gdata.youtube.com/feeds/api/videos/foo/comments',
  241. $query->getQueryUrl()
  242. );
  243. }
  244. }