WordpressAtom10Test.php 7.2 KB

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