WeblogTest.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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_Weblog
  28. */
  29. require_once 'Zend/Service/Technorati/Weblog.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_WeblogTest extends Zend_Service_Technorati_TestCase
  40. {
  41. public function setUp()
  42. {
  43. $this->domElement = self::getTestFileElementAsDom('TestWeblog.xml', '//weblog');
  44. }
  45. public function testConstruct()
  46. {
  47. $this->_testConstruct('Zend_Service_Technorati_Weblog', array($this->domElement));
  48. }
  49. public function testConstructThrowsExceptionWithInvalidDom()
  50. {
  51. $this->_testConstructThrowsExceptionWithInvalidDom('Zend_Service_Technorati_Weblog', 'DOMElement');
  52. }
  53. public function testWeblog()
  54. {
  55. $weblog = new Zend_Service_Technorati_Weblog($this->domElement);
  56. // check name
  57. $this->assertEquals('Roby Web World Italia', $weblog->getName());
  58. // check URL
  59. $this->assertEquals(Zend_Uri::factory('http://robyww.blogspot.com'), $weblog->getUrl());
  60. // check Atom Url
  61. $this->assertEquals(Zend_Uri::factory('http://robyww.blogspot.com/feeds/posts/atom'), $weblog->getAtomUrl());
  62. // check RSS Url
  63. $this->assertEquals(Zend_Uri::factory('http://robyww.blogspot.com/feeds/posts/rss'), $weblog->getRssUrl());
  64. // check inbound blogs
  65. $this->assertEquals(71, $weblog->getInboundBlogs());
  66. // check inbound links
  67. $this->assertEquals(103, $weblog->getInboundLinks());
  68. // check last update
  69. $this->assertEquals(new Zend_Date('2007-11-11 08:47:26 GMT'), $weblog->getLastUpdate());
  70. // check rank
  71. $this->assertEquals(93473, $weblog->getRank());
  72. // check authors
  73. $var = $weblog->getAuthors();
  74. $this->assertTrue(is_array($var));
  75. $this->assertEquals(1, sizeof($var));
  76. // check photo
  77. $this->assertEquals(false, $weblog->hasPhoto());
  78. // check lat and lon
  79. $this->assertNull($weblog->getLat());
  80. $this->assertNull($weblog->getLon());
  81. }
  82. public function testWeblogWithTwoAuthors()
  83. {
  84. $domElement = self::getTestFileElementAsDom('TestWeblogTwoAuthors.xml', '//weblog');
  85. $weblog = new Zend_Service_Technorati_Weblog($domElement);
  86. $authors = $weblog->getAuthors();
  87. // check whether $authors is an array with valid length
  88. $this->assertTrue(is_array($authors));
  89. $this->assertEquals(2, sizeof($authors));
  90. // check first author
  91. $author = $authors[0];
  92. $this->assertTrue($author instanceof Zend_Service_Technorati_Author);
  93. $this->assertEquals('rfilippini', $author->getUsername());
  94. // check second author, be sure it's not the first one
  95. $author = $authors[1];
  96. $this->assertTrue($author instanceof Zend_Service_Technorati_Author);
  97. $this->assertEquals('Rinzi', $author->getUsername());
  98. }
  99. public function testSetGet()
  100. {
  101. $weblog = new Zend_Service_Technorati_Weblog($this->domElement);
  102. // check name
  103. $set = 'foo';
  104. $get = $weblog->setName($set)->getName();
  105. $this->assertTrue(is_string($get));
  106. $this->assertEquals($set, $get);
  107. // check URL
  108. $set = Zend_Uri::factory('http://www.simonecarletti.com/');
  109. $get = $weblog->setUrl($set)->getUrl();
  110. $this->assertTrue($get instanceof Zend_Uri_Http);
  111. $this->assertEquals($set, $get);
  112. $set = 'http://www.simonecarletti.com/';
  113. $get = $weblog->setUrl($set)->getUrl();
  114. $this->assertTrue($get instanceof Zend_Uri_Http);
  115. $this->assertEquals(Zend_Uri::factory($set), $get);
  116. $set = 'http:::/foo';
  117. try {
  118. $weblog->setUrl($set);
  119. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  120. } catch(Zend_Service_Technorati_Exception $e) {
  121. $this->assertContains("Invalid URI", $e->getMessage());
  122. }
  123. // check Atom URL
  124. $set = Zend_Uri::factory('http://www.simonecarletti.com/');
  125. $get = $weblog->setAtomUrl($set)->getAtomUrl();
  126. $this->assertTrue($get instanceof Zend_Uri_Http);
  127. $this->assertEquals($set, $get);
  128. $set = 'http://www.simonecarletti.com/';
  129. $get = $weblog->setAtomUrl($set)->getAtomUrl();
  130. $this->assertTrue($get instanceof Zend_Uri_Http);
  131. $this->assertEquals(Zend_Uri::factory($set), $get);
  132. $set = 'http:::/foo';
  133. try {
  134. $weblog->setAtomUrl($set);
  135. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  136. } catch(Zend_Service_Technorati_Exception $e) {
  137. $this->assertContains("Invalid URI", $e->getMessage());
  138. }
  139. // check RSS Url
  140. $set = Zend_Uri::factory('http://www.simonecarletti.com/');
  141. $get = $weblog->setRssUrl($set)->getRssUrl();
  142. $this->assertTrue($get instanceof Zend_Uri_Http);
  143. $this->assertEquals($set, $get);
  144. $set = 'http://www.simonecarletti.com/';
  145. $get = $weblog->setRssUrl($set)->getRssUrl();
  146. $this->assertTrue($get instanceof Zend_Uri_Http);
  147. $this->assertEquals(Zend_Uri::factory($set), $get);
  148. $set = 'http:::/foo';
  149. try {
  150. $weblog->setRssUrl($set);
  151. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  152. } catch(Zend_Service_Technorati_Exception $e) {
  153. $this->assertContains("Invalid URI", $e->getMessage());
  154. }
  155. // check inbound blogs
  156. $set = rand();
  157. $get = $weblog->setInboundBlogs($set)->getInboundBlogs();
  158. $this->assertTrue(is_int($get));
  159. $this->assertEquals($set, $get);
  160. $set = (string) rand();
  161. $get = $weblog->setInboundBlogs($set)->getInboundBlogs();
  162. $this->assertTrue(is_int($get));
  163. $this->assertEquals((int) $set, $get);
  164. // check inbound links
  165. $set = rand();
  166. $get = $weblog->setInboundLinks($set)->getInboundLinks();
  167. $this->assertTrue(is_int($get));
  168. $this->assertEquals((int) $set, $get);
  169. $set = (string) rand();
  170. $get = $weblog->setInboundLinks($set)->getInboundLinks();
  171. $this->assertTrue(is_int($get));
  172. $this->assertEquals((int) $set, $get);
  173. // last update
  174. $set = '2007-11-11 08:47:26 GMT';
  175. $get = $weblog->setLastUpdate($set)->getLastUpdate();
  176. $this->assertTrue($get instanceof Zend_Date);
  177. $this->assertEquals(new Zend_Date($set), $get);
  178. /* not supported
  179. $set = time();
  180. $get = $weblog->setLastUpdate($set)->getLastUpdate();
  181. $this->assertTrue(is_int($get));
  182. $this->assertEquals($set, $get); */
  183. $set = '200ty';
  184. try {
  185. $weblog->setLastUpdate($set);
  186. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  187. } catch(Zend_Service_Technorati_Exception $e) {
  188. $this->assertContains("valid Date/Time", $e->getMessage());
  189. }
  190. // check rank
  191. $set = rand();
  192. $get = $weblog->setRank($set)->getRank();
  193. $this->assertTrue(is_int($get));
  194. $this->assertEquals((int) $set, $get);
  195. $set = (string) rand();
  196. $get = $weblog->setRank($set)->getRank();
  197. $this->assertTrue(is_int($get));
  198. $this->assertEquals((int) $set, $get);
  199. // check hasPhoto
  200. $set = false;
  201. $get = $weblog->setHasPhoto($set)->hasPhoto();
  202. $this->assertTrue(is_bool($get));
  203. $this->assertEquals($set, $get);
  204. $set = 0;
  205. $get = $weblog->setHasPhoto($set)->hasPhoto();
  206. $this->assertTrue(is_bool($get));
  207. $this->assertEquals((bool) $set, $get);
  208. // check lat
  209. $set = 1.3;
  210. $get = $weblog->setLat($set)->getLat();
  211. $this->assertTrue(is_float($get));
  212. $this->assertEquals($set, $get);
  213. $set = '1.3';
  214. $get = $weblog->setLat($set)->getLat();
  215. $this->assertTrue(is_float($get));
  216. $this->assertEquals((float) $set, $get);
  217. // check lon
  218. $set = 1.3;
  219. $get = $weblog->setLon($set)->getLon();
  220. $this->assertTrue(is_float($get));
  221. $this->assertEquals($set, $get);
  222. $set = '1.3';
  223. $get = $weblog->setLon($set)->getLon();
  224. $this->assertTrue(is_float($get));
  225. $this->assertEquals((float) $set, $get);
  226. }
  227. }