WordpressAtom10Test.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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-2009 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 'PHPUnit/Framework/TestCase.php';
  23. require_once 'Zend/Feed/Reader.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Feed
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Feed
  31. * @group Zend_Feed_Reader
  32. */
  33. class Zend_Feed_Reader_Integration_WordpressAtom10Test extends PHPUnit_Framework_TestCase
  34. {
  35. protected $_feedSamplePath = null;
  36. public function setup()
  37. {
  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('norm2782'), $feed->getAuthors());
  64. }
  65. public function testGetsSingleAuthor()
  66. {
  67. $feed = Zend_Feed_Reader::importString(
  68. file_get_contents($this->_feedSamplePath)
  69. );
  70. $this->assertEquals('norm2782', $feed->getAuthor());
  71. }
  72. public function testGetsCopyright()
  73. {
  74. $feed = Zend_Feed_Reader::importString(
  75. file_get_contents($this->_feedSamplePath)
  76. );
  77. $this->assertEquals(null, $feed->getCopyright());
  78. }
  79. public function testGetsDescription()
  80. {
  81. $feed = Zend_Feed_Reader::importString(
  82. file_get_contents($this->_feedSamplePath)
  83. );
  84. $this->assertEquals('Why are you here?', $feed->getDescription());
  85. }
  86. public function testGetsLanguage()
  87. {
  88. $feed = Zend_Feed_Reader::importString(
  89. file_get_contents($this->_feedSamplePath)
  90. );
  91. $this->assertEquals('en', $feed->getLanguage());
  92. }
  93. public function testGetsLink()
  94. {
  95. $feed = Zend_Feed_Reader::importString(
  96. file_get_contents($this->_feedSamplePath)
  97. );
  98. $this->assertEquals('http://www.norm2782.com', $feed->getLink());
  99. }
  100. public function testGetsEncoding()
  101. {
  102. $feed = Zend_Feed_Reader::importString(
  103. file_get_contents($this->_feedSamplePath)
  104. );
  105. $this->assertEquals('UTF-8', $feed->getEncoding());
  106. }
  107. public function testGetsEntryCount()
  108. {
  109. $feed = Zend_Feed_Reader::importString(
  110. file_get_contents($this->_feedSamplePath)
  111. );
  112. $this->assertEquals(10, $feed->count());
  113. }
  114. /**
  115. * Entry level testing
  116. */
  117. public function testGetsEntryId()
  118. {
  119. $feed = Zend_Feed_Reader::importString(
  120. file_get_contents($this->_feedSamplePath)
  121. );
  122. $entry = $feed->current();
  123. $this->assertEquals('http://www.norm2782.com/?p=114', $entry->getId());
  124. }
  125. public function testGetsEntryTitle()
  126. {
  127. $feed = Zend_Feed_Reader::importString(
  128. file_get_contents($this->_feedSamplePath)
  129. );
  130. $entry = $feed->current();
  131. /**
  132. * Note: The three dots below is actually a single Unicode character
  133. * called the "three dot leader". Don't replace in error!
  134. */
  135. $this->assertEquals('Wth… reading books?', $entry->getTitle());
  136. }
  137. public function testGetsEntryAuthors()
  138. {
  139. $feed = Zend_Feed_Reader::importString(
  140. file_get_contents($this->_feedSamplePath)
  141. );
  142. $entry = $feed->current();
  143. $this->assertEquals(array('norm2782'), $entry->getAuthors());
  144. }
  145. public function testGetsEntrySingleAuthor()
  146. {
  147. $feed = Zend_Feed_Reader::importString(
  148. file_get_contents($this->_feedSamplePath)
  149. );
  150. $entry = $feed->current();
  151. $this->assertEquals('norm2782', $entry->getAuthor());
  152. }
  153. public function testGetsEntryDescription()
  154. {
  155. $feed = Zend_Feed_Reader::importString(
  156. file_get_contents($this->_feedSamplePath)
  157. );
  158. $entry = $feed->current();
  159. /**
  160. * Note: "’" is not the same as "'" - don't replace in error
  161. */
  162. $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());
  163. }
  164. public function testGetsEntryContent()
  165. {
  166. $feed = Zend_Feed_Reader::importString(
  167. file_get_contents($this->_feedSamplePath)
  168. );
  169. $entry = $feed->current();
  170. $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());
  171. }
  172. public function testGetsEntryLinks()
  173. {
  174. $feed = Zend_Feed_Reader::importString(
  175. file_get_contents($this->_feedSamplePath)
  176. );
  177. $entry = $feed->current();
  178. $this->assertEquals(array('http://www.norm2782.com/2009/03/wth-reading-books/'), $entry->getLinks());
  179. }
  180. public function testGetsEntryLink()
  181. {
  182. $feed = Zend_Feed_Reader::importString(
  183. file_get_contents($this->_feedSamplePath)
  184. );
  185. $entry = $feed->current();
  186. $this->assertEquals('http://www.norm2782.com/2009/03/wth-reading-books/', $entry->getLink());
  187. }
  188. public function testGetsEntryPermaLink()
  189. {
  190. $feed = Zend_Feed_Reader::importString(
  191. file_get_contents($this->_feedSamplePath)
  192. );
  193. $entry = $feed->current();
  194. $this->assertEquals('http://www.norm2782.com/2009/03/wth-reading-books/',
  195. $entry->getPermaLink());
  196. }
  197. public function testGetsEntryEncoding()
  198. {
  199. $feed = Zend_Feed_Reader::importString(
  200. file_get_contents($this->_feedSamplePath)
  201. );
  202. $entry = $feed->current();
  203. $this->assertEquals('UTF-8', $entry->getEncoding());
  204. }
  205. }