VideoQueryTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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-2012 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-2012 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. $yt = new Zend_Gdata_YouTube();
  37. $query = $yt->newVideoQuery();
  38. $query->setOrderBy('viewCount');
  39. $query->setVideoQuery('foobar');
  40. $expectedString = '?orderby=viewCount&vq=foobar';
  41. $this->assertEquals($expectedString, $query->getQueryString());
  42. }
  43. public function testQueryStringConstructionV2() {
  44. $yt = new Zend_Gdata_YouTube();
  45. $query = $yt->newVideoQuery();
  46. $query->setOrderBy('viewCount');
  47. $query->setVideoQuery('version2');
  48. $expectedString = '?orderby=viewCount&q=version2';
  49. $this->assertEquals($expectedString, $query->getQueryString(2));
  50. }
  51. public function testSafeSearchQueryV2() {
  52. $yt = new Zend_Gdata_YouTube();
  53. $query = $yt->newVideoQuery();
  54. $exceptionCaught = false;
  55. $query->setRacy('include');
  56. try {
  57. $query->getQueryString(2);
  58. } catch (Zend_Gdata_App_VersionException $e) {
  59. $exceptionCaught = true;
  60. }
  61. $this->assertTrue($exceptionCaught, 'Zend_Gdata_App_VersionException' .
  62. ' expected but not found');
  63. }
  64. public function testLocationRadiusV1() {
  65. $yt = new Zend_Gdata_YouTube();
  66. $query = $yt->newVideoQuery();
  67. $exceptionCaught = false;
  68. $query->setLocationRadius('1km');
  69. try {
  70. $query->getQueryString(1);
  71. } catch (Zend_Gdata_App_VersionException $e) {
  72. $exceptionCaught = true;
  73. }
  74. $this->assertTrue($exceptionCaught, 'Zend_Gdata_App_VersionException' .
  75. ' expected but not found');
  76. }
  77. public function testLocationV2() {
  78. $yt = new Zend_Gdata_YouTube();
  79. $query = $yt->newVideoQuery();
  80. $query->setLocation('-37.122,122.01');
  81. $expectedString = '?location=-37.122%2C122.01';
  82. $this->assertEquals($expectedString, $query->getQueryString(2));
  83. }
  84. public function testLocationExceptionOnNonNumericV2() {
  85. $yt = new Zend_Gdata_YouTube();
  86. $query = $yt->newVideoQuery();
  87. $exceptionCaught = false;
  88. try {
  89. $query->setLocation('mars');
  90. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  91. $exceptionCaught = true;
  92. }
  93. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  94. 'IllegalArgumentException when using alpha in setLocation');
  95. }
  96. public function testLocationExceptionOnOnlyOneCoordinateV2() {
  97. $yt = new Zend_Gdata_YouTube();
  98. $query = $yt->newVideoQuery();
  99. $exceptionCaught = false;
  100. try {
  101. $query->setLocation('-25.001');
  102. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  103. $exceptionCaught = true;
  104. }
  105. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  106. 'IllegalArgumentException when using only 1 coordinate ' .
  107. 'in setLocation');
  108. }
  109. public function testUploaderExceptionOnInvalidV2() {
  110. $yt = new Zend_Gdata_YouTube();
  111. $query = $yt->newVideoQuery();
  112. $exceptionCaught = false;
  113. try {
  114. $query->setUploader('invalid');
  115. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  116. $exceptionCaught = true;
  117. }
  118. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  119. 'IllegalArgumentException when using invalid string in ' .
  120. 'setUploader.');
  121. }
  122. public function testProjectionPresentInV2Query() {
  123. $yt = new Zend_Gdata_YouTube();
  124. $query = $yt->newVideoQuery();
  125. $query->setVideoQuery('foo');
  126. $expectedString = 'http://gdata.youtube.com/feeds/api/videos?q=foo';
  127. $this->assertEquals($expectedString, $query->getQueryUrl(2));
  128. }
  129. public function testSafeSearchParametersInV2() {
  130. $yt = new Zend_Gdata_YouTube();
  131. $query = $yt->newVideoQuery();
  132. $exceptionCaught = false;
  133. try {
  134. $query->setSafeSearch('invalid');
  135. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  136. $exceptionCaught = true;
  137. }
  138. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  139. 'InvalidArgumentException when using invalid value for ' .
  140. 'safeSearch.');
  141. }
  142. /**
  143. * @group ZF-8720
  144. * @expectedException Zend_Gdata_App_InvalidArgumentException
  145. */
  146. public function testVideoQuerySetLocationException()
  147. {
  148. $yt = new Zend_Gdata_YouTube();
  149. $query = $yt->newVideoQuery();
  150. $location = 'foobar';
  151. $this->assertNull($query->setLocation($location));
  152. }
  153. /**
  154. * @group ZF-8720
  155. * @expectedException Zend_Gdata_App_InvalidArgumentException
  156. */
  157. public function testVideoQuerySetLocationExceptionV2()
  158. {
  159. $yt = new Zend_Gdata_YouTube();
  160. $query = $yt->newVideoQuery();
  161. $location = '-100x,-200y';
  162. $this->assertNull($query->setLocation($location));
  163. }
  164. /**
  165. * @group ZF-8720
  166. * @expectedException Zend_Gdata_App_InvalidArgumentException
  167. */
  168. public function testVideoQuerySetLocationExceptionV3()
  169. {
  170. $yt = new Zend_Gdata_YouTube();
  171. $query = $yt->newVideoQuery();
  172. $location = '-100x,-200y!';
  173. $this->assertNull($query->setLocation($location));
  174. }
  175. /**
  176. * @group ZF-8720
  177. */
  178. public function testQueryExclamationMarkRemoveBug()
  179. {
  180. $yt = new Zend_Gdata_YouTube();
  181. $query = $yt->newVideoQuery();
  182. $location = '37.42307,-122.08427';
  183. $this->assertNull($query->setLocation($location));
  184. $this->assertEquals($location, $query->getLocation());
  185. $location = '37.42307,-122.08427!';
  186. $this->assertNull($query->setLocation($location));
  187. $this->assertEquals($location, $query->getLocation());
  188. }
  189. }