AtomStandaloneEntryTest.php 9.2 KB

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