CosmosResultSetTest.php 6.8 KB

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