AtomTest.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. require_once 'PHPUnit/Framework/TestCase.php';
  3. require_once 'Zend/Feed/Reader.php';
  4. class Zend_Feed_Reader_Entry_AtomTest extends PHPUnit_Framework_TestCase
  5. {
  6. protected $_feedSamplePath = null;
  7. public function setup()
  8. {
  9. if (Zend_Registry::isRegistered('Zend_Locale')) {
  10. $registry = Zend_Registry::getInstance();
  11. unset($registry['Zend_Locale']);
  12. }
  13. $this->_feedSamplePath = dirname(__FILE__) . '/_files/Atom';
  14. }
  15. /**
  16. * Get Id (Unencoded Text)
  17. */
  18. public function testGetsIdFromAtom03()
  19. {
  20. $feed = Zend_Feed_Reader::importString(
  21. file_get_contents($this->_feedSamplePath . '/id/plain/atom03.xml')
  22. );
  23. $entry = $feed->current();
  24. $this->assertEquals('1', $entry->getId());
  25. }
  26. public function testGetsIdFromAtom10()
  27. {
  28. $feed = Zend_Feed_Reader::importString(
  29. file_get_contents($this->_feedSamplePath . '/id/plain/atom10.xml')
  30. );
  31. $entry = $feed->current();
  32. $this->assertEquals('1', $entry->getId());
  33. }
  34. /**
  35. * Get creation date (Unencoded Text)
  36. */
  37. public function testGetsDateCreatedFromAtom03()
  38. {
  39. $feed = Zend_Feed_Reader::importString(
  40. file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom03.xml')
  41. );
  42. $entry = $feed->current();
  43. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  44. $entry->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  45. }
  46. public function testGetsDateCreatedFromAtom10()
  47. {
  48. $feed = Zend_Feed_Reader::importString(
  49. file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom10.xml')
  50. );
  51. $entry = $feed->current();
  52. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  53. $entry->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  54. }
  55. /**
  56. * Get modification date (Unencoded Text)
  57. */
  58. public function testGetsDateModifiedFromAtom03()
  59. {
  60. $feed = Zend_Feed_Reader::importString(
  61. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom03.xml')
  62. );
  63. $entry = $feed->current();
  64. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  65. $entry->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  66. }
  67. public function testGetsDateModifiedFromAtom10()
  68. {
  69. $feed = Zend_Feed_Reader::importString(
  70. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom10.xml')
  71. );
  72. $entry = $feed->current();
  73. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  74. $entry->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  75. }
  76. /**
  77. * Get Title (Unencoded Text)
  78. */
  79. public function testGetsTitleFromAtom03()
  80. {
  81. $feed = Zend_Feed_Reader::importString(
  82. file_get_contents($this->_feedSamplePath . '/title/plain/atom03.xml')
  83. );
  84. $entry = $feed->current();
  85. $this->assertEquals('Entry Title', $entry->getTitle());
  86. }
  87. public function testGetsTitleFromAtom10()
  88. {
  89. $feed = Zend_Feed_Reader::importString(
  90. file_get_contents($this->_feedSamplePath . '/title/plain/atom10.xml')
  91. );
  92. $entry = $feed->current();
  93. $this->assertEquals('Entry Title', $entry->getTitle());
  94. }
  95. /**
  96. * Get Authors (Unencoded Text)
  97. */
  98. public function testGetsAuthorsFromAtom03()
  99. {
  100. $feed = Zend_Feed_Reader::importString(
  101. file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
  102. );
  103. $authors = array(
  104. 0 => 'joe@example.com (Joe Bloggs)',
  105. 1 => 'Joe Bloggs',
  106. 3 => 'joe@example.com',
  107. 4 => 'http://www.example.com',
  108. 6 => 'jane@example.com (Jane Bloggs)'
  109. );
  110. $entry = $feed->current();
  111. $this->assertEquals($authors, $entry->getAuthors());
  112. }
  113. public function testGetsAuthorsFromAtom10()
  114. {
  115. $feed = Zend_Feed_Reader::importString(
  116. file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
  117. );
  118. $authors = array(
  119. 0 => 'joe@example.com (Joe Bloggs)',
  120. 1 => 'Joe Bloggs',
  121. 3 => 'joe@example.com',
  122. 4 => 'http://www.example.com',
  123. 6 => 'jane@example.com (Jane Bloggs)'
  124. );
  125. $entry = $feed->current();
  126. $this->assertEquals($authors, $entry->getAuthors());
  127. }
  128. /**
  129. * Get Author (Unencoded Text)
  130. */
  131. public function testGetsAuthorFromAtom03()
  132. {
  133. $feed = Zend_Feed_Reader::importString(
  134. file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
  135. );
  136. $entry = $feed->current();
  137. $this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
  138. }
  139. public function testGetsAuthorFromAtom10()
  140. {
  141. $feed = Zend_Feed_Reader::importString(
  142. file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
  143. );
  144. $entry = $feed->current();
  145. $this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
  146. }
  147. /**
  148. * Get Description (Unencoded Text)
  149. */
  150. public function testGetsDescriptionFromAtom03()
  151. {
  152. $feed = Zend_Feed_Reader::importString(
  153. file_get_contents($this->_feedSamplePath . '/description/plain/atom03.xml')
  154. );
  155. $entry = $feed->current();
  156. $this->assertEquals('Entry Description', $entry->getDescription());
  157. }
  158. public function testGetsDescriptionFromAtom10()
  159. {
  160. $feed = Zend_Feed_Reader::importString(
  161. file_get_contents($this->_feedSamplePath . '/description/plain/atom10.xml')
  162. );
  163. $entry = $feed->current();
  164. $this->assertEquals('Entry Description', $entry->getDescription());
  165. }
  166. /**
  167. * Get enclosure
  168. */
  169. public function testGetsEnclosureFromAtom03()
  170. {
  171. $feed = Zend_Feed_Reader::importString(
  172. file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom03.xml')
  173. );
  174. $entry = $feed->current();
  175. $expected = new stdClass();
  176. $expected->url = 'http://www.example.org/myaudiofile.mp3';
  177. $expected->length = '1234';
  178. $expected->type = 'audio/mpeg';
  179. $this->assertEquals($expected, $entry->getEnclosure());
  180. }
  181. public function testGetsEnclosureFromAtom10()
  182. {
  183. $feed = Zend_Feed_Reader::importString(
  184. file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom10.xml')
  185. );
  186. $entry = $feed->current();
  187. $expected = new stdClass();
  188. $expected->url = 'http://www.example.org/myaudiofile.mp3';
  189. $expected->length = '1234';
  190. $expected->type = 'audio/mpeg';
  191. $this->assertEquals($expected, $entry->getEnclosure());
  192. }
  193. /**
  194. * Get Content (Unencoded Text)
  195. */
  196. public function testGetsContentFromAtom03()
  197. {
  198. $feed = Zend_Feed_Reader::importString(
  199. file_get_contents($this->_feedSamplePath . '/content/plain/atom03.xml')
  200. );
  201. $entry = $feed->current();
  202. $this->assertEquals('Entry Content', $entry->getContent());
  203. }
  204. public function testGetsContentFromAtom10()
  205. {
  206. $feed = Zend_Feed_Reader::importString(
  207. file_get_contents($this->_feedSamplePath . '/content/plain/atom10.xml')
  208. );
  209. $entry = $feed->current();
  210. $this->assertEquals('Entry Content', $entry->getContent());
  211. }
  212. /**
  213. * Get Link (Unencoded Text)
  214. */
  215. public function testGetsLinkFromAtom03()
  216. {
  217. $feed = Zend_Feed_Reader::importString(
  218. file_get_contents($this->_feedSamplePath . '/link/plain/atom03.xml')
  219. );
  220. $entry = $feed->current();
  221. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  222. }
  223. public function testGetsLinkFromAtom10()
  224. {
  225. $feed = Zend_Feed_Reader::importString(
  226. file_get_contents($this->_feedSamplePath . '/link/plain/atom10.xml')
  227. );
  228. $entry = $feed->current();
  229. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  230. }
  231. }