AtomStandaloneEntryTest.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: AtomTest.php 19159 2009-11-21 14:23:15Z padraic $
  21. */
  22. require_once 'Zend/Feed/Reader.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Feed
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @group Zend_Feed
  30. * @group Zend_Feed_Reader
  31. */
  32. class Zend_Feed_Reader_Entry_AtomStandaloneEntryTest extends PHPUnit_Framework_TestCase
  33. {
  34. protected $_feedSamplePath = null;
  35. protected $_expectedCats = array();
  36. protected $_expectedCatsDc = array();
  37. public function setup()
  38. {
  39. Zend_Feed_Reader::reset();
  40. if (Zend_Registry::isRegistered('Zend_Locale')) {
  41. $registry = Zend_Registry::getInstance();
  42. unset($registry['Zend_Locale']);
  43. }
  44. $this->_feedSamplePath = dirname(__FILE__) . '/_files/AtomStandaloneEntry';
  45. $this->_options = Zend_Date::setOptions();
  46. foreach($this->_options as $k=>$v) {
  47. if (is_null($v)) {
  48. unset($this->_options[$k]);
  49. }
  50. }
  51. Zend_Date::setOptions(array('format_type'=>'iso'));
  52. $this->_expectedCats = array(
  53. array(
  54. 'term' => 'topic1',
  55. 'scheme' => 'http://example.com/schema1',
  56. 'label' => 'topic1'
  57. ),
  58. array(
  59. 'term' => 'topic1',
  60. 'scheme' => 'http://example.com/schema2',
  61. 'label' => 'topic1'
  62. ),
  63. array(
  64. 'term' => 'cat_dog',
  65. 'scheme' => 'http://example.com/schema1',
  66. 'label' => 'Cat & Dog'
  67. )
  68. );
  69. $this->_expectedCatsDc = array(
  70. array(
  71. 'term' => 'topic1',
  72. 'scheme' => null,
  73. 'label' => 'topic1'
  74. ),
  75. array(
  76. 'term' => 'topic2',
  77. 'scheme' => null,
  78. 'label' => 'topic2'
  79. )
  80. );
  81. }
  82. public function teardown()
  83. {
  84. Zend_Date::setOptions($this->_options);
  85. }
  86. public function testReaderImportOfAtomEntryDocumentReturnsEntryClass()
  87. {
  88. $object = Zend_Feed_Reader::importString(
  89. file_get_contents($this->_feedSamplePath . '/id/atom10.xml')
  90. );
  91. $this->assertTrue($object instanceof Zend_Feed_Reader_Entry_Atom);
  92. }
  93. /**
  94. * Get Id (Unencoded Text)
  95. * @group ZFR002
  96. */
  97. public function testGetsIdFromAtom10()
  98. {
  99. $entry = Zend_Feed_Reader::importString(
  100. file_get_contents($this->_feedSamplePath . '/id/atom10.xml')
  101. );
  102. $this->assertEquals('1', $entry->getId());
  103. }
  104. /**
  105. * Get creation date (Unencoded Text)
  106. * @group ZFR002
  107. */
  108. public function testGetsDateCreatedFromAtom10()
  109. {
  110. $entry = Zend_Feed_Reader::importString(
  111. file_get_contents($this->_feedSamplePath . '/datecreated/atom10.xml')
  112. );
  113. $edate = new Zend_Date;
  114. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  115. $this->assertTrue($edate->equals($entry->getDateCreated()));
  116. }
  117. /**
  118. * Get modification date (Unencoded Text)
  119. * @group ZFR002
  120. */
  121. public function testGetsDateModifiedFromAtom10()
  122. {
  123. $entry = Zend_Feed_Reader::importString(
  124. file_get_contents($this->_feedSamplePath . '/datemodified/atom10.xml')
  125. );
  126. $edate = new Zend_Date;
  127. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  128. $this->assertTrue($edate->equals($entry->getDateModified()));
  129. }
  130. /**
  131. * Get Title (Unencoded Text)
  132. * @group ZFR002
  133. */
  134. public function testGetsTitleFromAtom10()
  135. {
  136. $entry = Zend_Feed_Reader::importString(
  137. file_get_contents($this->_feedSamplePath . '/title/atom10.xml')
  138. );
  139. $this->assertEquals('Entry Title', $entry->getTitle());
  140. }
  141. /**
  142. * Get Authors (Unencoded Text)
  143. * @group ZFR002
  144. */
  145. public function testGetsAuthorsFromAtom10()
  146. {
  147. $entry = Zend_Feed_Reader::importString(
  148. file_get_contents($this->_feedSamplePath . '/author/atom10.xml')
  149. );
  150. $authors = array(
  151. array('email'=>'joe@example.com','name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
  152. array('name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
  153. array('name'=>'Joe Bloggs'),
  154. array('email'=>'joe@example.com','uri'=>'http://www.example.com'),
  155. array('uri'=>'http://www.example.com'),
  156. array('email'=>'joe@example.com')
  157. );
  158. $this->assertEquals($authors, (array) $entry->getAuthors());
  159. }
  160. /**
  161. * Get Author (Unencoded Text)
  162. * @group ZFR002
  163. */
  164. public function testGetsAuthorFromAtom10()
  165. {
  166. $entry = Zend_Feed_Reader::importString(
  167. file_get_contents($this->_feedSamplePath . '/author/atom10.xml')
  168. );
  169. $this->assertEquals(array('name'=>'Joe Bloggs','email'=>'joe@example.com','uri'=>'http://www.example.com'), $entry->getAuthor());
  170. }
  171. /**
  172. * Get Description (Unencoded Text)
  173. * @group ZFR002
  174. */
  175. public function testGetsDescriptionFromAtom10()
  176. {
  177. $entry = Zend_Feed_Reader::importString(
  178. file_get_contents($this->_feedSamplePath . '/description/atom10.xml')
  179. );
  180. $this->assertEquals('Entry Description', $entry->getDescription());
  181. }
  182. /**
  183. * Get enclosure
  184. * @group ZFR002
  185. */
  186. public function testGetsEnclosureFromAtom10()
  187. {
  188. $entry = Zend_Feed_Reader::importString(
  189. file_get_contents($this->_feedSamplePath.'/enclosure/atom10.xml')
  190. );
  191. $expected = new stdClass();
  192. $expected->url = 'http://www.example.org/myaudiofile.mp3';
  193. $expected->length = '1234';
  194. $expected->type = 'audio/mpeg';
  195. $this->assertEquals($expected, $entry->getEnclosure());
  196. }
  197. /**
  198. * TEXT
  199. * @group ZFRATOMCONTENT
  200. */
  201. public function testGetsContentFromAtom10()
  202. {
  203. $entry = Zend_Feed_Reader::importString(
  204. file_get_contents($this->_feedSamplePath . '/content/atom10.xml')
  205. );
  206. $this->assertEquals('Entry Content &amp;', $entry->getContent());
  207. }
  208. /**
  209. * HTML Escaped
  210. * @group ZFRATOMCONTENT
  211. */
  212. public function testGetsContentFromAtom10Html()
  213. {
  214. $entry = Zend_Feed_Reader::importString(
  215. file_get_contents($this->_feedSamplePath . '/content/atom10_Html.xml')
  216. );
  217. $this->assertEquals('<p>Entry Content &amp;</p>', $entry->getContent());
  218. }
  219. /**
  220. * HTML CDATA Escaped
  221. * @group ZFRATOMCONTENT
  222. */
  223. public function testGetsContentFromAtom10HtmlCdata()
  224. {
  225. $entry = Zend_Feed_Reader::importString(
  226. file_get_contents($this->_feedSamplePath . '/content/atom10_HtmlCdata.xml')
  227. );
  228. $this->assertEquals('<p>Entry Content &amp;</p>', $entry->getContent());
  229. }
  230. /**
  231. * XHTML
  232. * @group ZFRATOMCONTENT
  233. */
  234. public function testGetsContentFromAtom10XhtmlNamespaced()
  235. {
  236. $entry = Zend_Feed_Reader::importString(
  237. file_get_contents($this->_feedSamplePath . '/content/atom10_Xhtml.xml')
  238. );
  239. $this->assertEquals('<p class="x:"><em>Entry Content &amp;x:</em></p>', $entry->getContent());
  240. }
  241. /**
  242. * Get Link (Unencoded Text)
  243. * @group ZFR002
  244. */
  245. public function testGetsLinkFromAtom10()
  246. {
  247. $entry = Zend_Feed_Reader::importString(
  248. file_get_contents($this->_feedSamplePath . '/link/atom10.xml')
  249. );
  250. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  251. }
  252. /**
  253. * Get Comment HTML Link
  254. * @group ZFR002
  255. */
  256. public function testGetsCommentLinkFromAtom10()
  257. {
  258. $entry = Zend_Feed_Reader::importString(
  259. file_get_contents($this->_feedSamplePath . '/commentlink/atom10.xml')
  260. );
  261. $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
  262. }
  263. /**
  264. * Get category data
  265. * @group ZFR002
  266. */
  267. public function testGetsCategoriesFromAtom10()
  268. {
  269. $entry = Zend_Feed_Reader::importString(
  270. file_get_contents($this->_feedSamplePath.'/category/atom10.xml')
  271. );
  272. $this->assertEquals($this->_expectedCats, (array) $entry->getCategories());
  273. $this->assertEquals(array('topic1','Cat & Dog'), array_values($entry->getCategories()->getValues()));
  274. }
  275. }