PrivateDataTest.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Delicious
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Service_Delicious
  24. */
  25. require_once 'Zend/Service/Delicious.php';
  26. /**
  27. * @category Zend_Service
  28. * @package Zend_Service_Delicious
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Service
  33. * @group Zend_Service_Delicious
  34. */
  35. class Zend_Service_Delicious_PrivateDataTest extends PHPUnit_Framework_TestCase
  36. {
  37. const TEST_UNAME = 'zfTestUser';
  38. const TEST_PASS = 'zfuser';
  39. private static $TEST_POST_TITLE = 'test - title';
  40. private static $TEST_POST_URL = 'http://zfdev.com/unittests/delicious/test_url_1';
  41. private static $TEST_POST_NOTES = 'test - note';
  42. private static $TEST_POST_TAGS = array('testTag1','testTag2');
  43. private static $TEST_POST_SHARED = false;
  44. /**
  45. * @var Zend_Service_Delicious
  46. */
  47. protected $_delicious;
  48. /**
  49. *
  50. * @return void
  51. */
  52. public function setUp()
  53. {
  54. $httpClient = new Zend_Http_Client();
  55. $httpClient->setConfig(array(
  56. 'useragent' => 'Zend_Service_Delicious - Unit tests/0.1',
  57. 'keepalive' => true
  58. ));
  59. Zend_Rest_Client::setHttpClient($httpClient);
  60. $this->_delicious = new Zend_Service_Delicious(self::TEST_UNAME, self::TEST_PASS);
  61. }
  62. /**
  63. *
  64. * @return void
  65. */
  66. public function testLastUpdate()
  67. {
  68. $this->assertTrue($this->_delicious->getLastUpdate() instanceof Zend_Date);
  69. }
  70. /**
  71. *
  72. * @return void
  73. */
  74. public function testTagsAndBundles()
  75. {
  76. // get tags
  77. $tags = $this->_delicious->getTags();
  78. $this->assertTrue(is_array($tags));
  79. $tags = array_keys($tags);
  80. if (count($tags) < 1) {
  81. $this->fail('Test account corrupted - no tags');
  82. }
  83. $oldTagName = $tags[0];
  84. $newTagName = uniqid('tag');
  85. // rename tag
  86. $this->_delicious->renameTag($oldTagName, $newTagName);
  87. sleep(15);
  88. // get renamed tags
  89. $tags = $this->_delicious->getTags();
  90. $this->assertArrayHasKey($newTagName, $tags);
  91. $this->assertArrayNotHasKey($oldTagName, $tags);
  92. $tags = array_keys($tags);
  93. // add new bundle
  94. $newBundleName = uniqid('bundle');
  95. $this->_delicious->addBundle($newBundleName, $tags);
  96. sleep(15);
  97. // check if bundle was added
  98. $bundles = $this->_delicious->getBundles();
  99. $this->assertTrue(is_array($bundles));
  100. $this->assertArrayHasKey($newBundleName, $bundles);
  101. $this->assertEquals($tags, $bundles[$newBundleName]);
  102. // delete bundle
  103. $this->_delicious->deleteBundle($newBundleName);
  104. sleep(15);
  105. // check if bundle was deleted
  106. $bundles = $this->_delicious->getBundles();
  107. $this->assertArrayNotHasKey($newBundleName, $bundles);
  108. }
  109. /**
  110. *
  111. * @return void
  112. */
  113. public function _testAddDeletePost()
  114. {
  115. $newPost = $this->_delicious->createNewPost(self::$TEST_POST_TITLE, self::$TEST_POST_URL)
  116. ->setNotes(self::$TEST_POST_NOTES)
  117. ->setTags(self::$TEST_POST_TAGS)
  118. ->setShared(self::$TEST_POST_SHARED);
  119. // check if post was created correctly
  120. $this->assertEquals(self::$TEST_POST_TITLE, $newPost->getTitle());
  121. $this->assertEquals(self::$TEST_POST_URL, $newPost->getUrl());
  122. $this->assertEquals(self::$TEST_POST_NOTES, $newPost->getNotes());
  123. $this->assertEquals(self::$TEST_POST_TAGS, $newPost->getTags());
  124. $this->assertEquals(self::$TEST_POST_SHARED, $newPost->getShared());
  125. // test tag adding to tag
  126. $newTagName = uniqid('tag');
  127. $newPost->addTag($newTagName);
  128. $this->assertContains($newTagName, $newPost->getTags());
  129. // test tag removeing
  130. $newPost->removeTag($newTagName);
  131. $this->assertNotContains($newTagName, $newPost->getTags());
  132. // send post to del.icio.us
  133. $newPost->save();
  134. sleep(15);
  135. // get the post back
  136. $returnedPosts = $this->_delicious->getPosts(null, null, self::$TEST_POST_URL);
  137. $this->assertEquals(1, count($returnedPosts));
  138. $savedPost = $returnedPosts[0];
  139. // check if post was saved correctly
  140. $this->assertEquals(self::$TEST_POST_TITLE, $savedPost->getTitle());
  141. $this->assertEquals(self::$TEST_POST_URL, $savedPost->getUrl());
  142. $this->assertEquals(self::$TEST_POST_NOTES, $savedPost->getNotes());
  143. $this->assertEquals(self::$TEST_POST_TAGS, $savedPost->getTags());
  144. $this->assertEquals(self::$TEST_POST_SHARED, $savedPost->getShared());
  145. $this->assertTrue($savedPost->getDate() instanceof Zend_Date);
  146. $this->assertTrue(is_string($savedPost->getHash()));
  147. $this->assertTrue(is_int($savedPost->getOthers()));
  148. // delete post
  149. $savedPost->delete();
  150. sleep(15);
  151. // check if post was realy deleted
  152. $returnedPosts = $this->_delicious->getPosts(null, null, self::$TEST_POST_URL);
  153. $this->assertEquals(0, count($returnedPosts));
  154. }
  155. /**
  156. * Ensures that getAllPosts() provides expected behavior
  157. *
  158. * @return void
  159. */
  160. public function testGetAllPosts()
  161. {
  162. $posts = $this->_delicious->getAllPosts('zfSite');
  163. $this->assertTrue($posts instanceof Zend_Service_Delicious_PostList);
  164. foreach ($posts as $post) {
  165. $this->assertContains('zfSite', $post->getTags());
  166. }
  167. }
  168. /**
  169. * Ensures that getRecentPosts() provides expected behavior
  170. *
  171. * @return void
  172. */
  173. public function testGetRecentPosts()
  174. {
  175. $posts = $this->_delicious->getRecentPosts('zfSite', 10);
  176. $this->assertTrue($posts instanceof Zend_Service_Delicious_PostList);
  177. $this->assertTrue(count($posts) <= 10);
  178. foreach ($posts as $post) {
  179. $this->assertContains('zfSite', $post->getTags());
  180. }
  181. }
  182. /**
  183. * Ensures that getPosts() provides expected behavior
  184. *
  185. * @return void
  186. */
  187. public function testGetPosts()
  188. {
  189. $posts = $this->_delicious->getPosts('zfSite', new Zend_Date(), 'help');
  190. $this->assertTrue($posts instanceof Zend_Service_Delicious_PostList);
  191. $this->assertTrue(count($posts) <= 10);
  192. foreach ($posts as $post) {
  193. $this->assertContains('zfSite', $post->getTags());
  194. }
  195. }
  196. /**
  197. *
  198. * @return void
  199. */
  200. public function testDates()
  201. {
  202. $this->assertTrue(is_array($this->_delicious->getDates()));
  203. }
  204. }