WordpressAtom10Test.php 8.8 KB

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