| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049 |
- <?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.php';
- require_once 'Zend/Gdata/YouTube/VideoQuery.php';
- require_once 'Zend/Gdata/ClientLogin.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_YouTubeOnlineTest extends PHPUnit_Framework_TestCase
- {
- public function setUp()
- {
- $this->ytAccount = constant('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT');
- $this->user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
- $this->pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
- $this->subscriptionTypeSchema = 'http://gdata.youtube.com/schemas/' .
- '2007/subscriptiontypes.cat';
- $this->gdata = new Zend_Gdata_YouTube();
- }
- public function tearDown()
- {
- }
- public function testRetrieveSubScriptionFeed()
- {
- $feed = $this->gdata->getSubscriptionFeed($this->ytAccount);
- $this->assertTrue($feed->totalResults->text > 0);
- $this->assertEquals('Subscriptions of ' . $this->ytAccount,
- $feed->title->text);
- $this->assertTrue(count($feed->entry) > 0);
- foreach ($feed->entry as $entry) {
- $this->assertTrue($entry->title->text != '');
- }
- }
- public function testRetrieveContactFeed()
- {
- $feed = $this->gdata->getContactFeed($this->ytAccount);
- $this->assertTrue($feed->totalResults->text > 0);
- $this->assertEquals('Contacts of ' . $this->ytAccount,
- $feed->title->text);
- $this->assertTrue(count($feed->entry) > 0);
- foreach ($feed->entry as $entry) {
- $this->assertTrue($entry->title->text != '');
- }
- $this->assertEquals('ytgdatatest1', $feed->entry[0]->username->text);
- }
- public function testRetrieveUserVideos()
- {
- $feed = $this->gdata->getUserUploads($this->ytAccount);
- $this->assertEquals('Uploads by ' . $this->ytAccount,
- $feed->title->text);
- $this->assertTrue(count($feed->entry) === 1);
- }
- public function testRetrieveVideoFeed()
- {
- $feed = $this->gdata->getVideoFeed();
- $query = new Zend_Gdata_YouTube_VideoQuery();
- $query->setVideoQuery('puppy');
- $feed = $this->gdata->getVideoFeed($query);
- foreach ($feed as $videoEntry) {
- $videoResponsesLink = $videoEntry->getVideoResponsesLink();
- $videoRatingsLink = $videoEntry->getVideoRatingsLink();
- $videoComplaintsLink = $videoEntry->getVideoComplaintsLink();
- }
- $feed = $this->gdata->getVideoFeed($query->getQueryUrl());
- }
- public function testRetrieveVideoEntry()
- {
- $entry = $this->gdata->getVideoEntry('66wj2g5yz0M');
- $this->assertEquals('TestMovie', $entry->title->text);
- $entry = $this->gdata->getVideoEntry(null, 'https://gdata.youtube.com/feeds/api/videos/66wj2g5yz0M');
- $this->assertEquals('TestMovie', $entry->title->text);
- }
- public function testRetrieveOtherFeeds()
- {
- $feed = $this->gdata->getRelatedVideoFeed('66wj2g5yz0M');
- $feed = $this->gdata->getVideoResponseFeed('66wj2g5yz0M');
- $feed = $this->gdata->getVideoCommentFeed('66wj2g5yz0M');
- $feed = $this->gdata->getWatchOnMobileVideoFeed();
- $feed = $this->gdata->getUserFavorites($this->ytAccount);
- }
- public function testRetrieveUserProfile()
- {
- $entry = $this->gdata->getUserProfile($this->ytAccount);
- $this->assertEquals($this->ytAccount . ' Channel', $entry->title->text);
- $this->assertEquals($this->ytAccount, $entry->username->text);
- $this->assertEquals('I\'m a lonely test account, with little to do but sit around and wait for people to use me. I get bored in between releases and often sleep to pass the time. Please use me more often, as I love to show off my talent in breaking your code.',
- $entry->description->text);
- $this->assertEquals(32, $entry->age->text);
- $this->assertEquals('crime and punishment, ps i love you, the stand', $entry->books->text);
- $this->assertEquals('Google', $entry->company->text);
- $this->assertEquals('software engineering, information architecture, photography, travel', $entry->hobbies->text);
- $this->assertEquals('Mountain View, CA', $entry->hometown->text);
- $this->assertEquals('San Francisco, CA 94114, US', $entry->location->text);
- $this->assertEquals('monk, heroes, law and order, top gun', $entry->movies->text);
- $this->assertEquals('imogen heap, frou frou, thievory corp, morcheeba, barenaked ladies', $entry->music->text);
- $this->assertEquals('Developer Programs', $entry->occupation->text);
- $this->assertEquals('University of the World', $entry->school->text);
- $this->assertEquals('f', $entry->gender->text);
- $this->assertEquals('taken', $entry->relationship->text);
- }
- public function testRetrieveAndUpdatePlaylistList()
- {
- $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
- $authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
- $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user,
- $this->pass,
- $service,
- null, // client
- 'Google-UnitTests-1.0', // source
- null, // loginToken
- null, // loginCaptcha
- $authenticationURL);
- $this->gdata = new Zend_Gdata_YouTube($httpClient,
- 'Google-UnitTests-1.0', 'ytapi-gdataops-12345-u78960r7-0',
- 'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7Eyu1IuvkioESq' .
- 'zRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
- $this->gdata->setMajorProtocolVersion(2);
- $feed = $this->gdata->getPlaylistListFeed($this->ytAccount);
- $this->assertTrue($feed->totalResults->text > 0);
- $this->assertEquals('Playlists of ' . $this->ytAccount,
- $feed->title->text);
- $this->assertTrue(count($feed->entry) > 0);
- $i = 0;
- foreach ($feed->entry as $entry) {
- $this->assertTrue($entry->title->text != '');
- if ($i == 0) {
- $entry->title->setText('new playlist title');
- $entry->save();
- }
- $i++;
- }
- }
- public function testRetrievePlaylistV2()
- {
- $this->gdata->setMajorProtocolVersion(2);
- $feed = $this->gdata->getPlaylistListFeed($this->ytAccount);
- $firstEntry = $feed->entries[0];
- $this->assertTrue($firstEntry instanceof Zend_Gdata_YouTube_PlaylistListEntry);
- $this->assertTrue($firstEntry->getSummary()->text != null);
- }
- public function testRetrievePlaylistVideoFeed()
- {
- $listFeed = $this->gdata->getPlaylistListFeed($this->ytAccount);
- $feed = $this->gdata->getPlaylistVideoFeed($listFeed->entry[0]->feedLink[0]->href);
- $this->assertTrue($feed->totalResults->text > 0);
- $this->assertTrue(count($feed->entry) > 0);
- foreach ($feed->entry as $entry) {
- $this->assertTrue($entry->title->text != '');
- }
- }
- public function testRetrieveTopRatedVideos()
- {
- $feed = $this->gdata->getTopRatedVideoFeed();
- $this->assertTrue($feed->totalResults->text > 10);
- $this->assertEquals('Top Rated', $feed->title->text);
- $this->assertTrue(count($feed->entry) > 0);
- foreach ($feed->entry as $entry) {
- $this->assertTrue($entry->rating->average > 3);
- $this->assertEquals(1, $entry->rating->min);
- $this->assertEquals(5, $entry->rating->max);
- $this->assertTrue($entry->rating->numRaters > 2);
- }
- }
- public function testRetrieveTopRatedVideosV2()
- {
- $this->gdata->setMajorProtocolVersion(2);
- $feed = $this->gdata->getTopRatedVideoFeed();
- $client = $this->gdata->getHttpClient();
- $positionOfAPIProjection = strpos(
- $client->getLastRequest(), "/feeds/api/");
- $this->assertTrue(is_numeric($positionOfAPIProjection));
- }
- public function testRetrieveMostViewedVideosV2()
- {
- $this->gdata->setMajorProtocolVersion(2);
- $feed = $this->gdata->getMostViewedVideoFeed();
- $client = $this->gdata->getHttpClient();
- $positionOfAPIProjection = strpos(
- $client->getLastRequest(), "/feeds/api/");
- $this->assertTrue(is_numeric($positionOfAPIProjection));
- }
- public function testRetrieveRecentlyFeaturedVideosV2()
- {
- $this->gdata->setMajorProtocolVersion(2);
- $feed = $this->gdata->getRecentlyFeaturedVideoFeed();
- $client = $this->gdata->getHttpClient();
- $positionOfAPIProjection = strpos(
- $client->getLastRequest(), "/feeds/api/");
- $this->assertTrue(is_numeric($positionOfAPIProjection));
- }
- public function testWatchOnMobileVideosV2()
- {
- $this->gdata->setMajorProtocolVersion(2);
- $feed = $this->gdata->getWatchOnMobileVideoFeed();
- $client = $this->gdata->getHttpClient();
- $positionOfAPIProjection = strpos(
- $client->getLastRequest(), "/feeds/api/");
- $this->assertTrue(is_numeric($positionOfAPIProjection));
- }
- public function testRetrieveMostViewedVideos()
- {
- $feed = $this->gdata->getMostViewedVideoFeed();
- $this->assertTrue($feed->totalResults->text > 10);
- $this->assertEquals('Most Viewed', $feed->title->text);
- $this->assertTrue(count($feed->entry) > 0);
- foreach ($feed->entry as $entry) {
- if ($entry->rating) {
- $this->assertEquals(1, $entry->rating->min);
- $this->assertEquals(5, $entry->rating->max);
- }
- }
- }
- /**
- * @group ZF-9479
- */
- public function testPerformV2Query()
- {
- $this->gdata->setMajorProtocolVersion(2);
- $query = $this->gdata->newVideoQuery();
- $query->videoQuery = 'zend framework';
- $query->startIndex = 0;
- $query->maxResults = 10;
- $query->orderBy = 'viewCount';
- $query->safeSearch = 'strict';
- $videoFeed = $this->gdata->getVideoFeed($query);
- $this->assertTrue(count($videoFeed->entry) > 0,
- 'Could not retrieve a single entry for location search:' .
- $query->getQueryUrl(2));
- }
- public function testPerformV2Query_Location()
- {
- $this->gdata->setMajorProtocolVersion(2);
- $query = $this->gdata->newVideoQuery();
- // Setting location to New York City
- $query->setLocation('-37.0625,-95.677068');
- $query->setLocationRadius('1000km');
- $videoFeed = $this->gdata->getVideoFeed($query);
- $this->assertTrue(count($videoFeed->entry) > 0,
- 'Could not retrieve a single entry for location search:' .
- $query->getQueryUrl(2));
- }
- public function testPerformV2Query_SafeSearch()
- {
- $this->gdata->setMajorProtocolVersion(2);
- $query = $this->gdata->newVideoQuery();
- $query->setSafeSearch('strict');
- $videoFeed = $this->gdata->getVideoFeed($query);
- $this->assertTrue(count($videoFeed->entry) > 0,
- 'Could not retrieve a single entry for safeSearch=strict search:' .
- $query->getQueryUrl(2));
- }
- public function testPeformV2Query_Uploader()
- {
- $this->gdata->setMajorProtocolVersion(2);
- $query = $this->gdata->newVideoQuery();
- $query->setUploader('partner');
- $videoFeed = $this->gdata->getVideoFeed($query);
- $this->assertTrue(count($videoFeed->entry) > 0,
- 'Could not retrieve a single entry for uploader=partner search:' .
- $query->getQueryUrl(2));
- foreach($videoFeed as $videoEntry) {
- $mg = $videoEntry->getMediaGroup();
- $this->assertEquals('partner',
- $mg->getMediaCredit()->getYTtype());
- }
- }
- public function testAddUpdateAndDeletePlaylistV2()
- {
- $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
- $authenticationURL =
- 'https://www.google.com/youtube/accounts/ClientLogin';
- $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user,
- $this->pass,
- $service,
- null, // client
- 'Google-UnitTests-1.0', // source
- null, // $loginToken
- null, // loginCaptcha
- $authenticationURL);
- $yt = new Zend_Gdata_YouTube(
- $httpClient, 'Google-UnitTests-1.0',
- 'ytapi-gdataops-12345-u78960r7-0',
- 'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7E' .
- 'yu1IuvkioESqzRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
- $yt->setMajorProtocolVersion(2);
- $feed = $yt->getPlaylistListFeed($this->ytAccount);
- // Add new
- $newPlaylist = $yt->newPlaylistListEntry();
- $newPlaylist->setMajorProtocolVersion(2);
- $titleString = $this->generateRandomString(10);
- $newPlaylist->title = $yt->newTitle()->setText($titleString);
- $newPlaylist->summary = $yt->newSummary()->setText('testing');
- $postUrl = 'https://gdata.youtube.com/feeds/api/users/default/playlists';
- $successfulInsertion = true;
- try {
- $yt->insertEntry($newPlaylist, $postUrl);
- } catch (Zend_Gdata_App_Exception $e) {
- $successfulInsertion = false;
- }
- $this->assertTrue($successfulInsertion, 'Failed to insert a new ' .
- 'playlist.');
- $playlistListFeed = $yt->getPlaylistListFeed('default');
- $playlistFound = false;
- $newPlaylistEntry = null;
- foreach ($playlistListFeed as $playlistListEntry) {
- if ($playlistListEntry->title->text == $titleString) {
- $playlistFound = true;
- $newPlaylistEntry = $playlistListEntry;
- break;
- }
- }
- $this->assertTrue($playlistFound, 'Could not find the newly inserted ' .
- 'playlist.');
- // Update it
- $newTitle = $this->generateRandomString(10);
- $newPlaylistEntry->title->setText($newTitle);
- $updatedSuccesfully = true;
- try {
- $newPlaylistEntry->save();
- } catch (Zend_Gdata_App_Exception $e) {
- $updatedSuccesfully = false;
- }
- $this->assertTrue($updatedSuccesfully, 'Could not succesfully update ' .
- 'a new playlist.');
- // Delete it
- $deletedSuccesfully = true;
- try {
- $newPlaylistEntry->delete();
- } catch (Zend_Gdata_App_Exception $e) {
- $deletedSuccesfully = false;
- }
- $this->assertTrue($deletedSuccesfully, 'Could not succesfully delete ' .
- 'a new playlist.');
- }
- public function testAddAndDeleteSubscriptionToChannelV2()
- {
- $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
- $authenticationURL =
- 'https://www.google.com/youtube/accounts/ClientLogin';
- $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user,
- $this->pass,
- $service,
- null, // client
- 'Google-UnitTests-1.0', // source
- null, // loginToken
- null, // loginCaptcha
- $authenticationURL);
- $yt = new Zend_Gdata_YouTube(
- $httpClient, 'Google-UnitTests-1.0',
- 'ytapi-gdataops-12345-u78960r7-0',
- 'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7E' .
- 'yu1IuvkioESqzRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
- $yt->setMajorProtocolVersion(2);
- $channelToSubscribeTo = 'AssociatedPress';
- // Test for deletion first in case something went wrong
- // last time the test was run (network, etc...)
- $subscriptionFeed = $yt->getSubscriptionFeed($this->ytAccount);
- $successDeletionUpFront = true;
- $message = null;
- foreach($subscriptionFeed as $subscriptionEntry) {
- $subscriptionType = null;
- $categories = $subscriptionEntry->getCategory();
- // examine the correct category element since there are multiple
- foreach($categories as $category) {
- if ($category->getScheme() ==
- 'http://gdata.youtube.com/schemas/2007/' .
- 'subscriptiontypes.cat') {
- $subscriptionType = $category->getTerm();
- }
- }
- if ($subscriptionType == 'channel') {
- if ($subscriptionEntry->getUsername()->text ==
- $channelToSubscribeTo) {
- try {
- $subscriptionEntry->delete();
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successDeletionUpFront = false;
- }
- }
- }
- }
- $this->assertTrue($successDeletionUpFront, 'Found existing ' .
- 'subscription in unit test, could not delete prior to running ' .
- 'test -- ' . $message);
- // Channel
- $newSubscription = $yt->newSubscriptionEntry();
- $newSubscription->category = array(
- $yt->newCategory('channel',
- $this->subscriptionTypeSchema));
- $newSubscription->setUsername($yt->newUsername(
- $channelToSubscribeTo));
- $postUrl =
- 'https://gdata.youtube.com/feeds/api/users/default/subscriptions';
- $successPosting = true;
- $message = null;
- $insertedSubscription = null;
- try {
- $insertedSubscription = $yt->insertEntry(
- $newSubscription, $postUrl,
- 'Zend_Gdata_YouTube_SubscriptionEntry');
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successPosting = false;
- }
- $this->assertTrue($successPosting, $message);
- // Delete it
- $successDeletion = true;
- $message = null;
- try {
- $insertedSubscription->delete();
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successDeletion = false;
- }
- $this->assertTrue($successDeletion, $message);
- }
- public function testAddAndDeleteSubscriptionToFavoritesV2()
- {
- $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
- $authenticationURL =
- 'https://www.google.com/youtube/accounts/ClientLogin';
- $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
- $username = $this->user,
- $password = $this->pass,
- $service = $service,
- $client = null,
- $source = 'Google-UnitTests-1.0',
- $loginToken = null,
- $loginCaptcha = null,
- $authenticationURL);
- $yt = new Zend_Gdata_YouTube(
- $httpClient, 'Google-UnitTests-1.0',
- 'ytapi-gdataops-12345-u78960r7-0',
- 'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7E' .
- 'yu1IuvkioESqzRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
- $yt->setMajorProtocolVersion(2);
- $usernameOfFavoritesToSubscribeTo = 'CBS';
- // Test for deletion first in case something went wrong
- // last time the test was run (network, etc...)
- $subscriptionFeed = $yt->getSubscriptionFeed($this->ytAccount);
- $successDeletionUpFront = true;
- $message = null;
- foreach($subscriptionFeed as $subscriptionEntry) {
- $subscriptionType = null;
- $categories = $subscriptionEntry->getCategory();
- // examine the correct category element since there are multiple
- foreach($categories as $category) {
- if ($category->getScheme() ==
- 'http://gdata.youtube.com/schemas/2007/' .
- 'subscriptiontypes.cat') {
- $subscriptionType = $category->getTerm();
- }
- }
- if ($subscriptionType == 'favorites') {
- if ($subscriptionEntry->getUsername()->text ==
- $usernameOfFavoritesToSubscribeTo) {
- try {
- $subscriptionEntry->delete();
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successDeletionUpFront = false;
- }
- }
- }
- }
- $this->assertTrue($successDeletionUpFront, 'Found existing ' .
- 'subscription in unit test, could not delete prior to running ' .
- 'test -- ' . $message);
- // CBS's favorites
- $newSubscription = $yt->newSubscriptionEntry();
- $newSubscription->category = array(
- $yt->newCategory('favorites',
- $this->subscriptionTypeSchema));
- $newSubscription->setUsername($yt->newUsername(
- $usernameOfFavoritesToSubscribeTo));
- $postUrl =
- 'https://gdata.youtube.com/feeds/api/users/default/subscriptions';
- $successPosting = true;
- $message = null;
- $insertedSubscription = null;
- try {
- $insertedSubscription = $yt->insertEntry(
- $newSubscription, $postUrl,
- 'Zend_Gdata_YouTube_SubscriptionEntry');
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successPosting = false;
- }
- $this->assertTrue($successPosting, $message);
- // Delete it
- $successDeletion = true;
- $message = null;
- try {
- $insertedSubscription->delete();
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successDeletion = false;
- }
- $this->assertTrue($successDeletion, $message);
- }
- public function testAddAndDeleteSubscriptionToPlaylistV2()
- {
- $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
- $authenticationURL =
- 'https://www.google.com/youtube/accounts/ClientLogin';
- $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
- $username = $this->user,
- $password = $this->pass,
- $service = $service,
- $client = null,
- $source = 'Google-UnitTests-1.0',
- $loginToken = null,
- $loginCaptcha = null,
- $authenticationURL);
- $yt = new Zend_Gdata_YouTube(
- $httpClient, 'Google-UnitTests-1.0',
- 'ytapi-gdataops-12345-u78960r7-0',
- 'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7E' .
- 'yu1IuvkioESqzRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
- $yt->setMajorProtocolVersion(2);
- $playlistIdToSubscribeTo = '7A2BB4AFFEBED2A4';
- // Test for deletion first in case something went wrong
- // last time the test was run (network, etc...)
- $subscriptionFeed = $yt->getSubscriptionFeed($this->ytAccount);
- $successDeletionUpFront = true;
- $message = null;
- foreach($subscriptionFeed as $subscriptionEntry) {
- $subscriptionType = null;
- $categories = $subscriptionEntry->getCategory();
- // examine the correct category element since there are multiple
- foreach($categories as $category) {
- if ($category->getScheme() ==
- 'http://gdata.youtube.com/schemas/2007/' .
- 'subscriptiontypes.cat') {
- $subscriptionType = $category->getTerm();
- }
- }
- if ($subscriptionType == 'playlist') {
- if ($subscriptionEntry->getPlaylistId()->text ==
- $playlistIdToSubscribeTo) {
- try {
- $subscriptionEntry->delete();
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successDeletionUpFront = false;
- }
- }
- }
- }
- $this->assertTrue($successDeletionUpFront, 'Found existing ' .
- 'subscription in unit test, could not delete prior to running ' .
- 'test -- ' . $message);
- // Playlist of McGyver videos
- $newSubscription = $yt->newSubscriptionEntry();
- $newSubscription->setMajorProtocolVersion(2);
- $newSubscription->category = array(
- $yt->newCategory('playlist',
- $this->subscriptionTypeSchema));
- $newSubscription->setPlaylistId($yt->newPlaylistId(
- $playlistIdToSubscribeTo));
- $postUrl =
- 'https://gdata.youtube.com/feeds/api/users/default/subscriptions';
- $successPosting = true;
- $message = null;
- $insertedSubscription = null;
- try {
- $insertedSubscription = $yt->insertEntry(
- $newSubscription, $postUrl,
- 'Zend_Gdata_YouTube_SubscriptionEntry');
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successPosting = false;
- }
- $this->assertTrue($successPosting, $message);
- // Delete it
- $successDeletion = true;
- $message = null;
- try {
- $insertedSubscription->delete();
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successDeletion = false;
- }
- $this->assertTrue($successDeletion, $message);
- }
- public function testAddAndDeleteSubscriptionToQueryV2()
- {
- $developerKey = constant('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
- $clientId = constant('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
- $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
- $authenticationURL =
- 'https://www.google.com/youtube/accounts/ClientLogin';
- $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
- $username = $this->user,
- $password = $this->pass,
- $service = $service,
- $client = null,
- $source = 'Google-UnitTests-1.0',
- $loginToken = null,
- $loginCaptcha = null,
- $authenticationURL);
- $yt = new Zend_Gdata_YouTube($httpClient, 'Google-UnitTests-1.0', $clientId, $developerKey);
- $yt->setMajorProtocolVersion(2);
- $queryStringToSubscribeTo = 'zend';
- // Test for deletion first in case something went wrong
- // last time the test was run (network, etc...)
- $subscriptionFeed = $yt->getSubscriptionFeed($this->ytAccount);
- $successDeletionUpFront = true;
- $message = null;
- foreach($subscriptionFeed as $subscriptionEntry) {
- $subscriptionType = null;
- $categories = $subscriptionEntry->getCategory();
- // examine the correct category element since there are multiple
- foreach($categories as $category) {
- if ($category->getScheme() ==
- 'http://gdata.youtube.com/schemas/2007/' .
- 'subscriptiontypes.cat') {
- $subscriptionType = $category->getTerm();
- }
- }
- if ($subscriptionType == 'query') {
- if ($subscriptionEntry->getQueryString() ==
- $queryStringToSubscribeTo) {
- try {
- $subscriptionEntry->delete();
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successDeletionUpFront = false;
- }
- }
- }
- }
- $this->assertTrue($successDeletionUpFront, 'Found existing ' .
- 'subscription in unit test, could not delete prior to running ' .
- 'test -- ' . $message);
- // Query
- $newSubscription = $yt->newSubscriptionEntry();
- $newSubscription->category = array(
- $yt->newCategory('query',
- $this->subscriptionTypeSchema));
- $newSubscription->setQueryString($yt->newQueryString(
- $queryStringToSubscribeTo));
- $postUrl =
- 'https://gdata.youtube.com/feeds/api/users/default/subscriptions';
- $successPosting = true;
- $message = null;
- $insertedSubscription = null;
- try {
- $insertedSubscription = $yt->insertEntry(
- $newSubscription, $postUrl,
- 'Zend_Gdata_YouTube_SubscriptionEntry');
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successPosting = false;
- }
- $this->assertTrue($successPosting, $message);
- // Delete it
- $successDeletion = true;
- $message = null;
- try {
- $insertedSubscription->delete();
- } catch (Zend_App_Exception $e) {
- $message = $e->getMessage();
- $successDeletion = false;
- }
- $this->assertTrue($successDeletion, $message);
- }
- public function generateRandomString($length)
- {
- $outputString = null;
- for($i = 0; $i < $length; $i++) {
- $outputString .= chr(rand(65,90));
- }
- return $outputString;
- }
- public function testRetrieveActivityFeed()
- {
- $developerKey = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
- $clientId = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
- $client = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user, $this->pass, 'youtube' , null, 'ZF_UnitTest', null, null,
- 'https://www.google.com/youtube/accounts/ClientLogin');
- $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
- $clientId, $developerKey);
- $youtube->setMajorProtocolVersion(2);
- $feed = $youtube->getActivityForUser($this->ytAccount);
- $this->assertTrue($feed instanceof Zend_Gdata_YouTube_ActivityFeed);
- $this->assertTrue((count($feed->entries) > 0));
- $this->assertEquals('Activity of ' . $this->ytAccount,
- $feed->title->text);
- }
- public function testExceptionIfNotUsingDeveloperKey()
- {
- $exceptionThrown = false;
- $youtube = new Zend_Gdata_YouTube();
- $youtube->setMajorProtocolVersion(2);
- try {
- $youtube->getActivityForUser($this->ytAccount);
- } catch (Zend_Gdata_App_HttpException $e) {
- $exceptionThrown = true;
- }
- $this->assertTrue($exceptionThrown, 'Was expecting an exception when ' .
- 'making a request to the YouTube Activity feed without a ' .
- 'developer key.');
- }
- public function testRetrieveActivityFeedForMultipleUsers()
- {
- $developerKey = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
- $clientId = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
- $client = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user, $this->pass, 'youtube' , null, 'ZF_UnitTest', null, null,
- 'https://www.google.com/youtube/accounts/ClientLogin');
- $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
- $clientId, $developerKey);
- $youtube->setMajorProtocolVersion(2);
- $feed = $youtube->getActivityForUser($this->ytAccount .
- ',associatedpress');
- $this->assertTrue($feed instanceof Zend_Gdata_YouTube_ActivityFeed);
- $this->assertTrue((count($feed->entries) > 0));
- $this->assertEquals('Activity of ' . $this->ytAccount .
- ',associatedpress', $feed->title->text);
- }
- public function testRetrieveFriendFeed()
- {
- $developerKey = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
- $clientId = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
- $client = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user, $this->pass, 'youtube' , null, 'ZF_UnitTest', null, null,
- 'https://www.google.com/youtube/accounts/ClientLogin');
- $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
- $clientId, $developerKey);
- $youtube->setMajorProtocolVersion(2);
- $feed = $youtube->getFriendActivityForCurrentUser();
- $this->assertTrue($feed instanceof Zend_Gdata_YouTube_ActivityFeed);
- $this->assertTrue((count($feed->entries) > 0));
- $this->assertEquals('Activity of the friends of ' . $this->ytAccount,
- $feed->title->text);
- }
- public function testThrowExceptionOnActivityFeedRequestForMoreThan20Users()
- {
- $exceptionThrown = false;
- $listOfMoreThan20Users = null;
- $youtube = new Zend_Gdata_YouTube();
- $youtube->setMajorProtocolVersion(2);
- for ($x = 0; $x < 30; $x++) {
- $listOfMoreThan20Users .= "user$x";
- if ($x != 29) {
- $listOfMoreThan20Users .= ",";
- }
- }
- try {
- $youtube->getActivityForUser($listOfMoreThan20Users);
- } catch (Zend_Gdata_App_InvalidArgumentException $e) {
- $exceptionThrown = true;
- }
- $this->assertTrue($exceptionThrown, 'Was expecting an exception on ' .
- 'a request to ->getActivityForUser when more than 20 users were ' .
- 'specified in YouTube.php');
- }
- public function testGetInboxFeedForCurrentUserV1()
- {
- $developerKey = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
- $clientId = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
- $client = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user, $this->pass, 'youtube' , null, 'ZF_UnitTest', null, null,
- 'https://www.google.com/youtube/accounts/ClientLogin');
- $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
- $clientId, $developerKey);
- $inboxFeed = $youtube->getInboxFeedForCurrentUser();
- $this->assertTrue($inboxFeed instanceof Zend_Gdata_YouTube_InboxFeed);
- $this->assertTrue(count($inboxFeed->entries) > 0, 'Test account ' .
- $this->ytAccount . ' had no messages in their inbox.');
- // get the first entry
- $inboxFeed->rewind();
- $inboxEntry = $inboxFeed->current();
- $this->assertTrue(
- $inboxEntry instanceof Zend_Gdata_YouTube_InboxEntry);
- $this->assertTrue($inboxEntry->getTitle()->text != '');
- }
- public function testGetInboxFeedForCurrentUserV2()
- {
- $developerKey = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
- $clientId = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
- $client = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user, $this->pass, 'youtube' , null, 'ZF_UnitTest', null, null,
- 'https://www.google.com/youtube/accounts/ClientLogin');
- $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
- $clientId, $developerKey);
- $youtube->setMajorProtocolVersion(2);
- $inboxFeed = $youtube->getInboxFeedForCurrentUser();
- $this->assertTrue($inboxFeed instanceof Zend_Gdata_YouTube_InboxFeed);
- $this->assertTrue(count($inboxFeed->entries) > 0, 'Test account ' .
- $this->ytAccount . ' had no messages in their inbox.');
- // get the first entry
- $inboxFeed->rewind();
- $inboxEntry = $inboxFeed->current();
- $this->assertTrue(
- $inboxEntry instanceof Zend_Gdata_YouTube_InboxEntry);
- $this->assertTrue($inboxEntry->getTitle()->text != '');
- }
- public function testSendAMessageV2()
- {
- $developerKey = constant('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
- $clientId = constant('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
- $client = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user, $this->pass, 'youtube' , null, 'ZF_UnitTest', null, null,
- 'https://www.google.com/youtube/accounts/ClientLogin');
- $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
- $clientId, $developerKey);
- $youtube->setMajorProtocolVersion(2);
- // get a video from the recently featured video feed
- $videoFeed = $youtube->getRecentlyFeaturedVideoFeed();
- $videoEntry = $videoFeed->entry[0];
- $this->assertTrue($videoEntry instanceof Zend_Gdata_YouTube_VideoEntry);
- // sending message to gdpython (python client library unit test user)
- $sentMessage = $youtube->sendVideoMessage(
- 'Sending a v2 test message from Zend_Gdata_YouTubeOnlineTest.',
- $videoEntry, null, 'gdpython');
- $this->assertTrue(
- $sentMessage instanceof Zend_Gdata_YouTube_InboxEntry);
- }
- public function testSendAMessageV1()
- {
- $developerKey = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
- $clientId = constant(
- 'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
- $client = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user, $this->pass, 'youtube' , null, 'ZF_UnitTest', null, null,
- 'https://www.google.com/youtube/accounts/ClientLogin');
- $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
- $clientId, $developerKey);
- $youtube->setMajorProtocolVersion(1);
- // get a video from the recently featured video feed
- $videoFeed = $youtube->getRecentlyFeaturedVideoFeed();
- $videoEntry = $videoFeed->entry[0];
- $this->assertTrue($videoEntry instanceof Zend_Gdata_YouTube_VideoEntry);
- // sending message to gdpython (python client library unit test user)
- $sentMessage = $youtube->sendVideoMessage(
- 'Sending a v1 test message from Zend_Gdata_YouTubeOnlineTest.',
- $videoEntry, null, 'gdpython');
- $this->assertTrue(
- $sentMessage instanceof Zend_Gdata_YouTube_InboxEntry);
- }
- public function testThrowExceptionOnSendingMessageWithoutVideo()
- {
- $exceptionCaught = false;
- $this->gdata = new Zend_Gdata_YouTube();
- try {
- $this->gdata->sendVideoMessage('Should fail', null, null, 'foo');
- } catch (Zend_Gdata_App_InvalidArgumentException $e) {
- $exceptionCaught = true;
- }
- $this->assertTrue($exceptionCaught, 'Was expecting an exception if ' .
- 'sending a message without a video');
- }
- public function testCommentOnAComment()
- {
- $developerKey = constant('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
- $clientId = constant('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
- $client = Zend_Gdata_ClientLogin::getHttpClient(
- $this->user, $this->pass, 'youtube' , null, 'ZF_UnitTest', null, null,
- 'https://www.google.com/youtube/accounts/ClientLogin');
- $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
- $clientId, $developerKey);
- $youtube->setMajorProtocolVersion(2);
- $mostDiscussedFeed = $youtube->getVideoFeed(
- 'https://gdata.youtube.com/feeds/api/standardfeeds/most_discussed');
- // get first entry
- $mostDiscussedFeed->rewind();
- $firstEntry = $mostDiscussedFeed->current();
- $this->assertTrue($firstEntry instanceof Zend_Gdata_YouTube_VideoEntry);
- $commentFeed = $youtube->getVideoCommentFeed($firstEntry->getVideoId());
- // get first comment
- $commentFeed->rewind();
- $firstCommentEntry = $commentFeed->current();
- $commentedComment = $youtube->replyToCommentEntry($firstCommentEntry,
- 'awesome ! (ZFUnitTest-test)');
- $this->assertTrue(
- $commentedComment instanceof Zend_Gdata_YouTube_CommentEntry);
- }
- }
|