VideoQueryTest.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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-2010 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. /**
  23. * Test helper
  24. */
  25. require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  26. require_once 'Zend/Gdata/YouTube/VideoQuery.php';
  27. require_once 'Zend/Gdata/YouTube.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Gdata_YouTube
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_Gdata
  35. * @group Zend_Gdata_YouTube
  36. */
  37. class Zend_Gdata_YouTube_VideoQueryTest extends PHPUnit_Framework_TestCase
  38. {
  39. public function testQueryStringConstruction () {
  40. $yt = new Zend_Gdata_YouTube();
  41. $query = $yt->newVideoQuery();
  42. $query->setOrderBy('viewCount');
  43. $query->setVideoQuery('foobar');
  44. $expectedString = '?orderby=viewCount&vq=foobar';
  45. $this->assertEquals($expectedString, $query->getQueryString());
  46. }
  47. public function testQueryStringConstructionV2() {
  48. $yt = new Zend_Gdata_YouTube();
  49. $query = $yt->newVideoQuery();
  50. $query->setOrderBy('viewCount');
  51. $query->setVideoQuery('version2');
  52. $expectedString = '?orderby=viewCount&q=version2';
  53. $this->assertEquals($expectedString, $query->getQueryString(2));
  54. }
  55. public function testSafeSearchQueryV2() {
  56. $yt = new Zend_Gdata_YouTube();
  57. $query = $yt->newVideoQuery();
  58. $exceptionCaught = false;
  59. $query->setRacy('include');
  60. try {
  61. $query->getQueryString(2);
  62. } catch (Zend_Gdata_App_VersionException $e) {
  63. $exceptionCaught = true;
  64. }
  65. $this->assertTrue($exceptionCaught, 'Zend_Gdata_App_VersionException' .
  66. ' expected but not found');
  67. }
  68. public function testLocationRadiusV1() {
  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. $yt = new Zend_Gdata_YouTube();
  83. $query = $yt->newVideoQuery();
  84. $query->setLocation('-37.122,122.01');
  85. $expectedString = '?location=-37.122%2C122.01';
  86. $this->assertEquals($expectedString, $query->getQueryString(2));
  87. }
  88. public function testLocationExceptionOnNonNumericV2() {
  89. $yt = new Zend_Gdata_YouTube();
  90. $query = $yt->newVideoQuery();
  91. $exceptionCaught = false;
  92. try {
  93. $query->setLocation('mars');
  94. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  95. $exceptionCaught = true;
  96. }
  97. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  98. 'IllegalArgumentException when using alpha in setLocation');
  99. }
  100. public function testLocationExceptionOnOnlyOneCoordinateV2() {
  101. $yt = new Zend_Gdata_YouTube();
  102. $query = $yt->newVideoQuery();
  103. $exceptionCaught = false;
  104. try {
  105. $query->setLocation('-25.001');
  106. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  107. $exceptionCaught = true;
  108. }
  109. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  110. 'IllegalArgumentException when using only 1 coordinate ' .
  111. 'in setLocation');
  112. }
  113. public function testUploaderExceptionOnInvalidV2() {
  114. $yt = new Zend_Gdata_YouTube();
  115. $query = $yt->newVideoQuery();
  116. $exceptionCaught = false;
  117. try {
  118. $query->setUploader('invalid');
  119. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  120. $exceptionCaught = true;
  121. }
  122. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  123. 'IllegalArgumentException when using invalid string in ' .
  124. 'setUploader.');
  125. }
  126. public function testProjectionPresentInV2Query() {
  127. $yt = new Zend_Gdata_YouTube();
  128. $query = $yt->newVideoQuery();
  129. $query->setVideoQuery('foo');
  130. $expectedString = 'http://gdata.youtube.com/feeds/api/videos?q=foo';
  131. $this->assertEquals($expectedString, $query->getQueryUrl(2));
  132. }
  133. public function testSafeSearchParametersInV2() {
  134. $yt = new Zend_Gdata_YouTube();
  135. $query = $yt->newVideoQuery();
  136. $exceptionCaught = false;
  137. try {
  138. $query->setSafeSearch('invalid');
  139. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  140. $exceptionCaught = true;
  141. }
  142. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  143. 'InvalidArgumentException when using invalid value for ' .
  144. 'safeSearch.');
  145. }
  146. /**
  147. * @group ZF-8720
  148. * @expectedException Zend_Gdata_App_InvalidArgumentException
  149. */
  150. public function testVideoQuerySetLocationException()
  151. {
  152. $yt = new Zend_Gdata_YouTube();
  153. $query = $yt->newVideoQuery();
  154. $location = 'foobar';
  155. $this->assertNull($query->setLocation($location));
  156. }
  157. /**
  158. * @group ZF-8720
  159. * @expectedException Zend_Gdata_App_InvalidArgumentException
  160. */
  161. public function testVideoQuerySetLocationExceptionV2()
  162. {
  163. $yt = new Zend_Gdata_YouTube();
  164. $query = $yt->newVideoQuery();
  165. $location = '-100x,-200y';
  166. $this->assertNull($query->setLocation($location));
  167. }
  168. /**
  169. * @group ZF-8720
  170. * @expectedException Zend_Gdata_App_InvalidArgumentException
  171. */
  172. public function testVideoQuerySetLocationExceptionV3()
  173. {
  174. $yt = new Zend_Gdata_YouTube();
  175. $query = $yt->newVideoQuery();
  176. $location = '-100x,-200y!';
  177. $this->assertNull($query->setLocation($location));
  178. }
  179. /**
  180. * @group ZF-8720
  181. */
  182. public function testQueryExclamationMarkRemoveBug()
  183. {
  184. $yt = new Zend_Gdata_YouTube();
  185. $query = $yt->newVideoQuery();
  186. $location = '37.42307,-122.08427';
  187. $this->assertNull($query->setLocation($location));
  188. $this->assertEquals($location, $query->getLocation());
  189. $location = '37.42307,-122.08427!';
  190. $this->assertNull($query->setLocation($location));
  191. $this->assertEquals($location, $query->getLocation());
  192. }
  193. }