PublicDataTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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_PublicDataTest extends PHPUnit_Framework_TestCase
  36. {
  37. const TEST_UNAME = 'zfTestUser';
  38. const TEST_PASS = 'zfuser';
  39. const TEST_URL = 'http://framework.zend.com/';
  40. /**
  41. * @var Zend_Service_Delicious
  42. */
  43. protected $_delicious;
  44. /**
  45. * @return void
  46. */
  47. public function setUp()
  48. {
  49. $httpClient = new Zend_Http_Client();
  50. $httpClient->setConfig(array(
  51. 'useragent' => 'Zend_Service_Delicious - Unit tests/0.1',
  52. 'keepalive' => true
  53. ));
  54. Zend_Rest_Client::setHttpClient($httpClient);
  55. $this->_delicious = new Zend_Service_Delicious();
  56. }
  57. /**
  58. * Try to get tags of some user
  59. *
  60. * @return void
  61. */
  62. public function testGetTags()
  63. {
  64. $tags = $this->_delicious->getUserTags(self::TEST_UNAME);
  65. $this->assertTrue(is_array($tags));
  66. }
  67. /**
  68. * @return void
  69. */
  70. public function testGetTagsWithCount()
  71. {
  72. $tags = $this->_delicious->getUserTags(self::TEST_UNAME, null, 20);
  73. $this->assertTrue(is_array($tags));
  74. $this->assertTrue(count($tags) <= 20);
  75. }
  76. /**
  77. * @return void
  78. */
  79. public function testGetTagsWithAtLeast()
  80. {
  81. $tags = $this->_delicious->getUserTags(self::TEST_UNAME, 5);
  82. $this->assertTrue(is_array($tags));
  83. foreach ($tags as $count) {
  84. $this->assertTrue($count >= 5);
  85. }
  86. }
  87. /**
  88. * @return void
  89. */
  90. public function testGetNetwork()
  91. {
  92. $network = $this->_delicious->getUserNetwork(self::TEST_UNAME);
  93. $this->assertTrue(is_array($network));
  94. }
  95. /**
  96. * @return void
  97. */
  98. public function testGetFans()
  99. {
  100. $fans = $this->_delicious->getUserFans(self::TEST_UNAME);
  101. $this->assertTrue(is_array($fans));
  102. }
  103. /**
  104. * @return void
  105. */
  106. public function testGetUserPosts()
  107. {
  108. $posts = $this->_delicious->getUserPosts(self::TEST_UNAME, 10);
  109. $this->assertTrue($posts instanceof Zend_Service_Delicious_PostList);
  110. // check if all objects in returned Zend_Service_Delicious_PostList
  111. // are instances of Zend_Service_Delicious_SimplePost
  112. foreach ($posts as $post) {
  113. $this->assertTrue($post instanceof Zend_Service_Delicious_SimplePost);
  114. }
  115. // test filtering of Zend_Service_Delicious_PostList by tag name
  116. $filterPostList = $posts->withTag('zfSite');
  117. foreach ($filterPostList as $post) {
  118. $this->assertTrue(is_array($post->getTags()));
  119. $this->assertContains('zfSite', $post->getTags());
  120. }
  121. }
  122. /**
  123. * Try to get details of some URL
  124. *
  125. * @return void
  126. */
  127. public function testGetUrlDetails() {
  128. $details = $this->_delicious->getUrlDetails(self::TEST_URL);
  129. $this->assertTrue(is_array($details));
  130. $this->assertArrayHasKey('hash', $details);
  131. $this->assertArrayHasKey('top_tags', $details);
  132. $this->assertArrayHasKey('url', $details);
  133. $this->assertArrayHasKey('total_posts', $details);
  134. $this->assertEquals(self::TEST_URL, $details['url']);
  135. $this->assertTrue(is_array($details['top_tags']));
  136. }
  137. }