PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/ZendFramework/tests/Zend/Feed/Reader/Feed/AtomSourceTest.php

https://bitbucket.org/Dal-Papa/is-340-publish-base
PHP | 306 lines | 194 code | 41 blank | 71 comment | 2 complexity | 81b788c637c01090759d4c3318bc009c MD5 | raw file
  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-2012 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 'Zend/Feed/Reader.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Feed
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2012 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_Feed_AtomSourceTest extends PHPUnit_Framework_TestCase
  33. {
  34. protected $_feedSamplePath = null;
  35. protected $_options = array();
  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/AtomSource';
  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 testGetsSourceFromEntry()
  88. {
  89. $feed = Zend_Feed_Reader::importString(
  90. file_get_contents($this->_feedSamplePath.'/title/atom10.xml')
  91. );
  92. $source = $feed->current()->getSource();
  93. $this->assertTrue($source instanceof Zend_Feed_Reader_Feed_Atom_Source);
  94. }
  95. /**
  96. * Get Title (Unencoded Text)
  97. */
  98. public function testGetsTitleFromAtom10()
  99. {
  100. $feed = Zend_Feed_Reader::importString(
  101. file_get_contents($this->_feedSamplePath.'/title/atom10.xml')
  102. );
  103. $source = $feed->current()->getSource();
  104. $this->assertEquals('My Title', $source->getTitle());
  105. }
  106. /**
  107. * Get Authors (Unencoded Text)
  108. */
  109. public function testGetsAuthorArrayFromAtom10()
  110. {
  111. $feed = Zend_Feed_Reader::importString(
  112. file_get_contents($this->_feedSamplePath.'/author/atom10.xml')
  113. );
  114. $source = $feed->current()->getSource();
  115. $authors = array(
  116. array('email'=>'joe@example.com','name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
  117. array('name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
  118. array('name'=>'Joe Bloggs'),
  119. array('email'=>'joe@example.com','uri'=>'http://www.example.com'),
  120. array('uri'=>'http://www.example.com'),
  121. array('email'=>'joe@example.com')
  122. );
  123. $this->assertEquals($authors, (array) $source->getAuthors());
  124. }
  125. /**
  126. * Get Single Author (Unencoded Text)
  127. */
  128. public function testGetsSingleAuthorFromAtom10()
  129. {
  130. $feed = Zend_Feed_Reader::importString(
  131. file_get_contents($this->_feedSamplePath.'/author/atom10.xml')
  132. );
  133. $source = $feed->current()->getSource();
  134. $this->assertEquals(array('name'=>'Joe Bloggs','email'=>'joe@example.com','uri'=>'http://www.example.com'), $feed->getAuthor());
  135. }
  136. /**
  137. * Get creation date (Unencoded Text)
  138. */
  139. public function testGetsDateCreatedFromAtom10()
  140. {
  141. $feed = Zend_Feed_Reader::importString(
  142. file_get_contents($this->_feedSamplePath . '/datecreated/atom10.xml')
  143. );
  144. $source = $feed->current()->getSource();
  145. $edate = new Zend_Date;
  146. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  147. $this->assertTrue($edate->equals($source->getDateCreated()));
  148. }
  149. /**
  150. * Get modification date (Unencoded Text)
  151. */
  152. public function testGetsDateModifiedFromAtom10()
  153. {
  154. $feed = Zend_Feed_Reader::importString(
  155. file_get_contents($this->_feedSamplePath . '/datemodified/atom10.xml')
  156. );
  157. $source = $feed->current()->getSource();
  158. $edate = new Zend_Date;
  159. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  160. $this->assertTrue($edate->equals($source->getDateModified()));
  161. }
  162. /**
  163. * Get Generator (Unencoded Text)
  164. */
  165. public function testGetsGeneratorFromAtom10()
  166. {
  167. $feed = Zend_Feed_Reader::importString(
  168. file_get_contents($this->_feedSamplePath.'/generator/atom10.xml')
  169. );
  170. $source = $feed->current()->getSource();
  171. $this->assertEquals('Zend_Feed', $source->getGenerator());
  172. }
  173. /**
  174. * Get Copyright (Unencoded Text)
  175. */
  176. public function testGetsCopyrightFromAtom10()
  177. {
  178. $feed = Zend_Feed_Reader::importString(
  179. file_get_contents($this->_feedSamplePath.'/copyright/atom10.xml')
  180. );
  181. $source = $feed->current()->getSource();
  182. $this->assertEquals('Copyright 2008', $source->getCopyright());
  183. }
  184. /**
  185. * Get Description (Unencoded Text)
  186. */
  187. public function testGetsDescriptionFromAtom10()
  188. {
  189. $feed = Zend_Feed_Reader::importString(
  190. file_get_contents($this->_feedSamplePath.'/description/atom10.xml')
  191. );
  192. $source = $feed->current()->getSource();
  193. $this->assertEquals('My Description', $source->getDescription());
  194. }
  195. /**
  196. * Get Id (Unencoded Text)
  197. */
  198. public function testGetsIdFromAtom10()
  199. {
  200. $feed = Zend_Feed_Reader::importString(
  201. file_get_contents($this->_feedSamplePath.'/id/atom10.xml')
  202. );
  203. $source = $feed->current()->getSource();
  204. $this->assertEquals('123', $source->getId());
  205. }
  206. /**
  207. * Get Language (Unencoded Text)
  208. */
  209. public function testGetsLanguageFromAtom10()
  210. {
  211. $feed = Zend_Feed_Reader::importString(
  212. file_get_contents($this->_feedSamplePath.'/language/atom10.xml')
  213. );
  214. $source = $feed->current()->getSource();
  215. $this->assertEquals('en-GB', $source->getLanguage());
  216. }
  217. /**
  218. * Get Link (Unencoded Text)
  219. */
  220. public function testGetsLinkFromAtom10()
  221. {
  222. $feed = Zend_Feed_Reader::importString(
  223. file_get_contents($this->_feedSamplePath.'/link/atom10.xml')
  224. );
  225. $source = $feed->current()->getSource();
  226. $this->assertEquals('http://www.example.com', $source->getLink());
  227. }
  228. /**
  229. * Get Feed Link (Unencoded Text)
  230. */
  231. public function testGetsFeedLinkFromAtom10()
  232. {
  233. $feed = Zend_Feed_Reader::importString(
  234. file_get_contents($this->_feedSamplePath.'/feedlink/atom10.xml')
  235. );
  236. $source = $feed->current()->getSource();
  237. $this->assertEquals('http://www.example.com/feed/atom', $source->getFeedLink());
  238. }
  239. /**
  240. * Get Pubsubhubbub Hubs
  241. */
  242. public function testGetsHubsFromAtom10()
  243. {
  244. $feed = Zend_Feed_Reader::importString(
  245. file_get_contents($this->_feedSamplePath.'/hubs/atom10.xml')
  246. );
  247. $source = $feed->current()->getSource();
  248. $this->assertEquals(array(
  249. 'http://www.example.com/hub1',
  250. 'http://www.example.com/hub2'
  251. ), $source->getHubs());
  252. }
  253. /**
  254. * Get category data
  255. */
  256. public function testGetsCategoriesFromAtom10()
  257. {
  258. $feed = Zend_Feed_Reader::importString(
  259. file_get_contents($this->_feedSamplePath.'/category/atom10.xml')
  260. );
  261. $source = $feed->current()->getSource();
  262. $this->assertEquals($this->_expectedCats, (array) $source->getCategories());
  263. $this->assertEquals(array('topic1','Cat & Dog'), array_values($source->getCategories()->getValues()));
  264. }
  265. }