AtomTest.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. require_once 'PHPUnit/Framework/TestCase.php';
  3. require_once 'Zend/Feed/Reader.php';
  4. class Zend_Feed_Reader_Feed_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 Title (Unencoded Text)
  17. */
  18. public function testGetsTitleFromAtom03()
  19. {
  20. $feed = Zend_Feed_Reader::importString(
  21. file_get_contents($this->_feedSamplePath.'/title/plain/atom03.xml')
  22. );
  23. $this->assertEquals('My Title', $feed->getTitle());
  24. }
  25. public function testGetsTitleFromAtom10()
  26. {
  27. $feed = Zend_Feed_Reader::importString(
  28. file_get_contents($this->_feedSamplePath.'/title/plain/atom10.xml')
  29. );
  30. $this->assertEquals('My Title', $feed->getTitle());
  31. }
  32. /**
  33. * Get Authors (Unencoded Text)
  34. */
  35. public function testGetsAuthorArrayFromAtom03()
  36. {
  37. $feed = Zend_Feed_Reader::importString(
  38. file_get_contents($this->_feedSamplePath.'/author/plain/atom03.xml')
  39. );
  40. $authors = array(
  41. 0 => 'joe@example.com (Joe Bloggs)',
  42. 1 => 'Joe Bloggs',
  43. 3 => 'joe@example.com',
  44. 4 => 'http://www.example.com',
  45. 6 => 'jane@example.com (Jane Bloggs)'
  46. );
  47. $this->assertEquals($authors, $feed->getAuthors());
  48. }
  49. public function testGetsAuthorArrayFromAtom10()
  50. {
  51. $feed = Zend_Feed_Reader::importString(
  52. file_get_contents($this->_feedSamplePath.'/author/plain/atom10.xml')
  53. );
  54. $authors = array(
  55. 0 => 'joe@example.com (Joe Bloggs)',
  56. 1 => 'Joe Bloggs',
  57. 3 => 'joe@example.com',
  58. 4 => 'http://www.example.com',
  59. 6 => 'jane@example.com (Jane Bloggs)'
  60. );
  61. $this->assertEquals($authors, $feed->getAuthors());
  62. }
  63. /**
  64. * Get Single Author (Unencoded Text)
  65. */
  66. public function testGetsSingleAuthorFromAtom03()
  67. {
  68. $feed = Zend_Feed_Reader::importString(
  69. file_get_contents($this->_feedSamplePath.'/author/plain/atom03.xml')
  70. );
  71. $this->assertEquals('joe@example.com (Joe Bloggs)', $feed->getAuthor());
  72. }
  73. public function testGetsSingleAuthorFromAtom10()
  74. {
  75. $feed = Zend_Feed_Reader::importString(
  76. file_get_contents($this->_feedSamplePath.'/author/plain/atom10.xml')
  77. );
  78. $this->assertEquals('joe@example.com (Joe Bloggs)', $feed->getAuthor());
  79. }
  80. /**
  81. * Get creation date (Unencoded Text)
  82. */
  83. public function testGetsDateCreatedFromAtom03()
  84. {
  85. $feed = Zend_Feed_Reader::importString(
  86. file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom03.xml')
  87. );
  88. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  89. $feed->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  90. }
  91. public function testGetsDateCreatedFromAtom10()
  92. {
  93. $feed = Zend_Feed_Reader::importString(
  94. file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom10.xml')
  95. );
  96. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  97. $feed->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  98. }
  99. /**
  100. * Get modification date (Unencoded Text)
  101. */
  102. public function testGetsDateModifiedFromAtom03()
  103. {
  104. $feed = Zend_Feed_Reader::importString(
  105. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom03.xml')
  106. );
  107. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  108. $feed->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  109. }
  110. public function testGetsDateModifiedFromAtom10()
  111. {
  112. $feed = Zend_Feed_Reader::importString(
  113. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom10.xml')
  114. );
  115. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  116. $feed->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  117. }
  118. /**
  119. * Get Generator (Unencoded Text)
  120. */
  121. public function testGetsGeneratorFromAtom03()
  122. {
  123. $feed = Zend_Feed_Reader::importString(
  124. file_get_contents($this->_feedSamplePath.'/generator/plain/atom03.xml')
  125. );
  126. $this->assertEquals('Zend_Feed', $feed->getGenerator());
  127. }
  128. public function testGetsGeneratorFromAtom10()
  129. {
  130. $feed = Zend_Feed_Reader::importString(
  131. file_get_contents($this->_feedSamplePath.'/generator/plain/atom10.xml')
  132. );
  133. $this->assertEquals('Zend_Feed', $feed->getGenerator());
  134. }
  135. /**
  136. * Get Copyright (Unencoded Text)
  137. */
  138. public function testGetsCopyrightFromAtom03()
  139. {
  140. $feed = Zend_Feed_Reader::importString(
  141. file_get_contents($this->_feedSamplePath.'/copyright/plain/atom03.xml')
  142. );
  143. $this->assertEquals('Copyright 2008', $feed->getCopyright());
  144. }
  145. public function testGetsCopyrightFromAtom10()
  146. {
  147. $feed = Zend_Feed_Reader::importString(
  148. file_get_contents($this->_feedSamplePath.'/copyright/plain/atom10.xml')
  149. );
  150. $this->assertEquals('Copyright 2008', $feed->getCopyright());
  151. }
  152. /**
  153. * Get Description (Unencoded Text)
  154. */
  155. public function testGetsDescriptionFromAtom03()
  156. {
  157. $feed = Zend_Feed_Reader::importString(
  158. file_get_contents($this->_feedSamplePath.'/description/plain/atom03.xml')
  159. );
  160. $this->assertEquals('My Description', $feed->getDescription());
  161. }
  162. public function testGetsDescriptionFromAtom10()
  163. {
  164. $feed = Zend_Feed_Reader::importString(
  165. file_get_contents($this->_feedSamplePath.'/description/plain/atom10.xml')
  166. );
  167. $this->assertEquals('My Description', $feed->getDescription());
  168. }
  169. /**
  170. * Get Id (Unencoded Text)
  171. */
  172. public function testGetsIdFromAtom03()
  173. {
  174. $feed = Zend_Feed_Reader::importString(
  175. file_get_contents($this->_feedSamplePath.'/id/plain/atom03.xml')
  176. );
  177. $this->assertEquals('123', $feed->getId());
  178. }
  179. public function testGetsIdFromAtom10()
  180. {
  181. $feed = Zend_Feed_Reader::importString(
  182. file_get_contents($this->_feedSamplePath.'/id/plain/atom10.xml')
  183. );
  184. $this->assertEquals('123', $feed->getId());
  185. }
  186. /**
  187. * Get Language (Unencoded Text)
  188. */
  189. public function testGetsLanguageFromAtom03()
  190. {
  191. $feed = Zend_Feed_Reader::importString(
  192. file_get_contents($this->_feedSamplePath.'/language/plain/atom03.xml')
  193. );
  194. $this->assertEquals('en-GB', $feed->getLanguage());
  195. }
  196. public function testGetsLanguageFromAtom10()
  197. {
  198. $feed = Zend_Feed_Reader::importString(
  199. file_get_contents($this->_feedSamplePath.'/language/plain/atom10.xml')
  200. );
  201. $this->assertEquals('en-GB', $feed->getLanguage());
  202. }
  203. /**
  204. * Get Link (Unencoded Text)
  205. */
  206. public function testGetsLinkFromAtom03()
  207. {
  208. $feed = Zend_Feed_Reader::importString(
  209. file_get_contents($this->_feedSamplePath.'/link/plain/atom03.xml')
  210. );
  211. $this->assertEquals('http://www.example.com', $feed->getLink());
  212. }
  213. public function testGetsLinkFromAtom10()
  214. {
  215. $feed = Zend_Feed_Reader::importString(
  216. file_get_contents($this->_feedSamplePath.'/link/plain/atom10.xml')
  217. );
  218. $this->assertEquals('http://www.example.com', $feed->getLink());
  219. }
  220. /**
  221. * Get Feed Link (Unencoded Text)
  222. */
  223. public function testGetsFeedLinkFromAtom03()
  224. {
  225. $feed = Zend_Feed_Reader::importString(
  226. file_get_contents($this->_feedSamplePath.'/feedlink/plain/atom03.xml')
  227. );
  228. $this->assertEquals('http://www.example.com/feed/atom', $feed->getFeedLink());
  229. }
  230. public function testGetsFeedLinkFromAtom10()
  231. {
  232. $feed = Zend_Feed_Reader::importString(
  233. file_get_contents($this->_feedSamplePath.'/feedlink/plain/atom10.xml')
  234. );
  235. $this->assertEquals('http://www.example.com/feed/atom', $feed->getFeedLink());
  236. }
  237. /**
  238. * Implements Countable
  239. */
  240. public function testCountableInterface()
  241. {
  242. $feed = Zend_Feed_Reader::importString(
  243. file_get_contents($this->_feedSamplePath.'/link/plain/atom10.xml')
  244. );
  245. $this->assertEquals(0, count($feed));
  246. }
  247. }