WordpressRss2DcAtomTest.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. require_once 'PHPUnit/Framework/TestCase.php';
  3. require_once 'Zend/Feed/Reader.php';
  4. class Zend_Feed_Reader_Integration_WordpressRss2DcAtomTest extends PHPUnit_Framework_TestCase
  5. {
  6. protected $_feedSamplePath = null;
  7. public function setup()
  8. {
  9. $this->_feedSamplePath = dirname(__FILE__) . '/_files/wordpress-rss2-dc-atom.xml';
  10. }
  11. /**
  12. * Feed level testing
  13. */
  14. public function testGetsTitle()
  15. {
  16. $feed = Zend_Feed_Reader::importString(
  17. file_get_contents($this->_feedSamplePath)
  18. );
  19. $this->assertEquals('Norm 2782', $feed->getTitle());
  20. }
  21. public function testGetsAuthors()
  22. {
  23. $feed = Zend_Feed_Reader::importString(
  24. file_get_contents($this->_feedSamplePath)
  25. );
  26. $this->assertEquals(array('norm2782'), $feed->getAuthors());
  27. }
  28. public function testGetsSingleAuthor()
  29. {
  30. $feed = Zend_Feed_Reader::importString(
  31. file_get_contents($this->_feedSamplePath)
  32. );
  33. $this->assertEquals('norm2782', $feed->getAuthor());
  34. }
  35. public function testGetsCopyright()
  36. {
  37. $feed = Zend_Feed_Reader::importString(
  38. file_get_contents($this->_feedSamplePath)
  39. );
  40. $this->assertEquals(null, $feed->getCopyright());
  41. }
  42. public function testGetsDescription()
  43. {
  44. $feed = Zend_Feed_Reader::importString(
  45. file_get_contents($this->_feedSamplePath)
  46. );
  47. $this->assertEquals('Why are you here?', $feed->getDescription());
  48. }
  49. public function testGetsLanguage()
  50. {
  51. $feed = Zend_Feed_Reader::importString(
  52. file_get_contents($this->_feedSamplePath)
  53. );
  54. $this->assertEquals('en', $feed->getLanguage());
  55. }
  56. public function testGetsLink()
  57. {
  58. $feed = Zend_Feed_Reader::importString(
  59. file_get_contents($this->_feedSamplePath)
  60. );
  61. $this->assertEquals('http://www.norm2782.com', $feed->getLink());
  62. }
  63. public function testGetsEncoding()
  64. {
  65. $feed = Zend_Feed_Reader::importString(
  66. file_get_contents($this->_feedSamplePath)
  67. );
  68. $this->assertEquals('UTF-8', $feed->getEncoding());
  69. }
  70. public function testGetsEntryCount()
  71. {
  72. $feed = Zend_Feed_Reader::importString(
  73. file_get_contents($this->_feedSamplePath)
  74. );
  75. $this->assertEquals(10, $feed->count());
  76. }
  77. /**
  78. * Entry level testing
  79. */
  80. public function testGetsEntryId()
  81. {
  82. $feed = Zend_Feed_Reader::importString(
  83. file_get_contents($this->_feedSamplePath)
  84. );
  85. $entry = $feed->current();
  86. $this->assertEquals('http://www.norm2782.com/?p=114', $entry->getId());
  87. }
  88. public function testGetsEntryTitle()
  89. {
  90. $feed = Zend_Feed_Reader::importString(
  91. file_get_contents($this->_feedSamplePath)
  92. );
  93. $entry = $feed->current();
  94. /**
  95. * Note: The three dots below is actually a single Unicode character
  96. * called the "three dot leader". Don't replace in error!
  97. */
  98. $this->assertEquals('Wth… reading books?', $entry->getTitle());
  99. }
  100. public function testGetsEntryAuthors()
  101. {
  102. $feed = Zend_Feed_Reader::importString(
  103. file_get_contents($this->_feedSamplePath)
  104. );
  105. $entry = $feed->current();
  106. $this->assertEquals(array('norm2782'), $entry->getAuthors());
  107. }
  108. public function testGetsEntrySingleAuthor()
  109. {
  110. $feed = Zend_Feed_Reader::importString(
  111. file_get_contents($this->_feedSamplePath)
  112. );
  113. $entry = $feed->current();
  114. $this->assertEquals('norm2782', $entry->getAuthor());
  115. }
  116. public function testGetsEntryDescription()
  117. {
  118. $feed = Zend_Feed_Reader::importString(
  119. file_get_contents($this->_feedSamplePath)
  120. );
  121. $entry = $feed->current();
  122. /**
  123. * Note: "’" is not the same as "'" - don't replace in error
  124. */
  125. $this->assertEquals('Being in New Zealand does strange things to a person. Everybody who knows me, knows I don’t much like that crazy invention called a Book. However, being here I’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());
  126. }
  127. public function testGetsEntryContent()
  128. {
  129. $feed = Zend_Feed_Reader::importString(
  130. file_get_contents($this->_feedSamplePath)
  131. );
  132. $entry = $feed->current();
  133. $this->assertEquals('<p>Being in New Zealand does strange things to a person. Everybody who knows me, knows I don’t much like that crazy invention called a Book. However, being here I’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());
  134. }
  135. public function testGetsEntryLinks()
  136. {
  137. $feed = Zend_Feed_Reader::importString(
  138. file_get_contents($this->_feedSamplePath)
  139. );
  140. $entry = $feed->current();
  141. $this->assertEquals(array('http://www.norm2782.com/2009/03/wth-reading-books/'), $entry->getLinks());
  142. }
  143. public function testGetsEntryLink()
  144. {
  145. $feed = Zend_Feed_Reader::importString(
  146. file_get_contents($this->_feedSamplePath)
  147. );
  148. $entry = $feed->current();
  149. $this->assertEquals('http://www.norm2782.com/2009/03/wth-reading-books/', $entry->getLink());
  150. }
  151. public function testGetsEntryPermaLink()
  152. {
  153. $feed = Zend_Feed_Reader::importString(
  154. file_get_contents($this->_feedSamplePath)
  155. );
  156. $entry = $feed->current();
  157. $this->assertEquals('http://www.norm2782.com/2009/03/wth-reading-books/',
  158. $entry->getPermaLink());
  159. }
  160. public function testGetsEntryEncoding()
  161. {
  162. $feed = Zend_Feed_Reader::importString(
  163. file_get_contents($this->_feedSamplePath)
  164. );
  165. $entry = $feed->current();
  166. $this->assertEquals('UTF-8', $entry->getEncoding());
  167. }
  168. }