AtomTest.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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$
  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_AtomTest extends PHPUnit_Framework_TestCase
  34. {
  35. protected $_feedSamplePath = null;
  36. public function setup()
  37. {
  38. if (Zend_Registry::isRegistered('Zend_Locale')) {
  39. $registry = Zend_Registry::getInstance();
  40. unset($registry['Zend_Locale']);
  41. }
  42. $this->_feedSamplePath = dirname(__FILE__) . '/_files/Atom';
  43. $this->_options = Zend_Date::setOptions();
  44. foreach($this->_options as $k=>$v) {
  45. if (is_null($v)) {
  46. unset($this->_options[$k]);
  47. }
  48. }
  49. Zend_Date::setOptions(array('format_type'=>'iso'));
  50. }
  51. public function teardown()
  52. {
  53. Zend_Date::setOptions($this->_options);
  54. }
  55. /**
  56. * Get Id (Unencoded Text)
  57. */
  58. public function testGetsIdFromAtom03()
  59. {
  60. $feed = Zend_Feed_Reader::importString(
  61. file_get_contents($this->_feedSamplePath . '/id/plain/atom03.xml')
  62. );
  63. $entry = $feed->current();
  64. $this->assertEquals('1', $entry->getId());
  65. }
  66. public function testGetsIdFromAtom10()
  67. {
  68. $feed = Zend_Feed_Reader::importString(
  69. file_get_contents($this->_feedSamplePath . '/id/plain/atom10.xml')
  70. );
  71. $entry = $feed->current();
  72. $this->assertEquals('1', $entry->getId());
  73. }
  74. /**
  75. * Get creation date (Unencoded Text)
  76. */
  77. public function testGetsDateCreatedFromAtom03()
  78. {
  79. $feed = Zend_Feed_Reader::importString(
  80. file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom03.xml')
  81. );
  82. $entry = $feed->current();
  83. $edate = new Zend_Date;
  84. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  85. $this->assertTrue($edate->equals($entry->getDateCreated()));
  86. }
  87. public function testGetsDateCreatedFromAtom10()
  88. {
  89. $feed = Zend_Feed_Reader::importString(
  90. file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom10.xml')
  91. );
  92. $entry = $feed->current();
  93. $edate = new Zend_Date;
  94. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  95. $this->assertTrue($edate->equals($entry->getDateCreated()));
  96. }
  97. /**
  98. * Get modification date (Unencoded Text)
  99. */
  100. public function testGetsDateModifiedFromAtom03()
  101. {
  102. $feed = Zend_Feed_Reader::importString(
  103. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom03.xml')
  104. );
  105. $entry = $feed->current();
  106. $edate = new Zend_Date;
  107. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  108. $this->assertTrue($edate->equals($entry->getDateModified()));
  109. }
  110. public function testGetsDateModifiedFromAtom10()
  111. {
  112. $feed = Zend_Feed_Reader::importString(
  113. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom10.xml')
  114. );
  115. $entry = $feed->current();
  116. $edate = new Zend_Date;
  117. $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
  118. $this->assertTrue($edate->equals($entry->getDateModified()));
  119. }
  120. /**
  121. * Get Title (Unencoded Text)
  122. */
  123. public function testGetsTitleFromAtom03()
  124. {
  125. $feed = Zend_Feed_Reader::importString(
  126. file_get_contents($this->_feedSamplePath . '/title/plain/atom03.xml')
  127. );
  128. $entry = $feed->current();
  129. $this->assertEquals('Entry Title', $entry->getTitle());
  130. }
  131. public function testGetsTitleFromAtom10()
  132. {
  133. $feed = Zend_Feed_Reader::importString(
  134. file_get_contents($this->_feedSamplePath . '/title/plain/atom10.xml')
  135. );
  136. $entry = $feed->current();
  137. $this->assertEquals('Entry Title', $entry->getTitle());
  138. }
  139. /**
  140. * Get Authors (Unencoded Text)
  141. */
  142. public function testGetsAuthorsFromAtom03()
  143. {
  144. $feed = Zend_Feed_Reader::importString(
  145. file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
  146. );
  147. $authors = array(
  148. 0 => 'joe@example.com (Joe Bloggs)',
  149. 1 => 'Joe Bloggs',
  150. 3 => 'joe@example.com',
  151. 4 => 'http://www.example.com',
  152. 6 => 'jane@example.com (Jane Bloggs)'
  153. );
  154. $entry = $feed->current();
  155. $this->assertEquals($authors, $entry->getAuthors());
  156. }
  157. public function testGetsAuthorsFromAtom10()
  158. {
  159. $feed = Zend_Feed_Reader::importString(
  160. file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
  161. );
  162. $authors = array(
  163. 0 => 'joe@example.com (Joe Bloggs)',
  164. 1 => 'Joe Bloggs',
  165. 3 => 'joe@example.com',
  166. 4 => 'http://www.example.com',
  167. 6 => 'jane@example.com (Jane Bloggs)'
  168. );
  169. $entry = $feed->current();
  170. $this->assertEquals($authors, $entry->getAuthors());
  171. }
  172. /**
  173. * Get Author (Unencoded Text)
  174. */
  175. public function testGetsAuthorFromAtom03()
  176. {
  177. $feed = Zend_Feed_Reader::importString(
  178. file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
  179. );
  180. $entry = $feed->current();
  181. $this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
  182. }
  183. public function testGetsAuthorFromAtom10()
  184. {
  185. $feed = Zend_Feed_Reader::importString(
  186. file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
  187. );
  188. $entry = $feed->current();
  189. $this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
  190. }
  191. /**
  192. * Get Description (Unencoded Text)
  193. */
  194. public function testGetsDescriptionFromAtom03()
  195. {
  196. $feed = Zend_Feed_Reader::importString(
  197. file_get_contents($this->_feedSamplePath . '/description/plain/atom03.xml')
  198. );
  199. $entry = $feed->current();
  200. $this->assertEquals('Entry Description', $entry->getDescription());
  201. }
  202. public function testGetsDescriptionFromAtom10()
  203. {
  204. $feed = Zend_Feed_Reader::importString(
  205. file_get_contents($this->_feedSamplePath . '/description/plain/atom10.xml')
  206. );
  207. $entry = $feed->current();
  208. $this->assertEquals('Entry Description', $entry->getDescription());
  209. }
  210. /**
  211. * Get enclosure
  212. */
  213. public function testGetsEnclosureFromAtom03()
  214. {
  215. $feed = Zend_Feed_Reader::importString(
  216. file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom03.xml')
  217. );
  218. $entry = $feed->current();
  219. $expected = new stdClass();
  220. $expected->url = 'http://www.example.org/myaudiofile.mp3';
  221. $expected->length = '1234';
  222. $expected->type = 'audio/mpeg';
  223. $this->assertEquals($expected, $entry->getEnclosure());
  224. }
  225. public function testGetsEnclosureFromAtom10()
  226. {
  227. $feed = Zend_Feed_Reader::importString(
  228. file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom10.xml')
  229. );
  230. $entry = $feed->current();
  231. $expected = new stdClass();
  232. $expected->url = 'http://www.example.org/myaudiofile.mp3';
  233. $expected->length = '1234';
  234. $expected->type = 'audio/mpeg';
  235. $this->assertEquals($expected, $entry->getEnclosure());
  236. }
  237. /**
  238. * Get Content (Unencoded Text)
  239. */
  240. public function testGetsContentFromAtom03()
  241. {
  242. $feed = Zend_Feed_Reader::importString(
  243. file_get_contents($this->_feedSamplePath . '/content/plain/atom03.xml')
  244. );
  245. $entry = $feed->current();
  246. $this->assertEquals('Entry Content', $entry->getContent());
  247. }
  248. public function testGetsContentFromAtom10()
  249. {
  250. $feed = Zend_Feed_Reader::importString(
  251. file_get_contents($this->_feedSamplePath . '/content/plain/atom10.xml')
  252. );
  253. $entry = $feed->current();
  254. $this->assertEquals('Entry Content', $entry->getContent());
  255. }
  256. /**
  257. * Get Link (Unencoded Text)
  258. */
  259. public function testGetsLinkFromAtom03()
  260. {
  261. $feed = Zend_Feed_Reader::importString(
  262. file_get_contents($this->_feedSamplePath . '/link/plain/atom03.xml')
  263. );
  264. $entry = $feed->current();
  265. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  266. }
  267. public function testGetsLinkFromAtom10()
  268. {
  269. $feed = Zend_Feed_Reader::importString(
  270. file_get_contents($this->_feedSamplePath . '/link/plain/atom10.xml')
  271. );
  272. $entry = $feed->current();
  273. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  274. }
  275. public function testGetsLinkFromAtom10_WithNoRelAttribute()
  276. {
  277. $feed = Zend_Feed_Reader::importString(
  278. file_get_contents($this->_feedSamplePath . '/link/plain/atom10-norel.xml')
  279. );
  280. $entry = $feed->current();
  281. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  282. }
  283. public function testGetsLinkFromAtom10_WithRelativeUrl()
  284. {
  285. $feed = Zend_Feed_Reader::importString(
  286. file_get_contents($this->_feedSamplePath . '/link/plain/atom10-relative.xml')
  287. );
  288. $entry = $feed->current();
  289. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  290. }
  291. /**
  292. * Get Base Uri
  293. */
  294. public function testGetsBaseUriFromAtom10_FromFeedElement()
  295. {
  296. $feed = Zend_Feed_Reader::importString(
  297. file_get_contents($this->_feedSamplePath . '/baseurl/plain/atom10-feedlevel.xml')
  298. );
  299. $entry = $feed->current();
  300. $this->assertEquals('http://www.example.com', $entry->getBaseUrl());
  301. }
  302. public function testGetsBaseUriFromAtom10_FromEntryElement()
  303. {
  304. $feed = Zend_Feed_Reader::importString(
  305. file_get_contents($this->_feedSamplePath . '/baseurl/plain/atom10-entrylevel.xml')
  306. );
  307. $entry = $feed->current();
  308. $this->assertEquals('http://www.example.com/', $entry->getBaseUrl());
  309. }
  310. /**
  311. * Get Comment HTML Link
  312. */
  313. public function testGetsCommentLinkFromAtom03()
  314. {
  315. $feed = Zend_Feed_Reader::importString(
  316. file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom03.xml')
  317. );
  318. $entry = $feed->current();
  319. $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
  320. }
  321. public function testGetsCommentLinkFromAtom10()
  322. {
  323. $feed = Zend_Feed_Reader::importString(
  324. file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom10.xml')
  325. );
  326. $entry = $feed->current();
  327. $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
  328. }
  329. public function testGetsCommentLinkFromAtom10_RelativeLinks()
  330. {
  331. $feed = Zend_Feed_Reader::importString(
  332. file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom10-relative.xml')
  333. );
  334. $entry = $feed->current();
  335. $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
  336. }
  337. }