PublicDataTest.php 4.3 KB

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