WordpressRss2DcAtomTest.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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_WordpressRss2DcAtomTest 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-rss2-dc-atom.xml';
  39. }
  40. /**
  41. * Feed level testing
  42. */
  43. public function testGetsTitle()
  44. {
  45. $feed = Zend_Feed_Reader::importString(
  46. file_get_contents($this->_feedSamplePath)
  47. );
  48. $this->assertEquals('Norm 2782', $feed->getTitle());
  49. }
  50. public function testGetsAuthors()
  51. {
  52. $feed = Zend_Feed_Reader::importString(
  53. file_get_contents($this->_feedSamplePath)
  54. );
  55. $this->assertEquals(array(
  56. array('name'=>'norm2782')
  57. ), (array) $feed->getAuthors());
  58. }
  59. public function testGetsSingleAuthor()
  60. {
  61. $feed = Zend_Feed_Reader::importString(
  62. file_get_contents($this->_feedSamplePath)
  63. );
  64. $this->assertEquals(array('name'=>'norm2782'), $feed->getAuthor());
  65. }
  66. public function testGetsCopyright()
  67. {
  68. $feed = Zend_Feed_Reader::importString(
  69. file_get_contents($this->_feedSamplePath)
  70. );
  71. $this->assertEquals(null, $feed->getCopyright());
  72. }
  73. public function testGetsDescription()
  74. {
  75. $feed = Zend_Feed_Reader::importString(
  76. file_get_contents($this->_feedSamplePath)
  77. );
  78. $this->assertEquals('Why are you here?', $feed->getDescription());
  79. }
  80. public function testGetsLanguage()
  81. {
  82. $feed = Zend_Feed_Reader::importString(
  83. file_get_contents($this->_feedSamplePath)
  84. );
  85. $this->assertEquals('en', $feed->getLanguage());
  86. }
  87. public function testGetsLink()
  88. {
  89. $feed = Zend_Feed_Reader::importString(
  90. file_get_contents($this->_feedSamplePath)
  91. );
  92. $this->assertEquals('http://www.norm2782.com', $feed->getLink());
  93. }
  94. public function testGetsEncoding()
  95. {
  96. $feed = Zend_Feed_Reader::importString(
  97. file_get_contents($this->_feedSamplePath)
  98. );
  99. $this->assertEquals('UTF-8', $feed->getEncoding());
  100. }
  101. public function testGetsEntryCount()
  102. {
  103. $feed = Zend_Feed_Reader::importString(
  104. file_get_contents($this->_feedSamplePath)
  105. );
  106. $this->assertEquals(10, $feed->count());
  107. }
  108. /**
  109. * Entry level testing
  110. */
  111. public function testGetsEntryId()
  112. {
  113. $feed = Zend_Feed_Reader::importString(
  114. file_get_contents($this->_feedSamplePath)
  115. );
  116. $entry = $feed->current();
  117. $this->assertEquals('http://www.norm2782.com/?p=114', $entry->getId());
  118. }
  119. public function testGetsEntryTitle()
  120. {
  121. $feed = Zend_Feed_Reader::importString(
  122. file_get_contents($this->_feedSamplePath)
  123. );
  124. $entry = $feed->current();
  125. /**
  126. * Note: The three dots below is actually a single Unicode character
  127. * called the "three dot leader". Don't replace in error!
  128. */
  129. $this->assertEquals('Wth… reading books?', $entry->getTitle());
  130. }
  131. public function testGetsEntryAuthors()
  132. {
  133. $feed = Zend_Feed_Reader::importString(
  134. file_get_contents($this->_feedSamplePath)
  135. );
  136. $entry = $feed->current();
  137. $this->assertEquals(array(array('name'=>'norm2782')), (array) $entry->getAuthors());
  138. }
  139. public function testGetsEntrySingleAuthor()
  140. {
  141. $feed = Zend_Feed_Reader::importString(
  142. file_get_contents($this->_feedSamplePath)
  143. );
  144. $entry = $feed->current();
  145. $this->assertEquals(array('name'=>'norm2782'), $entry->getAuthor());
  146. }
  147. public function testGetsEntryDescription()
  148. {
  149. $feed = Zend_Feed_Reader::importString(
  150. file_get_contents($this->_feedSamplePath)
  151. );
  152. $entry = $feed->current();
  153. /**
  154. * Note: "’" is not the same as "'" - don't replace in error
  155. */
  156. $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());
  157. }
  158. public function testGetsEntryContent()
  159. {
  160. $feed = Zend_Feed_Reader::importString(
  161. file_get_contents($this->_feedSamplePath)
  162. );
  163. $entry = $feed->current();
  164. $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>'."\n".'<ul>'."\n".'<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>'."\n".'<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>'."\n".'<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>'."\n".'<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>'."\n".'</ul>'."\n".'<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>'."\n", $entry->getContent());
  165. }
  166. public function testGetsEntryLinks()
  167. {
  168. $feed = Zend_Feed_Reader::importString(
  169. file_get_contents($this->_feedSamplePath)
  170. );
  171. $entry = $feed->current();
  172. $this->assertEquals(array('http://www.norm2782.com/2009/03/wth-reading-books/'), $entry->getLinks());
  173. }
  174. public function testGetsEntryLink()
  175. {
  176. $feed = Zend_Feed_Reader::importString(
  177. file_get_contents($this->_feedSamplePath)
  178. );
  179. $entry = $feed->current();
  180. $this->assertEquals('http://www.norm2782.com/2009/03/wth-reading-books/', $entry->getLink());
  181. }
  182. public function testGetsEntryPermaLink()
  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/',
  189. $entry->getPermaLink());
  190. }
  191. public function testGetsEntryEncoding()
  192. {
  193. $feed = Zend_Feed_Reader::importString(
  194. file_get_contents($this->_feedSamplePath)
  195. );
  196. $entry = $feed->current();
  197. $this->assertEquals('UTF-8', $entry->getEncoding());
  198. }
  199. }