~clinton-collins/familyproject/trunk

« back to all changes in this revision

Viewing changes to ZendFramework/tests/Zend/Gdata/YouTubeOnlineTest.php

  • Committer: Clinton Collins
  • Date: 2009-06-26 19:54:58 UTC
  • Revision ID: clinton.collins@gmail.com-20090626195458-5ebba0qcvo15xlpy
Initial Import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Zend Framework
 
5
 *
 
6
 * LICENSE
 
7
 *
 
8
 * This source file is subject to the new BSD license that is bundled
 
9
 * with this package in the file LICENSE.txt.
 
10
 * It is also available through the world-wide-web at this URL:
 
11
 * http://framework.zend.com/license/new-bsd
 
12
 * If you did not receive a copy of the license and are unable to
 
13
 * obtain it through the world-wide-web, please send an email
 
14
 * to license@zend.com so we can send you a copy immediately.
 
15
 *
 
16
 * @category   Zend
 
17
 * @package    Zend_Gdata
 
18
 * @subpackage UnitTests
 
19
 * @copyright  Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
 
20
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
21
 */
 
22
 
 
23
require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
 
24
 
 
25
require_once 'Zend/Gdata/YouTube.php';
 
26
require_once 'Zend/Gdata/YouTube/VideoQuery.php';
 
27
require_once 'Zend/Gdata/ClientLogin.php';
 
28
 
 
29
/**
 
30
 * @package Zend_Gdata
 
31
 * @subpackage UnitTests
 
32
 */
 
33
class Zend_Gdata_YouTubeOnlineTest extends PHPUnit_Framework_TestCase
 
34
{
 
35
 
 
36
    public function setUp()
 
37
    {
 
38
        $this->ytAccount = constant('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT');
 
39
        $this->subscriptionTypeSchema = 'http://gdata.youtube.com/schemas/' .
 
40
            '2007/subscriptiontypes.cat';
 
41
        $this->gdata = new Zend_Gdata_YouTube();
 
42
    }
 
43
 
 
44
    public function tearDown()
 
45
    {
 
46
    }
 
47
 
 
48
    public function testRetrieveSubScriptionFeed()
 
49
    {
 
50
        $feed = $this->gdata->getSubscriptionFeed($this->ytAccount);
 
51
        $this->assertTrue($feed->totalResults->text > 0);
 
52
        $this->assertEquals('Subscriptions of ' . $this->ytAccount,
 
53
            $feed->title->text);
 
54
        $this->assertTrue(count($feed->entry) > 0);
 
55
        foreach ($feed->entry as $entry) {
 
56
            $this->assertTrue($entry->title->text != '');
 
57
        }
 
58
    }
 
59
 
 
60
    public function testRetrieveContactFeed()
 
61
    {
 
62
        $feed = $this->gdata->getContactFeed($this->ytAccount);
 
63
        $this->assertTrue($feed->totalResults->text > 0);
 
64
        $this->assertEquals('Contacts of ' . $this->ytAccount,
 
65
            $feed->title->text);
 
66
        $this->assertTrue(count($feed->entry) > 0);
 
67
        foreach ($feed->entry as $entry) {
 
68
            $this->assertTrue($entry->title->text != '');
 
69
        }
 
70
        $this->assertEquals('ytgdatatest1', $feed->entry[0]->username->text);
 
71
    }
 
72
 
 
73
    public function testRetrieveUserVideos()
 
74
    {
 
75
        $feed = $this->gdata->getUserUploads($this->ytAccount);
 
76
        $this->assertEquals('Uploads by ' . $this->ytAccount,
 
77
            $feed->title->text);
 
78
        $this->assertTrue(count($feed->entry) === 1);
 
79
    }
 
80
 
 
81
    public function testRetrieveVideoFeed()
 
82
    {
 
83
        $feed = $this->gdata->getVideoFeed();
 
84
 
 
85
        $query = new Zend_Gdata_YouTube_VideoQuery();
 
86
        $query->setVideoQuery('puppy');
 
87
        $feed = $this->gdata->getVideoFeed($query);
 
88
        foreach ($feed as $videoEntry) {
 
89
            $videoResponsesLink = $videoEntry->getVideoResponsesLink();
 
90
            $videoRatingsLink = $videoEntry->getVideoRatingsLink();
 
91
            $videoComplaintsLink = $videoEntry->getVideoComplaintsLink();
 
92
        }
 
93
 
 
94
        $feed = $this->gdata->getVideoFeed($query->getQueryUrl());
 
95
    }
 
96
 
 
97
    public function testRetrieveVideoEntry()
 
98
    {
 
99
        $entry = $this->gdata->getVideoEntry('66wj2g5yz0M');
 
100
        $this->assertEquals('TestMovie', $entry->title->text);
 
101
 
 
102
        $entry = $this->gdata->getVideoEntry(null, 'http://gdata.youtube.com/feeds/api/videos/66wj2g5yz0M');
 
103
        $this->assertEquals('TestMovie', $entry->title->text);
 
104
    }
 
105
 
 
106
    public function testRetrieveOtherFeeds()
 
107
    {
 
108
        $feed = $this->gdata->getRelatedVideoFeed('66wj2g5yz0M');
 
109
        $feed = $this->gdata->getVideoResponseFeed('66wj2g5yz0M');
 
110
        $feed = $this->gdata->getVideoCommentFeed('66wj2g5yz0M');
 
111
        $feed = $this->gdata->getWatchOnMobileVideoFeed();
 
112
        $feed = $this->gdata->getUserFavorites($this->ytAccount);
 
113
    }
 
114
 
 
115
    public function testRetrieveUserProfile()
 
116
    {
 
117
        $entry = $this->gdata->getUserProfile($this->ytAccount);
 
118
        $this->assertEquals($this->ytAccount . ' Channel', $entry->title->text);
 
119
        $this->assertEquals($this->ytAccount, $entry->username->text);
 
120
        $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.',
 
121
                $entry->description->text);
 
122
        $this->assertEquals(32, $entry->age->text);
 
123
        $this->assertEquals('crime and punishment, ps i love you, the stand', $entry->books->text);
 
124
        $this->assertEquals('Google', $entry->company->text);
 
125
        $this->assertEquals('software engineering, information architecture, photography, travel', $entry->hobbies->text);
 
126
        $this->assertEquals('Mountain View, CA', $entry->hometown->text);
 
127
        $this->assertEquals('San Francisco, CA 94114, US', $entry->location->text);
 
128
        $this->assertEquals('monk, heroes, law and order, top gun', $entry->movies->text);
 
129
        $this->assertEquals('imogen heap, frou frou, thievory corp, morcheeba, barenaked ladies', $entry->music->text);
 
130
        $this->assertEquals('Developer Programs', $entry->occupation->text);
 
131
        $this->assertEquals('University of the World', $entry->school->text);
 
132
        $this->assertEquals('f', $entry->gender->text);
 
133
        $this->assertEquals('taken', $entry->relationship->text);
 
134
    }
 
