VideoQueryTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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) 2006 Zend Technologies USA Inc. (http://www.zend.com);
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * Test helper
  23. */
  24. require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  25. require_once 'Zend/Gdata/YouTube/VideoQuery.php';
  26. require_once 'Zend/Gdata/YouTube.php';
  27. /**
  28. * @package Zend_Gdata_App
  29. * @subpackage UnitTests
  30. */
  31. class Zend_Gdata_YouTube_VideoQueryTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function testQueryStringConstruction () {
  34. $yt = new Zend_Gdata_YouTube();
  35. $query = $yt->newVideoQuery();
  36. $query->setOrderBy('viewCount');
  37. $query->setVideoQuery('foobar');
  38. $expectedString = '?orderby=viewCount&vq=foobar';
  39. $this->assertEquals($expectedString, $query->getQueryString());
  40. }
  41. public function testQueryStringConstructionV2() {
  42. $yt = new Zend_Gdata_YouTube();
  43. $query = $yt->newVideoQuery();
  44. $query->setOrderBy('viewCount');
  45. $query->setVideoQuery('version2');
  46. $expectedString = '?orderby=viewCount&q=version2';
  47. $this->assertEquals($expectedString, $query->getQueryString(2));
  48. }
  49. public function testSafeSearchQueryV2() {
  50. $yt = new Zend_Gdata_YouTube();
  51. $query = $yt->newVideoQuery();
  52. $exceptionCaught = false;
  53. $query->setRacy('include');
  54. try {
  55. $query->getQueryString(2);
  56. } catch (Zend_Gdata_App_VersionException $e) {
  57. $exceptionCaught = true;
  58. }
  59. $this->assertTrue($exceptionCaught, 'Zend_Gdata_App_VersionException' .
  60. ' expected but not found');
  61. }
  62. public function testLocationRadiusV1() {
  63. $yt = new Zend_Gdata_YouTube();
  64. $query = $yt->newVideoQuery();
  65. $exceptionCaught = false;
  66. $query->setLocationRadius('1km');
  67. try {
  68. $query->getQueryString(1);
  69. } catch (Zend_Gdata_App_VersionException $e) {
  70. $exceptionCaught = true;
  71. }
  72. $this->assertTrue($exceptionCaught, 'Zend_Gdata_App_VersionException' .
  73. ' expected but not found');
  74. }
  75. public function testLocationV2() {
  76. $yt = new Zend_Gdata_YouTube();
  77. $query = $yt->newVideoQuery();
  78. $query->setLocation('-37.122,122.01');
  79. $expectedString = '?location=-37.122%2C122.01';
  80. $this->assertEquals($expectedString, $query->getQueryString(2));
  81. }
  82. public function testLocationExceptionOnNonNumericV2() {
  83. $yt = new Zend_Gdata_YouTube();
  84. $query = $yt->newVideoQuery();
  85. $exceptionCaught = false;
  86. try {
  87. $query->setLocation('mars');
  88. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  89. $exceptionCaught = true;
  90. }
  91. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  92. 'IllegalArgumentException when using alpha in setLocation');
  93. }
  94. public function testLocationExceptionOnOnlyOneCoordinateV2() {
  95. $yt = new Zend_Gdata_YouTube();
  96. $query = $yt->newVideoQuery();
  97. $exceptionCaught = false;
  98. try {
  99. $query->setLocation('-25.001');
  100. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  101. $exceptionCaught = true;
  102. }
  103. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  104. 'IllegalArgumentException when using only 1 coordinate ' .
  105. 'in setLocation');
  106. }
  107. public function testUploaderExceptionOnInvalidV2() {
  108. $yt = new Zend_Gdata_YouTube();
  109. $query = $yt->newVideoQuery();
  110. $exceptionCaught = false;
  111. try {
  112. $query->setUploader('invalid');
  113. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  114. $exceptionCaught = true;
  115. }
  116. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  117. 'IllegalArgumentException when using invalid string in ' .
  118. 'setUploader.');
  119. }
  120. public function testProjectionPresentInV2Query() {
  121. $yt = new Zend_Gdata_YouTube();
  122. $query = $yt->newVideoQuery();
  123. $query->setVideoQuery('foo');
  124. $expectedString = 'http://gdata.youtube.com/feeds/api/videos?q=foo';
  125. $this->assertEquals($expectedString, $query->getQueryUrl(2));
  126. }
  127. public function testSafeSearchParametersInV2() {
  128. $yt = new Zend_Gdata_YouTube();
  129. $query = $yt->newVideoQuery();
  130. $exceptionCaught = false;
  131. try {
  132. $query->setSafeSearch('invalid');
  133. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  134. $exceptionCaught = true;
  135. }
  136. $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
  137. 'InvalidArgumentException when using invalid value for ' .
  138. 'safeSearch.');
  139. }
  140. }