/tests/ZendTest/Feed/Reader/Entry/AtomStandaloneEntryTest.php

https://github.com/Ocramius/zf2 · PHP · 269 lines · 171 code · 27 blank · 71 comment · 0 complexity · 90cf3ec421c0c7a3520d63b94a732688 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace ZendTest\Feed\Reader\Entry;
  10. use DateTime;
  11. use Zend\Feed\Reader;
  12. /**
  13. * @group Zend_Feed
  14. * @group Zend_Feed_Reader
  15. */
  16. class AtomStandaloneEntryTest extends \PHPUnit_Framework_TestCase
  17. {
  18. protected $feedSamplePath = null;
  19. protected $expectedCats = array();
  20. protected $expectedCatsDc = array();
  21. public function setup()
  22. {
  23. Reader\Reader::reset();
  24. $this->feedSamplePath = dirname(__FILE__) . '/_files/AtomStandaloneEntry';
  25. $this->expectedCats = array(
  26. array(
  27. 'term' => 'topic1',
  28. 'scheme' => 'http://example.com/schema1',
  29. 'label' => 'topic1'
  30. ),
  31. array(
  32. 'term' => 'topic1',
  33. 'scheme' => 'http://example.com/schema2',
  34. 'label' => 'topic1'
  35. ),
  36. array(
  37. 'term' => 'cat_dog',
  38. 'scheme' => 'http://example.com/schema1',
  39. 'label' => 'Cat & Dog'
  40. )
  41. );
  42. $this->expectedCatsDc = array(
  43. array(
  44. 'term' => 'topic1',
  45. 'scheme' => null,
  46. 'label' => 'topic1'
  47. ),
  48. array(
  49. 'term' => 'topic2',
  50. 'scheme' => null,
  51. 'label' => 'topic2'
  52. )
  53. );
  54. }
  55. public function testReaderImportOfAtomEntryDocumentReturnsEntryClass()
  56. {
  57. $object = Reader\Reader::importString(
  58. file_get_contents($this->feedSamplePath . '/id/atom10.xml')
  59. );
  60. $this->assertTrue($object instanceof Reader\Entry\Atom);
  61. }
  62. /**
  63. * Get Id (Unencoded Text)
  64. * @group ZFR002
  65. */
  66. public function testGetsIdFromAtom10()
  67. {
  68. $entry = Reader\Reader::importString(
  69. file_get_contents($this->feedSamplePath . '/id/atom10.xml')
  70. );
  71. $this->assertEquals('1', $entry->getId());
  72. }
  73. /**
  74. * Get creation date (Unencoded Text)
  75. * @group ZFR002
  76. */
  77. public function testGetsDateCreatedFromAtom10()
  78. {
  79. $entry = Reader\Reader::importString(
  80. file_get_contents($this->feedSamplePath . '/datecreated/atom10.xml')
  81. );
  82. $edate = DateTime::createFromFormat(DateTime::ATOM, '2009-03-07T08:03:50Z');
  83. $this->assertEquals($edate, $entry->getDateCreated());
  84. }
  85. /**
  86. * Get modification date (Unencoded Text)
  87. * @group ZFR002
  88. */
  89. public function testGetsDateModifiedFromAtom10()
  90. {
  91. $entry = Reader\Reader::importString(
  92. file_get_contents($this->feedSamplePath . '/datemodified/atom10.xml')
  93. );
  94. $edate = DateTime::createFromFormat(DateTime::ATOM, '2009-03-07T08:03:50Z');
  95. $this->assertEquals($edate, $entry->getDateModified());
  96. }
  97. /**
  98. * Get Title (Unencoded Text)
  99. * @group ZFR002
  100. */
  101. public function testGetsTitleFromAtom10()
  102. {
  103. $entry = Reader\Reader::importString(
  104. file_get_contents($this->feedSamplePath . '/title/atom10.xml')
  105. );
  106. $this->assertEquals('Entry Title', $entry->getTitle());
  107. }
  108. /**
  109. * Get Authors (Unencoded Text)
  110. * @group ZFR002
  111. */
  112. public function testGetsAuthorsFromAtom10()
  113. {
  114. $entry = Reader\Reader::importString(
  115. file_get_contents($this->feedSamplePath . '/author/atom10.xml')
  116. );
  117. $authors = array(
  118. array('email'=>'joe@example.com','name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
  119. array('name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
  120. array('name'=>'Joe Bloggs'),
  121. array('email'=>'joe@example.com','uri'=>'http://www.example.com'),
  122. array('uri'=>'http://www.example.com'),
  123. array('email'=>'joe@example.com')
  124. );
  125. $this->assertEquals($authors, (array) $entry->getAuthors());
  126. }
  127. /**
  128. * Get Author (Unencoded Text)
  129. * @group ZFR002
  130. */
  131. public function testGetsAuthorFromAtom10()
  132. {
  133. $entry = Reader\Reader::importString(
  134. file_get_contents($this->feedSamplePath . '/author/atom10.xml')
  135. );
  136. $this->assertEquals(array('name'=>'Joe Bloggs','email'=>'joe@example.com','uri'=>'http://www.example.com'), $entry->getAuthor());
  137. }
  138. /**
  139. * Get Description (Unencoded Text)
  140. * @group ZFR002
  141. */
  142. public function testGetsDescriptionFromAtom10()
  143. {
  144. $entry = Reader\Reader::importString(
  145. file_get_contents($this->feedSamplePath . '/description/atom10.xml')
  146. );
  147. $this->assertEquals('Entry Description', $entry->getDescription());
  148. }
  149. /**
  150. * Get enclosure
  151. * @group ZFR002
  152. */
  153. public function testGetsEnclosureFromAtom10()
  154. {
  155. $entry = Reader\Reader::importString(
  156. file_get_contents($this->feedSamplePath.'/enclosure/atom10.xml')
  157. );
  158. $expected = new \stdClass();
  159. $expected->url = 'http://www.example.org/myaudiofile.mp3';
  160. $expected->length = '1234';
  161. $expected->type = 'audio/mpeg';
  162. $this->assertEquals($expected, $entry->getEnclosure());
  163. }
  164. /**
  165. * TEXT
  166. * @group ZFRATOMCONTENT
  167. */
  168. public function testGetsContentFromAtom10()
  169. {
  170. $entry = Reader\Reader::importString(
  171. file_get_contents($this->feedSamplePath . '/content/atom10.xml')
  172. );
  173. $this->assertEquals('Entry Content &amp;', $entry->getContent());
  174. }
  175. /**
  176. * HTML Escaped
  177. * @group ZFRATOMCONTENT
  178. */
  179. public function testGetsContentFromAtom10Html()
  180. {
  181. $entry = Reader\Reader::importString(
  182. file_get_contents($this->feedSamplePath . '/content/atom10_Html.xml')
  183. );
  184. $this->assertEquals('<p>Entry Content &amp;</p>', $entry->getContent());
  185. }
  186. /**
  187. * HTML CDATA Escaped
  188. * @group ZFRATOMCONTENT
  189. */
  190. public function testGetsContentFromAtom10HtmlCdata()
  191. {
  192. $entry = Reader\Reader::importString(
  193. file_get_contents($this->feedSamplePath . '/content/atom10_HtmlCdata.xml')
  194. );
  195. $this->assertEquals('<p>Entry Content &amp;</p>', $entry->getContent());
  196. }
  197. /**
  198. * XHTML
  199. * @group ZFRATOMCONTENT
  200. */
  201. public function testGetsContentFromAtom10XhtmlNamespaced()
  202. {
  203. $entry = Reader\Reader::importString(
  204. file_get_contents($this->feedSamplePath . '/content/atom10_Xhtml.xml')
  205. );
  206. $this->assertEquals('<p class="x:"><em>Entry Content &amp;x:</em></p>', $entry->getContent());
  207. }
  208. /**
  209. * Get Link (Unencoded Text)
  210. * @group ZFR002
  211. */
  212. public function testGetsLinkFromAtom10()
  213. {
  214. $entry = Reader\Reader::importString(
  215. file_get_contents($this->feedSamplePath . '/link/atom10.xml')
  216. );
  217. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  218. }
  219. /**
  220. * Get Comment HTML Link
  221. * @group ZFR002
  222. */
  223. public function testGetsCommentLinkFromAtom10()
  224. {
  225. $entry = Reader\Reader::importString(
  226. file_get_contents($this->feedSamplePath . '/commentlink/atom10.xml')
  227. );
  228. $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
  229. }
  230. /**
  231. * Get category data
  232. * @group ZFR002
  233. */
  234. public function testGetsCategoriesFromAtom10()
  235. {
  236. $entry = Reader\Reader::importString(
  237. file_get_contents($this->feedSamplePath.'/category/atom10.xml')
  238. );
  239. $this->assertEquals($this->expectedCats, (array) $entry->getCategories());
  240. $this->assertEquals(array('topic1','Cat & Dog'), array_values($entry->getCategories()->getValues()));
  241. }
  242. }