AtomTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. $this->_feedSamplePath = dirname(__FILE__) . '/_files/Atom';
  10. }
  11. /**
  12. * Get Id (Unencoded Text)
  13. */
  14. public function testGetsIdFromAtom03()
  15. {
  16. $feed = Zend_Feed_Reader::importString(
  17. file_get_contents($this->_feedSamplePath . '/id/plain/atom03.xml')
  18. );
  19. $entry = $feed->current();
  20. $this->assertEquals('1', $entry->getId());
  21. }
  22. public function testGetsIdFromAtom10()
  23. {
  24. $feed = Zend_Feed_Reader::importString(
  25. file_get_contents($this->_feedSamplePath . '/id/plain/atom10.xml')
  26. );
  27. $entry = $feed->current();
  28. $this->assertEquals('1', $entry->getId());
  29. }
  30. /**
  31. * Get creation date (Unencoded Text)
  32. */
  33. public function testGetsDateCreatedFromAtom03()
  34. {
  35. $feed = Zend_Feed_Reader::importString(
  36. file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom03.xml')
  37. );
  38. $entry = $feed->current();
  39. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  40. $entry->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  41. }
  42. public function testGetsDateCreatedFromAtom10()
  43. {
  44. $feed = Zend_Feed_Reader::importString(
  45. file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom10.xml')
  46. );
  47. $entry = $feed->current();
  48. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  49. $entry->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  50. }
  51. /**
  52. * Get modification date (Unencoded Text)
  53. */
  54. public function testGetsDateModifiedFromAtom03()
  55. {
  56. $feed = Zend_Feed_Reader::importString(
  57. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom03.xml')
  58. );
  59. $entry = $feed->current();
  60. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  61. $entry->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  62. }
  63. public function testGetsDateModifiedFromAtom10()
  64. {
  65. $feed = Zend_Feed_Reader::importString(
  66. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom10.xml')
  67. );
  68. $entry = $feed->current();
  69. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  70. $entry->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  71. }
  72. /**
  73. * Get Title (Unencoded Text)
  74. */
  75. public function testGetsTitleFromAtom03()
  76. {
  77. $feed = Zend_Feed_Reader::importString(
  78. file_get_contents($this->_feedSamplePath . '/title/plain/atom03.xml')
  79. );
  80. $entry = $feed->current();
  81. $this->assertEquals('Entry Title', $entry->getTitle());
  82. }
  83. public function testGetsTitleFromAtom10()
  84. {
  85. $feed = Zend_Feed_Reader::importString(
  86. file_get_contents($this->_feedSamplePath . '/title/plain/atom10.xml')
  87. );
  88. $entry = $feed->current();
  89. $this->assertEquals('Entry Title', $entry->getTitle());
  90. }
  91. /**
  92. * Get Authors (Unencoded Text)
  93. */
  94. public function testGetsAuthorsFromAtom03()
  95. {
  96. $feed = Zend_Feed_Reader::importString(
  97. file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
  98. );
  99. $authors = array(
  100. 0 => 'joe@example.com (Joe Bloggs)',
  101. 1 => 'Joe Bloggs',
  102. 3 => 'joe@example.com',
  103. 4 => 'http://www.example.com',
  104. 6 => 'jane@example.com (Jane Bloggs)'
  105. );
  106. $entry = $feed->current();
  107. $this->assertEquals($authors, $entry->getAuthors());
  108. }
  109. public function testGetsAuthorsFromAtom10()
  110. {
  111. $feed = Zend_Feed_Reader::importString(
  112. file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
  113. );
  114. $authors = array(
  115. 0 => 'joe@example.com (Joe Bloggs)',
  116. 1 => 'Joe Bloggs',
  117. 3 => 'joe@example.com',
  118. 4 => 'http://www.example.com',
  119. 6 => 'jane@example.com (Jane Bloggs)'
  120. );
  121. $entry = $feed->current();
  122. $this->assertEquals($authors, $entry->getAuthors());
  123. }
  124. /**
  125. * Get Author (Unencoded Text)
  126. */
  127. public function testGetsAuthorFromAtom03()
  128. {
  129. $feed = Zend_Feed_Reader::importString(
  130. file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
  131. );
  132. $entry = $feed->current();
  133. $this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
  134. }
  135. public function testGetsAuthorFromAtom10()
  136. {
  137. $feed = Zend_Feed_Reader::importString(
  138. file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
  139. );
  140. $entry = $feed->current();
  141. $this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
  142. }
  143. /**
  144. * Get Description (Unencoded Text)
  145. */
  146. public function testGetsDescriptionFromAtom03()
  147. {
  148. $feed = Zend_Feed_Reader::importString(
  149. file_get_contents($this->_feedSamplePath . '/description/plain/atom03.xml')
  150. );
  151. $entry = $feed->current();
  152. $this->assertEquals('Entry Description', $entry->getDescription());
  153. }
  154. public function testGetsDescriptionFromAtom10()
  155. {
  156. $feed = Zend_Feed_Reader::importString(
  157. file_get_contents($this->_feedSamplePath . '/description/plain/atom10.xml')
  158. );
  159. $entry = $feed->current();
  160. $this->assertEquals('Entry Description', $entry->getDescription());
  161. }
  162. /**
  163. * Get Content (Unencoded Text)
  164. */
  165. public function testGetsContentFromAtom03()
  166. {
  167. $feed = Zend_Feed_Reader::importString(
  168. file_get_contents($this->_feedSamplePath . '/content/plain/atom03.xml')
  169. );
  170. $entry = $feed->current();
  171. $this->assertEquals('Entry Content', $entry->getContent());
  172. }
  173. public function testGetsContentFromAtom10()
  174. {
  175. $feed = Zend_Feed_Reader::importString(
  176. file_get_contents($this->_feedSamplePath . '/content/plain/atom10.xml')
  177. );
  178. $entry = $feed->current();
  179. $this->assertEquals('Entry Content', $entry->getContent());
  180. }
  181. /**
  182. * Get Link (Unencoded Text)
  183. */
  184. public function testGetsLinkFromAtom03()
  185. {
  186. $feed = Zend_Feed_Reader::importString(
  187. file_get_contents($this->_feedSamplePath . '/link/plain/atom03.xml')
  188. );
  189. $entry = $feed->current();
  190. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  191. }
  192. public function testGetsLinkFromAtom10()
  193. {
  194. $feed = Zend_Feed_Reader::importString(
  195. file_get_contents($this->_feedSamplePath . '/link/plain/atom10.xml')
  196. );
  197. $entry = $feed->current();
  198. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  199. }
  200. }