WordpressAtom10Test.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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_Feed
  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. require_once 'Zend/Feed/Reader.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Feed
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @group Zend_Feed
  30. * @group Zend_Feed_Reader
  31. */
  32. class Zend_Feed_Reader_Integration_WordpressAtom10Test extends PHPUnit_Framework_TestCase
  33. {
  34. protected $_feedSamplePath = null;
  35. public function setup()
  36. {
  37. Zend_Feed_Reader::reset();
  38. $this->_feedSamplePath = dirname(__FILE__) . '/_files/wordpress-atom10.xml';
  39. $this->_options = Zend_Date::setOptions();
  40. foreach($this->_options as $k=>$v) {
  41. if (is_null($v)) {
  42. unset($this->_options[$k]);
  43. }
  44. }
  45. Zend_Date::setOptions(array('format_type'=>'iso'));
  46. }
  47. public function teardown()
  48. {
  49. Zend_Date::setOptions($this->_options);
  50. }
  51. public function testGetsTitle()
  52. {
  53. $feed = Zend_Feed_Reader::importString(
  54. file_get_contents($this->_feedSamplePath)
  55. );
  56. $this->assertEquals('Norm 2782', $feed->getTitle());
  57. }
  58. public function testGetsAuthors()
  59. {
  60. $feed = Zend_Feed_Reader::importString(
  61. file_get_contents($this->_feedSamplePath)
  62. );
  63. $this->assertEquals(array(
  64. array('name'=>'norm2782','uri'=>'http://www.norm2782.com')
  65. ), (array) $feed->getAuthors());
  66. }
  67. public function testGetsSingleAuthor()
  68. {
  69. $feed = Zend_Feed_Reader::importString(
  70. file_get_contents($this->_feedSamplePath)
  71. );
  72. $this->assertEquals(array('name'=>'norm2782','uri'=>'http://www.norm2782.com'), $feed->getAuthor());
  73. }
  74. public function testGetsCopyright()
  75. {
  76. $feed = Zend_Feed_Reader::importString(
  77. file_get_contents($this->_feedSamplePath)
  78. );
  79. $this->assertEquals(null, $feed->getCopyright());
  80. }
  81. public function testGetsDescription()
  82. {
  83. $feed = Zend_Feed_Reader::importString(
  84. file_get_contents($this->_feedSamplePath)
  85. );
  86. $this->assertEquals('Why are you here?', $feed->getDescription());
  87. }
  88. public function testGetsLanguage()
  89. {
  90. $feed = Zend_Feed_Reader::importString(
  91. file_get_contents($this->_feedSamplePath)
  92. );
  93. $this->assertEquals('en', $feed->getLanguage());
  94. }
  95. public function testGetsLink()
  96. {
  97. $feed = Zend_Feed_Reader::importString(
  98. file_get_contents($this->_feedSamplePath)
  99. );
  100. $this->assertEquals('http://www.norm2782.com', $feed->getLink());
  101. }
  102. public function testGetsEncoding()
  103. {
  104. $feed = Zend_Feed_Reader::importString(
  105. file_get_contents($this->_feedSamplePath)
  106. );
  107. $this->assertEquals('UTF-8', $feed->getEncoding());
  108. }
  109. public function testGetsEntryCount()
  110. {
  111. $feed = Zend_Feed_Reader::importString(
  112. file_get_contents($this->_feedSamplePath)
  113. );
  114. $this->assertEquals(10, $feed->count());
  115. }
  116. /**
  117. * Entry level testing
  118. */
  119. public function testGetsEntryId()
  120. {
  121. $feed = Zend_Feed_Reader::importString(
  122. file_get_contents($this->_feedSamplePath)
  123. );
  124. $entry = $feed->current();
  125. $this->assertEquals('http://www.norm2782.com/?p=114', $entry->getId());
  126. }
  127. public function testGetsEntryTitle()
  128. {
  129. $feed = Zend_Feed_Reader::importString(
  130. file_get_contents($this->_feedSamplePath)
  131. );
  132. $entry = $feed->current();
  133. /**
  134. * Note: The three dots below is actually a single Unicode character
  135. * called the "three dot leader". Don't replace in error!
  136. */
  137. $this->assertEquals('Wth&#8230; reading books?', $entry->getTitle());
  138. }
  139. public function testGetsEntryAuthors()
  140. {
  141. $feed = Zend_Feed_Reader::importString(
  142. file_get_contents($this->_feedSamplePath)
  143. );
  144. $entry = $feed->current();
  145. $this->assertEquals(array(array('name'=>'norm2782','uri'=>'http://www.norm2782.com')), (array) $entry->getAuthors());
  146. }
  147. public function testGetsEntrySingleAuthor()
  148. {
  149. $feed = Zend_Feed_Reader::importString(
  150. file_get_contents($this->_feedSamplePath)
  151. );
  152. $entry = $feed->current();
  153. $this->assertEquals(array('name'=>'norm2782','uri'=>'http://www.norm2782.com'), $entry->getAuthor());
  154. }
  155. public function testGetsEntryDescription()
  156. {
  157. $feed = Zend_Feed_Reader::importString(
  158. file_get_contents($this->_feedSamplePath)
  159. );
  160. $entry = $feed->current();
  161. /**
  162. * Note: "’" is not the same as "'" - don't replace in error
  163. */
  164. $this->assertEquals('Being in New Zealand does strange things to a person. Everybody who knows me, knows I don&#8217;t much like that crazy invention called a Book. However, being here I&#8217;ve already finished 4 books, all of which I can highly recommend.'."\n\n".'Agile Software Development with Scrum, by Ken Schwaber and Mike Beedle'."\n".'Domain-Driven Design: Tackling Complexity in the [...]', $entry->getDescription());
  165. }
  166. public function testGetsEntryContent()
  167. {
  168. $feed = Zend_Feed_Reader::importString(
  169. file_get_contents($this->_feedSamplePath)
  170. );
  171. $entry = $feed->current();
  172. $this->assertEquals('<p>Being in New Zealand does strange things to a person. Everybody who knows me, knows I don&#8217;t much like that crazy invention called a Book. However, being here I&#8217;ve already finished 4 books, all of which I can highly recommend.</p><ul><li><a href="http://www.amazon.com/Agile-Software-Development-Scrum/dp/0130676349/">Agile Software Development with Scrum, by Ken Schwaber and Mike Beedle</a></li><li><a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/">Domain-Driven Design: Tackling Complexity in the Heart of Software, by Eric Evans</a></li><li><a href="http://www.amazon.com/Enterprise-Application-Architecture-Addison-Wesley-Signature/dp/0321127420/">Patterns of Enterprise Application Architecture, by Martin Fowler</a></li><li><a href="http://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Technology/dp/0201485672/">Refactoring: Improving the Design of Existing Code by Martin Fowler</a></li></ul><p>Next up: <a href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/">Design Patterns: Elements of Reusable Object-Oriented Software, by the Gang of Four</a>. Yes, talk about classics and shame on me for not having ordered it sooner! Also reading <a href="http://www.amazon.com/Implementation-Patterns-Addison-Wesley-Signature-Kent/dp/0321413091/">Implementation Patterns, by Kent Beck</a> at the moment.</p>', str_replace("\n",'',$entry->getContent()));
  173. }
  174. public function testGetsEntryLinks()
  175. {
  176. $feed = Zend_Feed_Reader::importString(
  177. file_get_contents($this->_feedSamplePath)
  178. );
  179. $entry = $feed->current();
  180. $this->assertEquals(array('http://www.norm2782.com/2009/03/wth-reading-books/'), $entry->getLinks());
  181. }
  182. public function testGetsEntryLink()
  183. {
  184. $feed = Zend_Feed_Reader::importString(
  185. file_get_contents($this->_feedSamplePath)
  186. );
  187. $entry = $feed->current();
  188. $this->assertEquals('http://www.norm2782.com/2009/03/wth-reading-books/', $entry->getLink());
  189. }
  190. public function testGetsEntryPermaLink()
  191. {
  192. $feed = Zend_Feed_Reader::importString(
  193. file_get_contents($this->_feedSamplePath)
  194. );
  195. $entry = $feed->current();
  196. $this->assertEquals('http://www.norm2782.com/2009/03/wth-reading-books/',
  197. $entry->getPermaLink());
  198. }
  199. public function testGetsEntryEncoding()
  200. {
  201. $feed = Zend_Feed_Reader::importString(
  202. file_get_contents($this->_feedSamplePath)
  203. );
  204. $entry = $feed->current();
  205. $this->assertEquals('UTF-8', $entry->getEncoding());
  206. }
  207. }