135
 
 
136
    public function testRetrieveAndUpdatePlaylistList()
 
137
    {
 
138
 
 
139
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
140
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
141
        $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
 
142
        $authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
 
143
        $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
 
144
                                          $username = $user,
 
145
                                          $password = $pass,
 
146
                                          $service = $service,
 
147
                                          $client = null,
 
148
                                          $source = 'Google-UnitTests-1.0',
 
149
                                          $loginToken = null,
 
150
                                          $loginCaptcha = null,
 
151
                                          $authenticationURL);
 
152
 
 
153
        $this->gdata = new Zend_Gdata_YouTube($httpClient,
 
154
            'Google-UnitTests-1.0', 'ytapi-gdataops-12345-u78960r7-0',
 
155
            'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7Eyu1IuvkioESq' .
 
156
            'zRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
 
157
 
 
158
        $this->gdata->setMajorProtocolVersion(2);
 
159
        $feed = $this->gdata->getPlaylistListFeed($this->ytAccount);
 
160
        $this->assertTrue($feed->totalResults->text > 0);
 
161
        $this->assertEquals('Playlists of ' . $this->ytAccount,
 
162
            $feed->title->text);
 
163
        $this->assertTrue(count($feed->entry) > 0);
 
164
        $i = 0;
 
165
        foreach ($feed->entry as $entry) {
 
166
            $this->assertTrue($entry->title->text != '');
 
167
            if ($i == 0) {
 
168
                $entry->title->setText('new playlist title');
 
169
                $entry->save();
 
170
            }
 
171
            $i++;
 
172
        }
 
173
    }
 
174
 
 
175
    public function testRetrievePlaylistV2()
 
176
    {
 
177
      $this->gdata->setMajorProtocolVersion(2);
 
178
      $feed = $this->gdata->getPlaylistListFeed($this->ytAccount);
 
179
      $firstEntry = $feed->entries[0];
 
180
      $this->assertTrue($firstEntry instanceof Zend_Gdata_YouTube_PlaylistListEntry);
 
181
      $this->assertTrue($firstEntry->getSummary()->text != null);                  
 
182
    }
 
183
 
 
184
    public function testRetrievePlaylistVideoFeed()
 
185
    {
 
186
        $listFeed = $this->gdata->getPlaylistListFeed($this->ytAccount);
 
187
 
 
188
        $feed = $this->gdata->getPlaylistVideoFeed($listFeed->entry[0]->feedLink[0]->href);
 
189
        $this->assertTrue($feed->totalResults->text > 0);
 
190
        $this->assertTrue(count($feed->entry) > 0);
 
191
        foreach ($feed->entry as $entry) {
 
192
            $this->assertTrue($entry->title->text != '');
 
193
        }
 
194
    }
 
195
 
 
196
    public function testRetrieveTopRatedVideos()
 
197
    {
 
198
        $feed = $this->gdata->getTopRatedVideoFeed();
 
199
        $this->assertTrue($feed->totalResults->text > 10);
 
200
        $this->assertEquals('Top Rated', $feed->title->text);
 
201
        $this->assertTrue(count($feed->entry) > 0);
 
202
        foreach ($feed->entry as $entry) {
 
203
            $this->assertTrue($entry->rating->average > 3);
 
204
            $this->assertEquals(1, $entry->rating->min);
 
205
            $this->assertEquals(5, $entry->rating->max);
 
206
            $this->assertTrue($entry->rating->numRaters > 2);
 
207
        }
 
208
    }
 
209
 
 
210
    public function testRetrieveTopRatedVideosV2()
 
211
    {
 
212
        $this->gdata->setMajorProtocolVersion(2);
 
213
        $feed = $this->gdata->getTopRatedVideoFeed();
 
214
        $client = $this->gdata->getHttpClient();
 
215
        $positionOfAPIProjection = strpos(
 
216
            $client->getLastRequest(), "/feeds/api/");
 
217
        $this->assertTrue(is_numeric($positionOfAPIProjection));
 
218
    }
 
219
 
 
220
    public function testRetrieveMostViewedVideosV2()
 
221
    {
 
222
        $this->gdata->setMajorProtocolVersion(2);
 
223
        $feed = $this->gdata->getMostViewedVideoFeed();
 
224
        $client = $this->gdata->getHttpClient();
 
225
        $positionOfAPIProjection = strpos(
 
226
            $client->getLastRequest(), "/feeds/api/");
 
227
        $this->assertTrue(is_numeric($positionOfAPIProjection));
 
228
    }
 
229
 
 
230
    public function testRetrieveRecentlyFeaturedVideosV2()
 
231
    {
 
232
        $this->gdata->setMajorProtocolVersion(2);
 
233
        $feed = $this->gdata->getRecentlyFeaturedVideoFeed();
 
234
        $client = $this->gdata->getHttpClient();
 
235
        $positionOfAPIProjection = strpos(
 
236
            $client->getLastRequest(), "/feeds/api/");
 
237
        $this->assertTrue(is_numeric($positionOfAPIProjection));
 
238
    }
 
