| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Gdata_YouTube
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id $
- */
- require_once 'Zend/Gdata/YouTube/VideoQuery.php';
- require_once 'Zend/Gdata/YouTube.php';
- /**
- * @category Zend
- * @package Zend_Gdata_YouTube
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Gdata
- * @group Zend_Gdata_YouTube
- */
- class Zend_Gdata_YouTube_VideoQueryTest extends PHPUnit_Framework_TestCase
- {
- public function testQueryStringConstruction()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $query->setOrderBy('viewCount');
- $query->setVideoQuery('foobar');
- $expectedString = '?orderby=viewCount&vq=foobar';
- $this->assertEquals($expectedString, $query->getQueryString());
- }
- public function testQueryStringConstructionV2()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $query->setOrderBy('viewCount');
- $query->setVideoQuery('version2');
- $expectedString = '?orderby=viewCount&q=version2';
- $this->assertEquals($expectedString, $query->getQueryString(2));
- }
- public function testSafeSearchQueryV2()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $exceptionCaught = false;
- $query->setRacy('include');
- try {
- $query->getQueryString(2);
- } catch (Zend_Gdata_App_VersionException $e) {
- $exceptionCaught = true;
- }
- $this->assertTrue($exceptionCaught, 'Zend_Gdata_App_VersionException' .
- ' expected but not found');
- }
- public function testLocationRadiusV1()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $exceptionCaught = false;
- $query->setLocationRadius('1km');
- try {
- $query->getQueryString(1);
- } catch (Zend_Gdata_App_VersionException $e) {
- $exceptionCaught = true;
- }
- $this->assertTrue($exceptionCaught, 'Zend_Gdata_App_VersionException' .
- ' expected but not found');
- }
- public function testLocationV2()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $query->setLocation('-37.122,122.01');
- $expectedString = '?location=-37.122%2C122.01';
- $this->assertEquals($expectedString, $query->getQueryString(2));
- }
- public function testLocationExceptionOnNonNumericV2()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $exceptionCaught = false;
- try {
- $query->setLocation('mars');
- } catch (Zend_Gdata_App_InvalidArgumentException $e) {
- $exceptionCaught = true;
- }
- $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
- 'IllegalArgumentException when using alpha in setLocation');
- }
- public function testLocationExceptionOnOnlyOneCoordinateV2()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $exceptionCaught = false;
- try {
- $query->setLocation('-25.001');
- } catch (Zend_Gdata_App_InvalidArgumentException $e) {
- $exceptionCaught = true;
- }
- $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
- 'IllegalArgumentException when using only 1 coordinate ' .
- 'in setLocation');
- }
- public function testUploaderExceptionOnInvalidV2()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $exceptionCaught = false;
- try {
- $query->setUploader('invalid');
- } catch (Zend_Gdata_App_InvalidArgumentException $e) {
- $exceptionCaught = true;
- }
- $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
- 'IllegalArgumentException when using invalid string in ' .
- 'setUploader.');
- }
- public function testProjectionPresentInV2Query()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $query->setVideoQuery('foo');
- $expectedString = 'https://gdata.youtube.com/feeds/api/videos?q=foo';
- $this->assertEquals($expectedString, $query->getQueryUrl(2));
- }
- public function testSafeSearchParametersInV2()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $exceptionCaught = false;
- try {
- $query->setSafeSearch('invalid');
- } catch (Zend_Gdata_App_InvalidArgumentException $e) {
- $exceptionCaught = true;
- }
- $this->assertTrue($exceptionCaught, 'Expected Zend_Gdata_App_' .
- 'InvalidArgumentException when using invalid value for ' .
- 'safeSearch.');
- }
- /**
- * @group ZF-8720
- * @expectedException Zend_Gdata_App_InvalidArgumentException
- */
- public function testVideoQuerySetLocationException()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $location = 'foobar';
- $this->assertNull($query->setLocation($location));
- }
- /**
- * @group ZF-8720
- * @expectedException Zend_Gdata_App_InvalidArgumentException
- */
- public function testVideoQuerySetLocationExceptionV2()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $location = '-100x,-200y';
- $this->assertNull($query->setLocation($location));
- }
- /**
- * @group ZF-8720
- * @expectedException Zend_Gdata_App_InvalidArgumentException
- */
- public function testVideoQuerySetLocationExceptionV3()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $location = '-100x,-200y!';
- $this->assertNull($query->setLocation($location));
- }
- /**
- * @group ZF-8720
- */
- public function testQueryExclamationMarkRemoveBug()
- {
- $yt = new Zend_Gdata_YouTube();
- $query = $yt->newVideoQuery();
- $location = '37.42307,-122.08427';
- $this->assertNull($query->setLocation($location));
- $this->assertEquals($location, $query->getLocation());
- $location = '37.42307,-122.08427!';
- $this->assertNull($query->setLocation($location));
- $this->assertEquals($location, $query->getLocation());
- }
- /**
- * @group ZF-12500
- */
- public function testQueryUrlForFeedTypRelated()
- {
- $yt = new Zend_Gdata_YouTube();
- // Query
- $query = $yt->newVideoQuery();
- $query->setFeedType('related', 'foo');
- // Test
- $this->assertSame(
- 'https://gdata.youtube.com/feeds/api/videos/foo/related',
- $query->getQueryUrl()
- );
- }
- /**
- * @group ZF-12500
- */
- public function testQueryUrlForFeedTypResponses()
- {
- $yt = new Zend_Gdata_YouTube();
- // Query
- $query = $yt->newVideoQuery();
- $query->setFeedType('responses', 'foo');
- // Test
- $this->assertSame(
- 'https://gdata.youtube.com/feeds/api/videos/foo/responses',
- $query->getQueryUrl()
- );
- }
- /**
- * @group ZF-12500
- */
- public function testQueryUrlForFeedTypComments()
- {
- $yt = new Zend_Gdata_YouTube();
- // Query
- $query = $yt->newVideoQuery();
- $query->setFeedType('comments', 'foo');
- // Test
- $this->assertSame(
- 'https://gdata.youtube.com/feeds/api/videos/foo/comments',
- $query->getQueryUrl()
- );
- }
- }
|