2
0

PublicDataTest.php 4.4 KB

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