| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?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_Service_Delicious
- * @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$
- */
- /**
- * @see Zend_Service_Delicious
- */
- require_once 'Zend/Service/Delicious.php';
- /**
- * @category Zend_Service
- * @package Zend_Service_Delicious
- * @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_Service
- * @group Zend_Service_Delicious
- */
- class Zend_Service_Delicious_PrivateDataTest extends PHPUnit_Framework_TestCase
- {
- const TEST_UNAME = 'zfTestUser';
- const TEST_PASS = 'zfuser';
- private static $TEST_POST_TITLE = 'test - title';
- private static $TEST_POST_URL = 'http://zfdev.com/unittests/delicious/test_url_1';
- private static $TEST_POST_NOTES = 'test - note';
- private static $TEST_POST_TAGS = array('testTag1','testTag2');
- private static $TEST_POST_SHARED = false;
- /**
- * @var Zend_Service_Delicious
- */
- protected $_delicious;
- /**
- *
- * @return void
- */
- public function setUp()
- {
- $httpClient = new Zend_Http_Client();
- $httpClient->setConfig(array(
- 'useragent' => 'Zend_Service_Delicious - Unit tests/0.1',
- 'keepalive' => true
- ));
- Zend_Rest_Client::setHttpClient($httpClient);
- $this->_delicious = new Zend_Service_Delicious(self::TEST_UNAME, self::TEST_PASS);
- }
- /**
- *
- * @return void
- */
- public function testLastUpdate()
- {
- $this->assertTrue($this->_delicious->getLastUpdate() instanceof Zend_Date);
- }
- /**
- *
- * @return void
- */
- public function testTagsAndBundles()
- {
- // get tags
- $tags = $this->_delicious->getTags();
- $this->assertTrue(is_array($tags));
- $tags = array_keys($tags);
- if (count($tags) < 1) {
- $this->fail('Test account corrupted - no tags');
- }
- $oldTagName = $tags[0];
- $newTagName = uniqid('tag');
- // rename tag
- $this->_delicious->renameTag($oldTagName, $newTagName);
- sleep(15);
- // get renamed tags
- $tags = $this->_delicious->getTags();
- $this->assertArrayHasKey($newTagName, $tags);
- $this->assertArrayNotHasKey($oldTagName, $tags);
- $tags = array_keys($tags);
- // add new bundle
- $newBundleName = uniqid('bundle');
- $this->_delicious->addBundle($newBundleName, $tags);
- sleep(15);
- // check if bundle was added
- $bundles = $this->_delicious->getBundles();
- $this->assertTrue(is_array($bundles));
- $this->assertArrayHasKey($newBundleName, $bundles);
- $this->assertEquals($tags, $bundles[$newBundleName]);
- // delete bundle
- $this->_delicious->deleteBundle($newBundleName);
- sleep(15);
- // check if bundle was deleted
- $bundles = $this->_delicious->getBundles();
- $this->assertArrayNotHasKey($newBundleName, $bundles);
- }
- /**
- *
- * @return void
- */
- public function _testAddDeletePost()
- {
- $newPost = $this->_delicious->createNewPost(self::$TEST_POST_TITLE, self::$TEST_POST_URL)
- ->setNotes(self::$TEST_POST_NOTES)
- ->setTags(self::$TEST_POST_TAGS)
- ->setShared(self::$TEST_POST_SHARED);
- // check if post was created correctly
- $this->assertEquals(self::$TEST_POST_TITLE, $newPost->getTitle());
- $this->assertEquals(self::$TEST_POST_URL, $newPost->getUrl());
- $this->assertEquals(self::$TEST_POST_NOTES, $newPost->getNotes());
- $this->assertEquals(self::$TEST_POST_TAGS, $newPost->getTags());
- $this->assertEquals(self::$TEST_POST_SHARED, $newPost->getShared());
- // test tag adding to tag
- $newTagName = uniqid('tag');
- $newPost->addTag($newTagName);
- $this->assertContains($newTagName, $newPost->getTags());
- // test tag removeing
- $newPost->removeTag($newTagName);
- $this->assertNotContains($newTagName, $newPost->getTags());
- // send post to del.icio.us
- $newPost->save();
- sleep(15);
- // get the post back
- $returnedPosts = $this->_delicious->getPosts(null, null, self::$TEST_POST_URL);
- $this->assertEquals(1, count($returnedPosts));
- $savedPost = $returnedPosts[0];
- // check if post was saved correctly
- $this->assertEquals(self::$TEST_POST_TITLE, $savedPost->getTitle());
- $this->assertEquals(self::$TEST_POST_URL, $savedPost->getUrl());
- $this->assertEquals(self::$TEST_POST_NOTES, $savedPost->getNotes());
- $this->assertEquals(self::$TEST_POST_TAGS, $savedPost->getTags());
- $this->assertEquals(self::$TEST_POST_SHARED, $savedPost->getShared());
- $this->assertTrue($savedPost->getDate() instanceof Zend_Date);
- $this->assertTrue(is_string($savedPost->getHash()));
- $this->assertTrue(is_int($savedPost->getOthers()));
- // delete post
- $savedPost->delete();
- sleep(15);
- // check if post was realy deleted
- $returnedPosts = $this->_delicious->getPosts(null, null, self::$TEST_POST_URL);
- $this->assertEquals(0, count($returnedPosts));
- }
- /**
- * Ensures that getAllPosts() provides expected behavior
- *
- * @return void
- */
- public function testGetAllPosts()
- {
- $posts = $this->_delicious->getAllPosts('zfSite');
- $this->assertTrue($posts instanceof Zend_Service_Delicious_PostList);
- foreach ($posts as $post) {
- $this->assertContains('zfSite', $post->getTags());
- }
- }
- /**
- * Ensures that getRecentPosts() provides expected behavior
- *
- * @return void
- */
- public function testGetRecentPosts()
- {
- $posts = $this->_delicious->getRecentPosts('zfSite', 10);
- $this->assertTrue($posts instanceof Zend_Service_Delicious_PostList);
- $this->assertTrue(count($posts) <= 10);
- foreach ($posts as $post) {
- $this->assertContains('zfSite', $post->getTags());
- }
- }
- /**
- * Ensures that getPosts() provides expected behavior
- *
- * @return void
- */
- public function testGetPosts()
- {
- $posts = $this->_delicious->getPosts('zfSite', new Zend_Date(), 'help');
- $this->assertTrue($posts instanceof Zend_Service_Delicious_PostList);
- $this->assertTrue(count($posts) <= 10);
- foreach ($posts as $post) {
- $this->assertContains('zfSite', $post->getTags());
- }
- }
- /**
- *
- * @return void
- */
- public function testDates()
- {
- $this->assertTrue(is_array($this->_delicious->getDates()));
- }
- }
|