239
 
 
240
    public function testWatchOnMobileVideosV2()
 
241
    {
 
242
        $this->gdata->setMajorProtocolVersion(2);
 
243
        $feed = $this->gdata->getWatchOnMobileVideoFeed();
 
244
        $client = $this->gdata->getHttpClient();
 
245
        $positionOfAPIProjection = strpos(
 
246
            $client->getLastRequest(), "/feeds/api/");
 
247
        $this->assertTrue(is_numeric($positionOfAPIProjection));
 
248
    }
 
249
 
 
250
    public function testRetrieveMostViewedVideos()
 
251
    {
 
252
        $feed = $this->gdata->getMostViewedVideoFeed();
 
253
        $this->assertTrue($feed->totalResults->text > 10);
 
254
        $this->assertEquals('Most Viewed', $feed->title->text);
 
255
        $this->assertTrue(count($feed->entry) > 0);
 
256
        foreach ($feed->entry as $entry) {
 
257
            if ($entry->rating) {
 
258
                $this->assertEquals(1, $entry->rating->min);
 
259
                $this->assertEquals(5, $entry->rating->max);
 
260
            }
 
261
        }
 
262
    }
 
263
    
 
264
    public function testPerformV2Query_Location()
 
265
    {
 
266
        $this->gdata->setMajorProtocolVersion(2);
 
267
        $query = $this->gdata->newVideoQuery();
 
268
        // Setting location to New York City
 
269
        $query->setLocation('-37.0625,-95.677068');
 
270
        $query->setLocationRadius('1000km');
 
271
        $videoFeed = $this->gdata->getVideoFeed($query);
 
272
        $this->assertTrue(count($videoFeed->entry) > 0,
 
273
            'Could not retrieve a single entry for location search:' .
 
274
            $query->getQueryUrl(2));
 
275
    }
 
276
    
 
277
    public function testPerformV2Query_SafeSearch()
 
278
    {
 
279
        $this->gdata->setMajorProtocolVersion(2);
 
280
        $query = $this->gdata->newVideoQuery();
 
281
        $query->setSafeSearch('strict');
 
282
        $videoFeed = $this->gdata->getVideoFeed($query);
 
283
        $this->assertTrue(count($videoFeed->entry) > 0,
 
284
            'Could not retrieve a single entry for safeSearch=strict search:' .
 
285
            $query->getQueryUrl(2));
 
286
    }
 
287
 
 
288
    public function testPeformV2Query_Uploader()
 
289
    {
 
290
        $this->gdata->setMajorProtocolVersion(2);
 
291
        $query = $this->gdata->newVideoQuery();
 
292
        $query->setUploader('partner');
 
293
        $videoFeed = $this->gdata->getVideoFeed($query);
 
294
        $this->assertTrue(count($videoFeed->entry) > 0,
 
295
            'Could not retrieve a single entry for uploader=partner search:' .
 
296
            $query->getQueryUrl(2));
 
297
 
 
298
        foreach($videoFeed as $videoEntry) {
 
299
            $mg = $videoEntry->getMediaGroup();
 
300
            $this->assertEquals('partner',
 
301
                $mg->getMediaCredit()->getYTtype());
 
302
        }
 
303
    }
 
304
    
 
305
    public function testAddUpdateAndDeletePlaylistV2()
 
306
    {
 
307
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
308
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
309
        $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
 
310
        $authenticationURL =
 
311
            'https://www.google.com/youtube/accounts/ClientLogin';
 
312
        $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
 
313
                                          $username = $user,
 
314
                                          $password = $pass,
 
315
                                          $service = $service,
 
316
                                          $client = null,
 
317
                                          $source = 'Google-UnitTests-1.0',
 
318
                                          $loginToken = null,
 
319
                                          $loginCaptcha = null,
 
320
                                          $authenticationURL);
 
321
 
 
322
        $yt = new Zend_Gdata_YouTube(
 
323
            $httpClient, 'Google-UnitTests-1.0',
 
324
            'ytapi-gdataops-12345-u78960r7-0',
 
325
            'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7E' . 
 
326
            'yu1IuvkioESqzRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
 
327
 
 
328
        $yt->setMajorProtocolVersion(2);
 
329
        $feed = $yt->getPlaylistListFeed($this->ytAccount);
 
330
 
 
331
        // Add new
 
332
        $newPlaylist = $yt->newPlaylistListEntry();
 
333
        $newPlaylist->setMajorProtocolVersion(2);
 
334
        $titleString = $this->generateRandomString(10);
 
335
        $newPlaylist->title = $yt->newTitle()->setText($titleString);
 
336
        $newPlaylist->summary = $yt->newSummary()->setText('testing');
 
337
        $postUrl = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
 
338
        $successfulInsertion = true;
 
339
 
 
340
        try {
 
341
            $yt->insertEntry($newPlaylist, $postUrl);
 
342
        } catch (Zend_Gdata_App_Exception $e) {
 
343
            $successfulInsertion = false;
 
344
        }
 
345
        
 
346
        $this->assertTrue($successfulInsertion, 'Failed to insert a new ' .
 
347
            'playlist.');
 
348
 
 
349
        $playlistListFeed = $yt->getPlaylistListFeed('default');
 
350
 
 
351
        $playlistFound = false;
 
352
        $newPlaylistEntry = null;
 
353
 
 
354
        foreach ($playlistListFeed as $playlistListEntry) {
 
355
            if ($playlistListEntry->title->text == $titleString) {
 
356
                $playlistFound = true;
 
357
                $newPlaylistEntry = $playlistListEntry;
 
358
                break;
 
359
            }
 
360
        }
 
361
        
 
362
        $this->assertTrue($playlistFound, 'Could not find the newly inserted ' .
 
363
            'playlist.');
 
364
 
 
365
        // Update it
 
366
        $newTitle = $this->generateRandomString(10);
 
367
        $newPlaylistEntry->title->setText($newTitle);
 
368
        $updatedSuccesfully = true;
 
369
        try {
 
370
            $newPlaylistEntry->save();
 
371
        } catch (Zend_Gdata_App_Exception $e) {
 
372
            $updatedSuccesfully = false;
 
373
        }
 
374
        
 
375
        $this->assertTrue($updatedSuccesfully, 'Could not succesfully update ' .
 
376
            'a new playlist.');
 
377
        
 
378
        // Delete it
 
379
        $deletedSuccesfully = true;
 
380
        try {
 
381
            $newPlaylistEntry->delete();
 
382
        } catch (Zend_Gdata_App_Exception $e) {
 
383
            $deletedSuccesfully = false;
 
384
        }
 
385
 
 
386
        $this->assertTrue($deletedSuccesfully, 'Could not succesfully delete ' .
 
387
            'a new playlist.');
 
388
    }
 
