CosmosResultTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_CosmosResult
  28. */
  29. require_once 'Zend/Service/Technorati/CosmosResult.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_CosmosResultTest extends Zend_Service_Technorati_TestCase
  40. {
  41. public function setUp()
  42. {
  43. $this->domElements = self::getTestFileElementsAsDom('TestCosmosResultSet.xml');
  44. }
  45. public function testConstruct()
  46. {
  47. $this->_testConstruct('Zend_Service_Technorati_CosmosResult', array($this->domElements->item(0)));
  48. }
  49. public function testConstructThrowsExceptionWithInvalidDom()
  50. {
  51. $this->_testConstructThrowsExceptionWithInvalidDom('Zend_Service_Technorati_CosmosResult', 'DOMElement');
  52. }
  53. public function testCosmosResultSerialization()
  54. {
  55. $this->_testResultSerialization(new Zend_Service_Technorati_CosmosResult($this->domElements->item(0)));
  56. }
  57. public function testCosmosResultSiteLink()
  58. {
  59. $domElements = self::getTestFileElementsAsDom('TestCosmosResultSetSiteLink.xml');
  60. $object = new Zend_Service_Technorati_CosmosResult($domElements->item(0));
  61. $this->assertTrue($object->getWeblog() instanceof Zend_Service_Technorati_Weblog);
  62. $this->assertContains('Gioxx', $object->getWeblog()->getName());
  63. $this->assertTrue($object->getNearestPermalink() instanceof Zend_Uri_Http);
  64. $this->assertEquals(Zend_Uri::factory('http://gioxx.org/2007/11/05/il-passaggio-a-mac-le-11-risposte/'), $object->getNearestPermalink());
  65. $this->assertTrue(is_string($object->getExcerpt()));
  66. $this->assertContains('Ho intenzione di prendere il modello bianco', $object->getExcerpt());
  67. $this->assertTrue($object->getLinkCreated() instanceof Zend_Date);
  68. $this->assertEquals(new Zend_Date('2007-11-11 20:07:11 GMT'), $object->getLinkCreated());
  69. $this->assertTrue($object->getLinkUrl() instanceof Zend_Uri_Http);
  70. $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com/blog/2007/04/parallels-desktop-overview.php'), $object->getLinkUrl());
  71. // test an other element to prevent cached values
  72. $object = new Zend_Service_Technorati_CosmosResult($domElements->item(1));
  73. $this->assertContains('Progetto-Seo', $object->getWeblog()->getName());
  74. $this->assertEquals(Zend_Uri::factory('http://www.progetto-seo.com/motori-di-ricerca/links-interni'), $object->getNearestPermalink());
  75. $this->assertContains('soprattutto Google', $object->getExcerpt());
  76. $this->assertEquals(new Zend_Date('2007-11-10 08:57:22 GMT'), $object->getLinkCreated());
  77. $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com/blog/2007/04/google-yahoo-ask-nofollow.php'), $object->getLinkUrl());
  78. }
  79. public function testCosmosResultSiteLinkNearestPermalinkIsNull()
  80. {
  81. $domElements = self::getTestFileElementsAsDom('TestCosmosResultSetSiteLink.xml');
  82. $object = new Zend_Service_Technorati_CosmosResult($domElements->item(2));
  83. $this->assertContains('Controrete', $object->getWeblog()->getName());
  84. $this->assertNull($object->getNearestPermalink());
  85. }
  86. public function testCosmosResultSiteWeblog()
  87. {
  88. $domElements = self::getTestFileElementsAsDom('TestCosmosResultSetSiteWeblog.xml');
  89. $object = new Zend_Service_Technorati_CosmosResult($domElements->item(0));
  90. $this->assertTrue($object->getWeblog() instanceof Zend_Service_Technorati_Weblog);
  91. $this->assertContains('Simone Carletti', $object->getWeblog()->getName());
  92. $this->assertTrue($object->getLinkUrl() instanceof Zend_Uri_Http);
  93. $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com'), $object->getLinkUrl());
  94. // test an other element to prevent cached values
  95. $object = new Zend_Service_Technorati_CosmosResult($domElements->item(1));
  96. $this->assertContains('Gioxx', $object->getWeblog()->getName());
  97. $this->assertEquals(Zend_Uri::factory('http://www.simonecarletti.com'), $object->getLinkUrl());
  98. }
  99. public function testCosmosResultBlogLink()
  100. {
  101. // same as testSearchResultSiteLink
  102. }
  103. public function testCosmosResultBlogWeblog()
  104. {
  105. // same as testSearchResultSiteWeblog
  106. }
  107. }