AtomSourceTest.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 19168 2009-11-21 17:17:18Z 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_Feed_AtomSourceTest extends PHPUnit_Framework_TestCase
  34. {
  35. protected $_feedSamplePath = null;
  36. protected $_options = array();
  37. protected $_expectedCats = array();
  38. protected $_expectedCatsDc = array();
  39. public function setup()
  40. {
  41. Zend_Feed_Reader::reset();
  42. if (Zend_Registry::isRegistered('Zend_Locale')) {
  43. $registry = Zend_Registry::getInstance();
  44. unset($registry['Zend_Locale']);
  45. }
  46. $this->_feedSamplePath = dirname(__FILE__) . '/_files/AtomSource';
  47. $this->_options = Zend_Date::setOptions();
  48. foreach($this->_options as $k=>$v) {
  49. if (is_null($v)) {
  50. unset($this->_options[$k]);
  51. }
  52. }
  53. Zend_Date::setOptions(array('format_type'=>'iso'));
  54. $this->_expectedCats = array(
  55. array(
  56. 'term' => 'topic1',
  57. 'scheme' => 'http://example.com/schema1',
  58. 'label' => 'topic1'
  59. ),
  60. array(
  61. 'term' => 'topic1',
  62. 'scheme' => 'http://example.com/schema2',
  63. 'label' => 'topic1'
  64. ),
  65. array(
  66. 'term' => 'cat_dog',
  67. 'scheme' => 'http://example.com/schema1',
  68. 'label' => 'Cat & Dog'
  69. )
  70. );
  71. $this->_expectedCatsDc = array(
  72. array(
  73. 'term' => 'topic1',
  74. 'scheme' => null,
  75. 'label' => 'topic1'
  76. ),
  77. array(
  78. 'term' => 'topic2',
  79. 'scheme' => null,
  80. 'label' => 'topic2'
  81. )
  82. );
  83. }
  84. public function teardown()
  85. {
  86. Zend_Date::setOptions($this->_options);
  87. }
  88. public function testGetsSourceFromEntry()
  89. {
  90. $feed = Zend_Feed_Reader::importString(
  91. file_get_contents($this->_feedSamplePath.'/title/atom10.xml')
  92. );
  93. $source = $feed->current()->getSource();
  94. $this->assertTrue($source instanceof Zend_Feed_Reader_Feed_Atom_Source);
  95. }
  96. /**
  97. * Get Title (Unencoded Text)
  98. */
  99. public function testGetsTitleFromAtom10()
  100. {
  101. $feed = Zend_Feed_Reader::importString(
  102. file_get_contents($this->_feedSamplePath.'/title/atom10.xml')
  103. );
  104. $source = $feed->current()->getSource();
  105. $this->assertEquals('My Title', $source->getTitle());
  106. }
  107. /**
  108. * Get Authors (Unencoded Text)
  109. */
  110. public function testGetsAuthorArrayFromAtom10()
  111. {
  112. $feed = Zend_Feed_Reader::importString(
  113. file_get_contents($this->_feedSamplePath.'/author/atom10.xml')
  114. );
  115. $source = $feed->current()->getSource();
  116. $authors = array(
  117. array('email'=>'joe@example.com','name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
  118. array('name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
  119. array('name'=>'Joe Bloggs'),
  120. array('email'=>'joe@example.com','uri'=>'http://www.example.com'),
  121. array('uri'=>'http://www.example.com'),
  122. array('email'=>'joe@example.com')
  123. );
  124. $this->assertEquals($authors, (array) $source->getAuthors());
  125. }
  126. /**
  127. * Get Single Author (Unencoded Text)
  128. */
  129. public function testGetsSingleAuthorFromAtom10()
  130. {
  131. $feed = Zend_Feed_Reader::importString(
  132. file_get_contents($this->_feedSamplePath.'/author/atom10.xml')
  133. );
  134. $source = $feed->current()->getSource();
  135. $this->assertEquals(array('name'=>'Joe Bloggs','email'=>'joe@example.com','uri'=>'http://www.example.com'), $feed->getAuthor());
  136. }
  137. /**
  138. * Get creation date (Unencoded Text)
  139. */
  140. public function testGetsDateCreatedFromAtom10()
  141. {
  142. $feed = Zend_Feed_Reader::importString(
  143. file_get_contents($this->_feedSamplePath . '/datecreated/atom10.xml')
  144. );
  145. $source = $feed->current()->getSource();
  146. $edate = new Zend_Date;
  147. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  148. $this->assertTrue($edate->equals($source->getDateCreated()));
  149. }
  150. /**
  151. * Get modification date (Unencoded Text)
  152. */
  153. public function testGetsDateModifiedFromAtom10()
  154. {
  155. $feed = Zend_Feed_Reader::importString(
  156. file_get_contents($this->_feedSamplePath . '/datemodified/atom10.xml')
  157. );
  158. $source = $feed->current()->getSource();
  159. $edate = new Zend_Date;
  160. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  161. $this->assertTrue($edate->equals($source->getDateModified()));
  162. }
  163. /**
  164. * Get Generator (Unencoded Text)
  165. */
  166. public function testGetsGeneratorFromAtom10()
  167. {
  168. $feed = Zend_Feed_Reader::importString(
  169. file_get_contents($this->_feedSamplePath.'/generator/atom10.xml')
  170. );
  171. $source = $feed->current()->getSource();
  172. $this->assertEquals('Zend_Feed', $source->getGenerator());
  173. }
  174. /**
  175. * Get Copyright (Unencoded Text)
  176. */
  177. public function testGetsCopyrightFromAtom10()
  178. {
  179. $feed = Zend_Feed_Reader::importString(
  180. file_get_contents($this->_feedSamplePath.'/copyright/atom10.xml')
  181. );
  182. $source = $feed->current()->getSource();
  183. $this->assertEquals('Copyright 2008', $source->getCopyright());
  184. }
  185. /**
  186. * Get Description (Unencoded Text)
  187. */
  188. public function testGetsDescriptionFromAtom10()
  189. {
  190. $feed = Zend_Feed_Reader::importString(
  191. file_get_contents($this->_feedSamplePath.'/description/atom10.xml')
  192. );
  193. $source = $feed->current()->getSource();
  194. $this->assertEquals('My Description', $source->getDescription());
  195. }
  196. /**
  197. * Get Id (Unencoded Text)
  198. */
  199. public function testGetsIdFromAtom10()
  200. {
  201. $feed = Zend_Feed_Reader::importString(
  202. file_get_contents($this->_feedSamplePath.'/id/atom10.xml')
  203. );
  204. $source = $feed->current()->getSource();
  205. $this->assertEquals('123', $source->getId());
  206. }
  207. /**
  208. * Get Language (Unencoded Text)
  209. */
  210. public function testGetsLanguageFromAtom10()
  211. {
  212. $feed = Zend_Feed_Reader::importString(
  213. file_get_contents($this->_feedSamplePath.'/language/atom10.xml')
  214. );
  215. $source = $feed->current()->getSource();
  216. $this->assertEquals('en-GB', $source->getLanguage());
  217. }
  218. /**
  219. * Get Link (Unencoded Text)
  220. */
  221. public function testGetsLinkFromAtom10()
  222. {
  223. $feed = Zend_Feed_Reader::importString(
  224. file_get_contents($this->_feedSamplePath.'/link/atom10.xml')
  225. );
  226. $source = $feed->current()->getSource();
  227. $this->assertEquals('http://www.example.com', $source->getLink());
  228. }
  229. /**
  230. * Get Feed Link (Unencoded Text)
  231. */
  232. public function testGetsFeedLinkFromAtom10()
  233. {
  234. $feed = Zend_Feed_Reader::importString(
  235. file_get_contents($this->_feedSamplePath.'/feedlink/atom10.xml')
  236. );
  237. $source = $feed->current()->getSource();
  238. $this->assertEquals('http://www.example.com/feed/atom', $source->getFeedLink());
  239. }
  240. /**
  241. * Get Pubsubhubbub Hubs
  242. */
  243. public function testGetsHubsFromAtom10()
  244. {
  245. $feed = Zend_Feed_Reader::importString(
  246. file_get_contents($this->_feedSamplePath.'/hubs/atom10.xml')
  247. );
  248. $source = $feed->current()->getSource();
  249. $this->assertEquals(array(
  250. 'http://www.example.com/hub1',
  251. 'http://www.example.com/hub2'
  252. ), $source->getHubs());
  253. }
  254. /**
  255. * Get category data
  256. */
  257. public function testGetsCategoriesFromAtom10()
  258. {
  259. $feed = Zend_Feed_Reader::importString(
  260. file_get_contents($this->_feedSamplePath.'/category/atom10.xml')
  261. );
  262. $source = $feed->current()->getSource();
  263. $this->assertEquals($this->_expectedCats, (array) $source->getCategories());
  264. $this->assertEquals(array('topic1','Cat & Dog'), array_values($source->getCategories()->getValues()));
  265. }
  266. }