389
    
 
390
    public function testAddAndDeleteSubscriptionToChannelV2()
 
391
    {
 
392
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
393
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
394
        $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
 
395
        $authenticationURL =
 
396
            'https://www.google.com/youtube/accounts/ClientLogin';
 
397
        $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
 
398
                                          $username = $user,
 
399
                                          $password = $pass,
 
400
                                          $service = $service,
 
401
                                          $client = null,
 
402
                                          $source = 'Google-UnitTests-1.0',
 
403
                                          $loginToken = null,
 
404
                                          $loginCaptcha = null,
 
405
                                          $authenticationURL);
 
406
 
 
407
        $yt = new Zend_Gdata_YouTube(
 
408
            $httpClient, 'Google-UnitTests-1.0',
 
409
            'ytapi-gdataops-12345-u78960r7-0',
 
410
            'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7E' . 
 
411
            'yu1IuvkioESqzRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
 
412
 
 
413
        $yt->setMajorProtocolVersion(2);
 
414
 
 
415
        $channelToSubscribeTo = 'AssociatedPress';
 
416
 
 
417
        // Test for deletion first in case something went wrong
 
418
        // last time the test was run (network, etc...)
 
419
        $subscriptionFeed = $yt->getSubscriptionFeed($this->ytAccount);
 
420
        $successDeletionUpFront = true;
 
421
        $message = null;
 
422
        foreach($subscriptionFeed as $subscriptionEntry) {
 
423
            $subscriptionType = null;
 
424
            $categories = $subscriptionEntry->getCategory();
 
425
            // examine the correct category element since there are multiple
 
426
            foreach($categories as $category) {
 
427
                if ($category->getScheme() ==
 
428
                    'http://gdata.youtube.com/schemas/2007/' . 
 
429
                    'subscriptiontypes.cat') {
 
430
                        $subscriptionType = $category->getTerm();
 
431
                    }
 
432
            }
 
433
            if ($subscriptionType == 'channel') {
 
434
                if ($subscriptionEntry->getUsername()->text ==
 
435
                    $channelToSubscribeTo) {
 
436
                    try {
 
437
                        $subscriptionEntry->delete();
 
438
                    } catch (Zend_App_Exception $e) {
 
439
                        $message = $e->getMessage();
 
440
                        $successDeletionUpFront = false;
 
441
                    }
 
442
                }
 
443
            }
 
444
        }
 
445
        $this->assertTrue($successDeletionUpFront, 'Found existing ' .
 
446
            'subscription in unit test, could not delete prior to running ' . 
 
447
            'test -- ' . $message);
 
448
 
 
449
        // Channel
 
450
        $newSubscription = $yt->newSubscriptionEntry();
 
451
        $newSubscription->category = array(
 
452
            $yt->newCategory('channel',
 
453
            $this->subscriptionTypeSchema));
 
454
        $newSubscription->setUsername($yt->newUsername(
 
455
            $channelToSubscribeTo));
 
456
        
 
457
        $postUrl =
 
458
            'http://gdata.youtube.com/feeds/api/users/default/subscriptions';
 
459
 
 
460
        $successPosting = true;
 
461
        $message = null;
 
462
        $insertedSubscription = null;
 
463
        try {
 
464
            $insertedSubscription = $yt->insertEntry(
 
465
                $newSubscription, $postUrl,
 
466
                'Zend_Gdata_YouTube_SubscriptionEntry');
 
467
        } catch (Zend_App_Exception $e) {
 
468
            $message = $e->getMessage();
 
469
            $successPosting = false;
 
470
        }
 
471
 
 
472
        $this->assertTrue($successPosting, $message);
 
473
 
 
474
        // Delete it
 
475
        $successDeletion = true;
 
476
        $message = null;
 
477
        try {
 
478
            $insertedSubscription->delete();
 
479
        } catch (Zend_App_Exception $e) {
 
480
            $message = $e->getMessage();
 
481
            $successDeletion = false;
 
482
        }
 
483
 
 
484
        $this->assertTrue($successDeletion, $message);
 
485
    }
 
486
 
 
487
    public function testAddAndDeleteSubscriptionToFavoritesV2()
 
488
    {
 
489
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
490
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
491
        $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
 
492
        $authenticationURL =
 
493
            'https://www.google.com/youtube/accounts/ClientLogin';
 
494
        $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
 
495
                                          $username = $user,
 
496
                                          $password = $pass,
 
497
                                          $service = $service,
 
498
                                          $client = null,
 
499
                                          $source = 'Google-UnitTests-1.0',
 
500
                                          $loginToken = null,
 
501
                                          $loginCaptcha = null,
 
502
                                          $authenticationURL);
 
