2
0

CosmosResultSetTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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_Technorati
  17. * @subpackage UnitTests
  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__) . DIRECTORY_SEPARATOR .'TestCase.php';
  26. /**
  27. * @see Zend_Service_Technorati_CosmosResultSet
  28. */
  29. require_once 'Zend/Service/Technorati/CosmosResultSet.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Service_Technorati
  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_Technorati_CosmosResultSetTest extends Zend_Service_Technorati_TestCase
  38. {
  39. public function setUp()
  40. {
  41. $this->dom = self::getTestFileContentAsDom('TestCosmosResultSet.xml');
  42. }
  43. public function testConstruct()
  44. {
  45. $this->_testConstruct('Zend_Service_Technorati_CosmosResultSet', array($this->dom));
  46. }
  47. public function testConstructThrowsExceptionWithInvalidDom()
  48. {
  49. $this->_testConstructThrowsExceptionWithInvalidDom('Zend_Service_Technorati_CosmosResultSet', 'DOMDocument');
  50. }
  51. public function testCosmosResultSet()
  52. {
  53. $object = new Zend_Service_Technorati_CosmosResultSet($this->dom);
  54. // check counts
  55. $this->assertType('integer', $object->totalResults());
  56. $this->assertEquals(2, $object->totalResults());
  57. $this->assertType('integer', $object->totalResultsAvailable());
  58. $this->assertEquals(278, $object->totalResultsAvailable());
  59. // check properties
  60. $this->assertType('Zend_Uri_Http', $object->getUrl());
  61. $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com/blog'), $object->getUrl());
  62. $this->assertType('integer', $object->getInboundLinks());
  63. $this->assertEquals(278, $object->getInboundLinks());
  64. // check weblog
  65. $this->assertType('Zend_Service_Technorati_Weblog', $object->getWeblog());
  66. $this->assertEquals('Simone Carletti\'s Blog', $object->getWeblog()->getName());
  67. }
  68. public function testCosmosResultSetItemsInstanceOfResult()
  69. {
  70. $this->_testResultSetItemsInstanceOfResult(
  71. 'Zend_Service_Technorati_CosmosResultSet',
  72. array($this->dom),
  73. 'Zend_Service_Technorati_CosmosResult');
  74. }
  75. public function testCosmosResultSetSerialization()
  76. {
  77. $this->_testResultSetSerialization(new Zend_Service_Technorati_CosmosResultSet($this->dom));
  78. }
  79. public function testCosmosResultSetSiteLink()
  80. {
  81. $dom = self::getTestFileContentAsDom('TestCosmosResultSetSiteLink.xml');
  82. $object = new Zend_Service_Technorati_CosmosResultSet($dom);
  83. $this->assertEquals(3, $object->totalResults());
  84. $this->assertEquals(949, $object->totalResultsAvailable());
  85. $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com'), $object->getUrl());
  86. $this->assertEquals(949, $object->getInboundLinks());
  87. }
  88. public function testCosmosResultSetSiteWeblog()
  89. {
  90. $dom = self::getTestFileContentAsDom('TestCosmosResultSetSiteWeblog.xml');
  91. $object = new Zend_Service_Technorati_CosmosResultSet($dom);
  92. $this->assertEquals(3, $object->totalResults());
  93. $this->assertEquals(39, $object->totalResultsAvailable());
  94. $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com'), $object->getUrl());
  95. $this->assertEquals(39, $object->getInboundBlogs());
  96. }
  97. public function testCosmosResultSetSiteWeblogWithMissingInboundblogs()
  98. {
  99. // I can't do nothing to fix this issue in charge of Technorati
  100. // I only have to ensure the class doens't fail and $object->totalResultsAvailable == 0
  101. $dom = self::getTestFileContentAsDom('TestCosmosResultSetSiteWeblogWithMissingInboundblogs.xml');
  102. $object = new Zend_Service_Technorati_CosmosResultSet($dom);
  103. $this->assertEquals(3, $object->totalResults());
  104. $this->assertEquals(0, $object->totalResultsAvailable());
  105. $this->assertEquals(null, $object->getInboundBlogs());
  106. }
  107. public function testCosmosResultSetSiteUrlWithInvalidSchema()
  108. {
  109. // FIXME
  110. // Technorati allows 'url' parameter to be specified with or without www and/or schema.
  111. // Technorati interface works well but returned responses may include invalid URIs.
  112. // I have 2 possibility to fix the following issue:
  113. // 1. using a default http schema when URL has an invalid one
  114. // 2. force developers to provide a valid schema with 'url' parameter
  115. // The second options is the best one because not only <url>
  116. // but other tags are affected by this issue if you don't provide a valid schema
  117. // $dom = self::getTestFileContentAsDom('TestCosmosResultSetSiteUrlWithInvalidSchema.xml');
  118. // $object = new Zend_Service_Technorati_CosmosResultSet($dom);
  119. // $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com'), $object->getUrl());
  120. }
  121. public function testCosmosResultSetBlogLink()
  122. {
  123. $dom = self::getTestFileContentAsDom('TestCosmosResultSetBlogLink.xml');
  124. $object = new Zend_Service_Technorati_CosmosResultSet($dom);
  125. $this->assertEquals(20, $object->totalResults());
  126. $this->assertEquals(298, $object->totalResultsAvailable());
  127. $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com/blog'), $object->getUrl());
  128. $this->assertEquals(298, $object->getInboundLinks());
  129. $this->assertEquals('Simone Carletti\'s Blog', $object->getWeblog()->getName());
  130. }
  131. public function testCosmosResultSetBlogWeblog()
  132. {
  133. $dom = self::getTestFileContentAsDom('TestCosmosResultSetBlogWeblog.xml');
  134. $object = new Zend_Service_Technorati_CosmosResultSet($dom);
  135. $this->assertEquals(20, $object->totalResults());
  136. $this->assertEquals(85, $object->totalResultsAvailable());
  137. $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com/blog'), $object->getUrl());
  138. $this->assertEquals(85, $object->getInboundBlogs());
  139. $this->assertEquals('Simone Carletti\'s Blog', $object->getWeblog()->getName());
  140. }
  141. }