AtomStandaloneEntryTest.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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-2009 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-2009 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. 0 => 'joe@example.com (Joe Bloggs)',
  153. 1 => 'Joe Bloggs',
  154. 3 => 'joe@example.com',
  155. 4 => 'http://www.example.com',
  156. 6 => 'jane@example.com (Jane Bloggs)'
  157. );
  158. $this->assertEquals($authors, $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('joe@example.com (Joe Bloggs)', $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. * Get Content (Unencoded Text)
  199. * @group ZFR002
  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', $entry->getContent());
  207. }
  208. /**
  209. * Get Link (Unencoded Text)
  210. * @group ZFR002
  211. */
  212. public function testGetsLinkFromAtom10()
  213. {
  214. $entry = Zend_Feed_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 = Zend_Feed_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 = Zend_Feed_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. }