503
 
 
504
        $yt = new Zend_Gdata_YouTube(
 
505
            $httpClient, 'Google-UnitTests-1.0',
 
506
            'ytapi-gdataops-12345-u78960r7-0',
 
507
            'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7E' . 
 
508
            'yu1IuvkioESqzRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
 
509
 
 
510
        $yt->setMajorProtocolVersion(2);
 
511
        
 
512
        $usernameOfFavoritesToSubscribeTo = 'CBS';
 
513
        
 
514
        // Test for deletion first in case something went wrong
 
515
        // last time the test was run (network, etc...)
 
516
        $subscriptionFeed = $yt->getSubscriptionFeed($this->ytAccount);
 
517
        $successDeletionUpFront = true;
 
518
        $message = null;
 
519
        foreach($subscriptionFeed as $subscriptionEntry) {
 
520
            $subscriptionType = null;
 
521
            $categories = $subscriptionEntry->getCategory();
 
522
            // examine the correct category element since there are multiple
 
523
            foreach($categories as $category) {
 
524
                if ($category->getScheme() ==
 
525
                    'http://gdata.youtube.com/schemas/2007/' . 
 
526
                    'subscriptiontypes.cat') {
 
527
                        $subscriptionType = $category->getTerm();
 
528
                    }
 
529
            }
 
530
            if ($subscriptionType == 'favorites') {
 
531
                if ($subscriptionEntry->getUsername()->text ==
 
532
                    $usernameOfFavoritesToSubscribeTo) {
 
533
                    try {
 
534
                        $subscriptionEntry->delete();
 
535
                    } catch (Zend_App_Exception $e) {
 
536
                        $message = $e->getMessage();
 
537
                        $successDeletionUpFront = false;
 
538
                    }
 
539
                }
 
540
            }
 
541
        }
 
542
        $this->assertTrue($successDeletionUpFront, 'Found existing ' .
 
543
            'subscription in unit test, could not delete prior to running ' . 
 
544
            'test -- ' . $message);
 
545
 
 
546
        // CBS's favorites
 
547
        $newSubscription = $yt->newSubscriptionEntry();
 
548
        $newSubscription->category = array(
 
549
            $yt->newCategory('favorites',
 
550
            $this->subscriptionTypeSchema));
 
551
        $newSubscription->setUsername($yt->newUsername(
 
552
            $usernameOfFavoritesToSubscribeTo));
 
553
        
 
554
        $postUrl =
 
555
            'http://gdata.youtube.com/feeds/api/users/default/subscriptions';
 
556
 
 
557
        $successPosting = true;
 
558
        $message = null;
 
559
        $insertedSubscription = null;
 
560
        try {
 
561
            $insertedSubscription = $yt->insertEntry(
 
562
                $newSubscription, $postUrl,
 
563
                'Zend_Gdata_YouTube_SubscriptionEntry');
 
564
        } catch (Zend_App_Exception $e) {
 
565
            $message = $e->getMessage();
 
566
            $successPosting = false;
 
567
        }
 
568
        
 
569
        $this->assertTrue($successPosting, $message);
 
570
 
 
571
        // Delete it
 
572
        $successDeletion = true;
 
573
        $message = null;
 
574
        try {
 
575
            $insertedSubscription->delete();
 
576
        } catch (Zend_App_Exception $e) {
 
577
            $message = $e->getMessage();
 
578
            $successDeletion = false;
 
579
        }
 
580
 
 
581
        $this->assertTrue($successDeletion, $message);
 
582
    }
 
583
    
 
584
    public function testAddAndDeleteSubscriptionToPlaylistV2()
 
585
    {
 
586
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
587
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
588
        $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
 
589
        $authenticationURL =
 
590
            'https://www.google.com/youtube/accounts/ClientLogin';
 
591
        $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
 
592
                                          $username = $user,
 
593
                                          $password = $pass,
 
594
                                          $service = $service,
 
595
                                          $client = null,
 
596
                                          $source = 'Google-UnitTests-1.0',
 
597
                                          $loginToken = null,
 
598
                                          $loginCaptcha = null,
 
599
                                          $authenticationURL);
 
600
 
 
601
        $yt = new Zend_Gdata_YouTube(
 
602
            $httpClient, 'Google-UnitTests-1.0',
 
603
            'ytapi-gdataops-12345-u78960r7-0',
 
604
            'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7E' . 
 
605
            'yu1IuvkioESqzRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
 
606
 
 
607
        $yt->setMajorProtocolVersion(2);
 
608
        $playlistIdToSubscribeTo = '7A2BB4AFFEBED2A4';
 
609
        
 
610
        // Test for deletion first in case something went wrong
 
611
        // last time the test was run (network, etc...)
 
612
        $subscriptionFeed = $yt->getSubscriptionFeed($this->ytAccount);
 
613
        $successDeletionUpFront = true;
 
614
        $message = null;
 
615
        foreach($subscriptionFeed as $subscriptionEntry) {
 
616
            $subscriptionType = null;
 
617
            $categories = $subscriptionEntry->getCategory();
 
618
            // examine the correct category element since there are multiple
 
619
            foreach($categories as $category) {
 
620
                if ($category->getScheme() ==
 
621
                    'http://gdata.youtube.com/schemas/2007/' . 
 
622
                    'subscriptiontypes.cat') {
 
623
                        $subscriptionType = $category->getTerm();
 
624
                    }
 
625
            }
 
626
            if ($subscriptionType == 'playlist') {
 
627
                if ($subscriptionEntry->getPlaylistId()->text ==
 
628
                    $playlistIdToSubscribeTo) {
 
629
                    try {
 
630
                        $subscriptionEntry->delete();
 
631
                    } catch (Zend_App_Exception $e) {
 
632
                        $message = $e->getMessage();
 
633
                        $successDeletionUpFront = false;
 
634
                    }
 
635
                }
 
636
            }
 
637
        }
 
638
        $this->assertTrue($successDeletionUpFront, 'Found existing ' .
 
639
            'subscription in unit test, could not delete prior to running ' . 
 
640
            'test -- ' . $message);
 
641
 
 
642
        // Playlist of McGyver videos
 
643
        $newSubscription = $yt->newSubscriptionEntry();
 
644
        $newSubscription->setMajorProtocolVersion(2);
 
645
        $newSubscription->category = array(
 
646
            $yt->newCategory('playlist',
 
647
            $this->subscriptionTypeSchema));
 
648
        $newSubscription->setPlaylistId($yt->newPlaylistId(
 
649
            $playlistIdToSubscribeTo));
 
650
        
 
651
        $postUrl =
 
652
            'http://gdata.youtube.com/feeds/api/users/default/subscriptions';
 
653
 
 
654
        $successPosting = true;
 
655
        $message = null;
 
656
        $insertedSubscription = null;
 
657
        try {
 
658
            $insertedSubscription = $yt->insertEntry(
 
659
                $newSubscription, $postUrl,
 
660
                'Zend_Gdata_YouTube_SubscriptionEntry');
 
661
        } catch (Zend_App_Exception $e) {
 
662
            $message = $e->getMessage();
 
663
            $successPosting = false;
 
664
        }
 
665
        
 
666
        $this->assertTrue($successPosting, $message);
 
667
 
 
668
        // Delete it
 
669
        $successDeletion = true;
 
670
        $message = null;
 
671
        try {
 
672
            $insertedSubscription->delete();
 
673
        } catch (Zend_App_Exception $e) {
 
674
            $message = $e->getMessage();
 
675
            $successDeletion = false;
 
676
        }
 
677
 
 
678
        $this->assertTrue($successDeletion, $message);
 
679
    }
 
