| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <?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_Photos
- * @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/Photos.php';
- require_once 'Zend/Http/Client.php';
- require_once 'Zend/Http/Client/Adapter/Test.php';
- require_once 'Zend/Gdata/ClientLogin.php';
- require_once 'Zend/Gdata/App/InvalidArgumentException.php';
- /**
- * @category Zend
- * @package Zend_Gdata_Photos
- * @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_Photos
- */
- class Zend_Gdata_PhotosOnlineTest extends PHPUnit_Framework_TestCase
- {
- protected $photos = null;
- public function setUp()
- {
- $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
- $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
- $service = 'lh2';
- $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
- $this->photos = new Zend_Gdata_Photos($client);
- }
- /**
- * Verify that a given property is set to a specific value
- * and that the getter and magic variable return the same value.
- *
- * @param object $obj The object to be interrogated.
- * @param string $name The name of the property to be verified.
- * @param string $secondName 2nd level accessor function name
- * @param object $value The expected value of the property.
- */
- protected function verifyProperty($obj, $name, $secondName, $value)
- {
- $propName = $name;
- $propGetter = "get" . ucfirst($name);
- $secondGetter = "get" . ucfirst($secondName);
- $this->assertEquals($obj->$propGetter(), $obj->$propName);
- $this->assertEquals($value, $obj->$propGetter()->$secondGetter());
- }
- public function createAlbum()
- {
- $client = $this->photos;
- $album = new Zend_Gdata_Photos_AlbumEntry();
- $album->setTitle($client->newTitle("testAlbum"));
- $album->setCategory(array($client->newCategory(
- 'http://schemas.google.com/photos/2007#album',
- 'http://schemas.google.com/g/2005#kind')));
- $newAlbum = $client->insertAlbumEntry($album);
- $this->assertEquals($album->getTitle(), $newAlbum->getTitle());
- $this->assertEquals($newAlbum->getTitle(), $client->getAlbumEntry($newAlbum->getLink('self')->href)->getTitle());
- $albumFeedUri = $newAlbum->getLink('http://schemas.google.com/g/2005#feed')->href;
- $albumFeed = $client->getAlbumFeed($albumFeedUri);
- $this->verifyProperty($albumFeed, "title", "text", "testAlbum");
- return $newAlbum;
- }
- public function createPhoto($album)
- {
- $client = $this->photos;
- $fd = $client->newMediaFileSource('Zend/Gdata/_files/testImage.jpg');
- $fd->setContentType('image/jpeg');
- $photo = new Zend_Gdata_Photos_PhotoEntry();
- $photo->setMediaSource($fd);
- $photo->setTitle($client->newTitle("test photo"));
- $photo->setCategory(array($client->newCategory(
- 'http://schemas.google.com/photos/2007#photo',
- 'http://schemas.google.com/g/2005#kind')));
- $newPhoto = $client->insertPhotoEntry($photo, $album);
- $this->assertEquals($photo->getTitle(), $newPhoto->getTitle());
- $this->assertEquals($newPhoto->getTitle(), $client->getPhotoEntry($newPhoto->getLink('self')->href)->getTitle());
- $photoFeedUri = $newPhoto->getLink('http://schemas.google.com/g/2005#feed')->href;
- $photoFeed = $client->getPhotoFeed($photoFeedUri);
- $this->verifyProperty($photoFeed, "title", "text", "test photo");
- return $newPhoto;
- }
- public function updatePhotoMetaData()
- {
- $client = $this->photos;
- $album = $this->createAlbum();
- $insertedEntry = $this->createPhoto($album);
- $insertedEntry->title->text = "New Photo";
- $insertedEntry->summary->text = "Photo caption";
- $keywords = new Zend_Gdata_Media_Extension_MediaKeywords();
- $keywords->setText("foo, bar, baz");
- $insertedEntry->mediaGroup->keywords = $keywords;
- $updatedEntry = $insertedEntry->save();
- return array($updatedEntry, $album);
- }
- public function createComment($photo)
- {
- $client = $this->photos;
- $comment = new Zend_Gdata_Photos_CommentEntry();
- $comment->setTitle($client->newTitle("test comment"));
- $comment->setContent($client->newContent("test comment"));
- $comment->setCategory(array($client->newCategory(
- 'http://schemas.google.com/photos/2007#comment',
- 'http://schemas.google.com/g/2005#kind')));
- $newComment = $client->insertCommentEntry($comment, $photo);
- $this->assertEquals($comment->getContent(), $newComment->getContent());
- $this->assertEquals($newComment->getContent(), $client->getCommentEntry($newComment->getLink('self')->href)->getContent());
- return $newComment;
- }
- public function createTag($photo)
- {
- $client = $this->photos;
- $tag = new Zend_Gdata_Photos_TagEntry();
- $tag->setTitle($client->newTitle("test tag"));
- $tag->setContent($client->newContent("test tag"));
- $tag->setCategory(array($client->newCategory(
- 'http://schemas.google.com/photos/2007#tag',
- 'http://schemas.google.com/g/2005#kind')));
- $newTag = $client->insertTagEntry($tag, $photo);
- $this->assertEquals($tag->getTitle(), $newTag->getTitle());
- $this->assertEquals($newTag->getTitle(), $client->getTagEntry($newTag->getLink('self')->href)->getTitle());
- return $newTag;
- }
- public function testCreateAlbumAndUploadPhoto()
- {
- $client = $this->photos;
- $album = $this->createAlbum();
- $photo = $this->createPhoto($album);
- // Clean up the mess
- $client->deletePhotoEntry($photo, true);
- $client->deleteAlbumEntry($album, true);
- }
- public function testUpdatePhotoMetadata()
- {
- $client = $this->photos;
- $dataArray = $this->updatePhotoMetaData();
- $updatedPhoto = $dataArray[0];
- $album = $dataArray[1];
- $this->assertTrue($updatedPhoto instanceof Zend_Gdata_Photos_PhotoEntry);
- // Clean up the mess
- $client->deletePhotoEntry($updatedPhoto, true);
- $client->deleteAlbumEntry($album, true);
- }
- public function testUserFeedAndEntry()
- {
- $client = $this->photos;
- $userEntryUri = "http://picasaweb.google.com/data/entry/api/user/" .
- constant('TESTS_ZEND_GDATA_PHOTOS_USERNAME');
- $userEntry = $client->getUserEntry($userEntryUri);
- $this->verifyProperty($userEntry, "id", "text",
- "http://picasaweb.google.com/data/entry/api/user/" .
- constant('TESTS_ZEND_GDATA_PHOTOS_USERNAME'));
- $userFeed = $client->getUserFeed(constant('TESTS_ZEND_GDATA_PHOTOS_USERNAME'));
- $this->verifyProperty($userFeed, "id", "text",
- "http://picasaweb.google.com/data/feed/api/user/" .
- constant('TESTS_ZEND_GDATA_PHOTOS_USERNAME'));
- }
- public function testCreatePhotoCommentAndTag()
- {
- $client = $this->photos;
- $album = $this->createAlbum();
- $photo = $this->createPhoto($album);
- $comment = $this->createComment($photo);
- $tag = $this->createTag($photo);
- // Clean up the mess
- $client->deleteTagEntry($tag, true);
- $client->deleteCommentEntry($comment, true);
- $client->deletePhotoEntry($photo, true);
- $client->deleteAlbumEntry($album, true);
- }
- public function testInvalidEntryFetchingAndInserting()
- {
- $client = $this->photos;
- try {
- $userEntry = $client->getUserEntry(null);
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException);
- }
- try {
- $userEntry = $client->getAlbumEntry(null);
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException);
- }
- try {
- $photoEntry = $client->getPhotoEntry(null);
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException);
- }
- try {
- $tagEntry = $client->getTagEntry(null);
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException);
- }
- try {
- $commentEntry = $client->getCommentEntry(null);
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException);
- }
- try {
- $photo = new Zend_Gdata_Photos_PhotoEntry();
- $result = $client->insertPhotoEntry($photo, null);
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException);
- }
- try {
- $comment = new Zend_Gdata_Photos_CommentEntry();
- $result = $client->insertCommentEntry($comment, null);
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException);
- }
- try {
- $tag = new Zend_Gdata_Photos_TagEntry();
- $result = $client->insertTagEntry($tag, null);
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException);
- }
- }
- public function testInvalidFeedFetching()
- {
- $client = $this->photos;
- try {
- $albumFeed = $client->getAlbumFeed(null);
- } catch (Exception $e) {
- $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException);
- }
- }
- }
|