680
 
 
681
    public function testAddAndDeleteSubscriptionToQueryV2()
 
682
    {
 
683
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
684
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
685
        $developerKey = constant('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
 
686
        $clientId = constant('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
 
687
 
 
688
        $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
 
689
        $authenticationURL =
 
690
            'https://www.google.com/youtube/accounts/ClientLogin';
 
691
        $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
 
692
                                          $username = $user,
 
693
                                          $password = $pass,
 
694
                                          $service = $service,
 
695
                                          $client = null,
 
696
                                          $source = 'Google-UnitTests-1.0',
 
697
                                          $loginToken = null,
 
698
                                          $loginCaptcha = null,
 
699
                                          $authenticationURL);
 
700
 
 
701
        $yt = new Zend_Gdata_YouTube($httpClient, $clientId, $developerKey);
 
702
 
 
703
        $yt->setMajorProtocolVersion(2);
 
704
        $queryStringToSubscribeTo = 'zend';
 
705
        
 
706
        // Test for deletion first in case something went wrong
 
707
        // last time the test was run (network, etc...)
 
708
        $subscriptionFeed = $yt->getSubscriptionFeed($this->ytAccount);
 
709
        $successDeletionUpFront = true;
 
710
        $message = null;
 
711
        foreach($subscriptionFeed as $subscriptionEntry) {
 
712
            $subscriptionType = null;
 
713
            $categories = $subscriptionEntry->getCategory();
 
714
            // examine the correct category element since there are multiple
 
715
            foreach($categories as $category) {
 
716
                if ($category->getScheme() ==
 
717
                    'http://gdata.youtube.com/schemas/2007/' . 
 
718
                    'subscriptiontypes.cat') {
 
719
                        $subscriptionType = $category->getTerm();
 
720
                    }
 
721
            }
 
722
            if ($subscriptionType == 'query') {
 
723
                if ($subscriptionEntry->getQueryString() ==
 
724
                    $queryStringToSubscribeTo) {
 
725
                    try {
 
726
                        $subscriptionEntry->delete();
 
727
                    } catch (Zend_App_Exception $e) {
 
728
                        $message = $e->getMessage();
 
729
                        $successDeletionUpFront = false;
 
730
                    }
 
731
                }
 
732
            }
 
733
        }
 
734
        $this->assertTrue($successDeletionUpFront, 'Found existing ' .
 
735
            'subscription in unit test, could not delete prior to running ' . 
 
736
            'test -- ' . $message);
 
737
 
 
738
        // Query
 
739
        $newSubscription = $yt->newSubscriptionEntry();
 
740
        $newSubscription->category = array(
 
741
            $yt->newCategory('query',
 
742
            $this->subscriptionTypeSchema));
 
743
        $newSubscription->setQueryString($yt->newQueryString(
 
744
            $queryStringToSubscribeTo));
 
745
        
 
746
        $postUrl =
 
747
            'http://gdata.youtube.com/feeds/api/users/default/subscriptions';
 
748
 
 
749
        $successPosting = true;
 
750
        $message = null;
 
751
        $insertedSubscription = null;
 
752
        try {
 
753
            $insertedSubscription = $yt->insertEntry(
 
754
                $newSubscription, $postUrl,
 
755
                'Zend_Gdata_YouTube_SubscriptionEntry');
 
756
        } catch (Zend_App_Exception $e) {
 
757
            $message = $e->getMessage();
 
758
            $successPosting = false;
 
759
        }
 
760
        
 
761
        $this->assertTrue($successPosting, $message);
 
762
 
 
763
        // Delete it
 
764
        $successDeletion = true;
 
765
        $message = null;
 
766
        try {
 
767
            $insertedSubscription->delete();
 
768
        } catch (Zend_App_Exception $e) {
 
769
            $message = $e->getMessage();
 
770
            $successDeletion = false;
 
771
        }
 
772
 
 
773
        $this->assertTrue($successDeletion, $message);
 
774
    }
 
775
 
 
776
    public function generateRandomString($length)
 
777
    {
 
778
        $outputString = null;
 
779
        for($i = 0; $i < $length; $i++) {
 
780
            $outputString .= chr(rand(65,90));
 
781
        }
 
782
        return $outputString;
 
783
    }
 
784
 
 
785
    public function testRetrieveActivityFeed()
 
786
    {
 
787
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
788
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
789
        $developerKey = constant(
 
790
            'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
 
791
        $clientId = constant(
 
792
            'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
 
793
        $client = Zend_Gdata_ClientLogin::getHttpClient(
 
794
            $user, $pass, 'youtube' , null, 'ZF_UnitTest', null, null,
 
795
            'https://www.google.com/youtube/accounts/ClientLogin');
 
796
 
 
797
        $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
 
798
            $clientId, $developerKey);
 
799
        $youtube->setMajorProtocolVersion(2);
 
800
 
 
801
        $feed = $youtube->getActivityForUser($this->ytAccount);
 
802
        $this->assertTrue($feed instanceof Zend_Gdata_YouTube_ActivityFeed);
 
803
        $this->assertTrue((count($feed->entries) > 0));
 
804
        $this->assertEquals('Activity of ' . $this->ytAccount,
 
805
            $feed->title->text);
 
806
    }
 
807
 
 
808
    public function testExceptionIfNotUsingDeveloperKey()
 
809
    {
 
810
        $exceptionThrown = false;
 
811
        $youtube = new Zend_Gdata_YouTube();
 
812
        $youtube->setMajorProtocolVersion(2);
 
813
        try {
 
814
            $youtube->getActivityForUser($this->ytAccount);
 
815
        } catch (Zend_Gdata_App_HttpException $e) {
 
816
            $exceptionThrown = true;
 
817
        }
 
818
        $this->assertTrue($exceptionThrown, 'Was expecting an exception when ' .
 
819
            'making a request to the YouTube Activity feed without a ' . 
 
820
            'developer key.');
 
821
    }
 
822
    
 
823
    public function testRetrieveActivityFeedForMultipleUsers()
 
824
    {
 
825
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
826
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
827
        $developerKey = constant(
 
828
            'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
 
829
        $clientId = constant(
 
830
            'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
 
831
        $client = Zend_Gdata_ClientLogin::getHttpClient(
 
832
            $user, $pass, 'youtube' , null, 'ZF_UnitTest', null, null,
 
833
            'https://www.google.com/youtube/accounts/ClientLogin');
 
834
 
 
835
        $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
 
836
            $clientId, $developerKey);
 
837
        $youtube->setMajorProtocolVersion(2);
 
838
 
 
839
        $feed = $youtube->getActivityForUser($this->ytAccount .
 
840
            ',associatedpress');
 
841
        $this->assertTrue($feed instanceof Zend_Gdata_YouTube_ActivityFeed);
 
842
        $this->assertTrue((count($feed->entries) > 0));
 
843
        $this->assertEquals('Activity of ' . $this->ytAccount .
 
844
            ',associatedpress', $feed->title->text);
 
845
    }
 
846
    
 
847
    public function testRetrieveFriendFeed()
 
848
    {
 
849
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
850
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
851
        $developerKey = constant(
 
852
            'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
 
853
        $clientId = constant(
 
854
            'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
 
855
        $client = Zend_Gdata_ClientLogin::getHttpClient(
 
856
            $user, $pass, 'youtube' , null, 'ZF_UnitTest', null, null,
 
857
            'https://www.google.com/youtube/accounts/ClientLogin');
 
858
 
 
859
        $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
 
860
            $clientId, $developerKey);
 
861
        $youtube->setMajorProtocolVersion(2);
 
862
 
 
863
        $feed = $youtube->getFriendActivityForCurrentUser();
 
864
        $this->assertTrue($feed instanceof Zend_Gdata_YouTube_ActivityFeed);
 
865
        $this->assertTrue((count($feed->entries) > 0));
 
866
        $this->assertEquals('Activity of the friends of ' . $this->ytAccount,
 
867
            $feed->title->text);
 
868
    }
 
869
 
 
870
   public function testThrowExceptionOnActivityFeedRequestForMoreThan20Users()
 
871
   {
 
872
        $exceptionThrown = false;
 
873
        $listOfMoreThan20Users = null;
 
874
        $youtube = new Zend_Gdata_YouTube();
 
875
        $youtube->setMajorProtocolVersion(2);
 
876
 
 
877
        for ($x = 0;  $x < 30; $x++) {
 
878
            $listOfMoreThan20Users .= "user$x";
 
879
            if ($x != 29) {
 
880
                $listOfMoreThan20Users .= ",";
 
881
            }
 
882
        }
 
883
 
 
884
        try {
 
885
            $youtube->getActivityForUser($listOfMoreThan20Users);
 
886
        } catch (Zend_Gdata_App_InvalidArgumentException $e) {
 
887
            $exceptionThrown = true;
 
888
        }
 
889
        $this->assertTrue($exceptionThrown, 'Was expecting an exception on ' .
 
890
            'a request to ->getActivityForUser when more than 20 users were ' .
 
891
            'specified in YouTube.php');
 
892
    }
 
893
 
 
894
    public function testGetInboxFeedForCurrentUserV1()
 
895
    {
 
896
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
897
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
898
        $developerKey = constant(
 
899
            'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
 
900
        $clientId = constant(
 
901
            'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
 
902
        $client = Zend_Gdata_ClientLogin::getHttpClient(
 
903
            $user, $pass, 'youtube' , null, 'ZF_UnitTest', null, null,
 
904
            'https://www.google.com/youtube/accounts/ClientLogin');
 
905
 
 
906
        $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
 
907
            $clientId, $developerKey);
 
908
        
 
909
        $inboxFeed = $youtube->getInboxFeedForCurrentUser();
 
910
        $this->assertTrue($inboxFeed instanceof Zend_Gdata_YouTube_InboxFeed);
 
911
        $this->assertTrue(count($inboxFeed->entries) > 0, 'Test account ' .
 
912
            $this->ytAccount . ' had no messages in their inbox.');
 
913
        
 
914
        // get the first entry
 
915
        $inboxFeed->rewind();
 
916
        $inboxEntry = $inboxFeed->current();
 
917
        $this->assertTrue(
 
918
            $inboxEntry instanceof Zend_Gdata_YouTube_InboxEntry);
 
919
        $this->assertTrue($inboxEntry->getTitle()->text != '');
 
920
    }
 
921
 
 
922
    public function testGetInboxFeedForCurrentUserV2()
 
923
    {
 
924
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
925
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
926
        $developerKey = constant(
 
927
            'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
 
928
        $clientId = constant(
 
929
            'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
 
930
        $client = Zend_Gdata_ClientLogin::getHttpClient(
 
931
            $user, $pass, 'youtube' , null, 'ZF_UnitTest', null, null,
 
932
            'https://www.google.com/youtube/accounts/ClientLogin');
 
933
 
 
934
        $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
 
935
            $clientId, $developerKey);
 
936
        $youtube->setMajorProtocolVersion(2);
 
937
        
 
938
        $inboxFeed = $youtube->getInboxFeedForCurrentUser();
 
939
        $this->assertTrue($inboxFeed instanceof Zend_Gdata_YouTube_InboxFeed);
 
940
        $this->assertTrue(count($inboxFeed->entries) > 0, 'Test account ' .
 
941
            $this->ytAccount . ' had no messages in their inbox.');
 
942
     
 
943
        // get the first entry
 
944
        $inboxFeed->rewind();
 
945
        $inboxEntry = $inboxFeed->current();
 
946
        $this->assertTrue(
 
947
            $inboxEntry instanceof Zend_Gdata_YouTube_InboxEntry);
 
948
        $this->assertTrue($inboxEntry->getTitle()->text != '');
 
949
    }
 
950
 
 
951
    
 
952
    public function testSendAMessageV2()
 
953
    {
 
954
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
955
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
956
        $developerKey = constant('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
 
957
        $clientId = constant('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
 
958
        $client = Zend_Gdata_ClientLogin::getHttpClient(
 
959
            $user, $pass, 'youtube' , null, 'ZF_UnitTest', null, null,
 
960
            'https://www.google.com/youtube/accounts/ClientLogin');
 
961
 
 
962
        $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
 
963
            $clientId, $developerKey);
 
964
        $youtube->setMajorProtocolVersion(2);
 
965
 
 
966
        // get a video from the recently featured video feed
 
967
        $videoFeed = $youtube->getRecentlyFeaturedVideoFeed();
 
968
        $videoEntry = $videoFeed->entry[0];
 
969
        $this->assertTrue($videoEntry instanceof Zend_Gdata_YouTube_VideoEntry);
 
970
 
 
971
        // sending message to gdpython (python client library unit test user)
 
972
        $sentMessage = $youtube->sendVideoMessage(
 
973
            'Sending a v2 test message from Zend_Gdata_YouTubeOnlineTest.',
 
974
            $videoEntry, null, 'gdpython');
 
975
        $this->assertTrue(
 
976
            $sentMessage instanceof Zend_Gdata_YouTube_InboxEntry);
 
977
    }
 
978
 
 
979
    public function testSendAMessageV1()
 
980
    {
 
981
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
982
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
983
        $developerKey = constant(
 
984
            'TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
 
985
        $clientId = constant(
 
986
            'TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
 
987
        $client = Zend_Gdata_ClientLogin::getHttpClient(
 
988
            $user, $pass, 'youtube' , null, 'ZF_UnitTest', null, null,
 
989
            'https://www.google.com/youtube/accounts/ClientLogin');
 
990
 
 
991
        $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
 
992
            $clientId, $developerKey);
 
993
        $youtube->setMajorProtocolVersion(1);
 
994
 
 
995
        // get a video from the recently featured video feed
 
996
        $videoFeed = $youtube->getRecentlyFeaturedVideoFeed();
 
997
        $videoEntry = $videoFeed->entry[0];
 
998
        $this->assertTrue($videoEntry instanceof Zend_Gdata_YouTube_VideoEntry);
 
999
 
 
1000
        // sending message to gdpython (python client library unit test user)
 
1001
        $sentMessage = $youtube->sendVideoMessage(
 
1002
            'Sending a v1 test message from Zend_Gdata_YouTubeOnlineTest.',
 
1003
            $videoEntry, null, 'gdpython');
 
1004
        $this->assertTrue(
 
1005
            $sentMessage instanceof Zend_Gdata_YouTube_InboxEntry);
 
1006
    }
 
1007
 
 
1008
    public function testThrowExceptionOnSendingMessageWithoutVideo()
 
1009
    {
 
1010
        $exceptionCaught = false;
 
1011
        $this->gdata = new Zend_Gdata_YouTube();
 
1012
        try {
 
1013
            $this->gdata->sendVideoMessage('Should fail', null, null, 'foo');
 
1014
        } catch (Zend_Gdata_App_InvalidArgumentException $e) {
 
1015
            $exceptionCaught = true;
 
1016
        }
 
1017
        $this->assertTrue($exceptionCaught, 'Was expecting an exception if ' .
 
1018
            'sending a message without a video');
 
1019
    }
 
1020
    
 
1021
    public function testCommentOnAComment()
 
1022
    {
 
1023
        $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
 
1024
        $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
 
1025
        $developerKey = constant('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
 
1026
        $clientId = constant('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
 
1027
        $client = Zend_Gdata_ClientLogin::getHttpClient(
 
1028
            $user, $pass, 'youtube' , null, 'ZF_UnitTest', null, null,
 
1029
            'https://www.google.com/youtube/accounts/ClientLogin');
 
1030
        $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest',
 
1031
            $clientId, $developerKey);
 
1032
        $youtube->setMajorProtocolVersion(2);
 
1033
        
 
1034
        $mostDiscussedFeed = $youtube->getVideoFeed(
 
1035
            'http://gdata.youtube.com/feeds/api/standardfeeds/most_discussed');
 
1036
        
 
1037
        // get first entry
 
1038
        $mostDiscussedFeed->rewind();
 
1039
        $firstEntry = $mostDiscussedFeed->current();
 
1040
        
 
1041
        $this->assertTrue($firstEntry instanceof Zend_Gdata_YouTube_VideoEntry);
 
1042
        
 
1043
        $commentFeed = $youtube->getVideoCommentFeed($firstEntry->getVideoId());
 
1044
 
 
1045
        // get first comment
 
1046
        $commentFeed->rewind();
 
1047
        $firstCommentEntry = $commentFeed->current();
 
1048
        
 
1049
        $commentedComment = $youtube->replyToCommentEntry($firstCommentEntry,
 
1050
            'awesome ! (ZFUnitTest-test)');
 
1051
        $this->assertTrue(
 
1052
            $commentedComment instanceof Zend_Gdata_YouTube_CommentEntry);
 
1053
    }
 
1054
 
 
1055
}