2
0

AtomTest.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  84. $entry->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  85. }
  86. public function testGetsDateCreatedFromAtom10()
  87. {
  88. $feed = Zend_Feed_Reader::importString(
  89. file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom10.xml')
  90. );
  91. $entry = $feed->current();
  92. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  93. $entry->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  94. }
  95. /**
  96. * Get modification date (Unencoded Text)
  97. */
  98. public function testGetsDateModifiedFromAtom03()
  99. {
  100. $feed = Zend_Feed_Reader::importString(
  101. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom03.xml')
  102. );
  103. $entry = $feed->current();
  104. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  105. $entry->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  106. }
  107. public function testGetsDateModifiedFromAtom10()
  108. {
  109. $feed = Zend_Feed_Reader::importString(
  110. file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom10.xml')
  111. );
  112. $entry = $feed->current();
  113. $this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
  114. $entry->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
  115. }
  116. /**
  117. * Get Title (Unencoded Text)
  118. */
  119. public function testGetsTitleFromAtom03()
  120. {
  121. $feed = Zend_Feed_Reader::importString(
  122. file_get_contents($this->_feedSamplePath . '/title/plain/atom03.xml')
  123. );
  124. $entry = $feed->current();
  125. $this->assertEquals('Entry Title', $entry->getTitle());
  126. }
  127. public function testGetsTitleFromAtom10()
  128. {
  129. $feed = Zend_Feed_Reader::importString(
  130. file_get_contents($this->_feedSamplePath . '/title/plain/atom10.xml')
  131. );
  132. $entry = $feed->current();
  133. $this->assertEquals('Entry Title', $entry->getTitle());
  134. }
  135. /**
  136. * Get Authors (Unencoded Text)
  137. */
  138. public function testGetsAuthorsFromAtom03()
  139. {
  140. $feed = Zend_Feed_Reader::importString(
  141. file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
  142. );
  143. $authors = array(
  144. 0 => 'joe@example.com (Joe Bloggs)',
  145. 1 => 'Joe Bloggs',
  146. 3 => 'joe@example.com',
  147. 4 => 'http://www.example.com',
  148. 6 => 'jane@example.com (Jane Bloggs)'
  149. );
  150. $entry = $feed->current();
  151. $this->assertEquals($authors, $entry->getAuthors());
  152. }
  153. public function testGetsAuthorsFromAtom10()
  154. {
  155. $feed = Zend_Feed_Reader::importString(
  156. file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
  157. );
  158. $authors = array(
  159. 0 => 'joe@example.com (Joe Bloggs)',
  160. 1 => 'Joe Bloggs',
  161. 3 => 'joe@example.com',
  162. 4 => 'http://www.example.com',
  163. 6 => 'jane@example.com (Jane Bloggs)'
  164. );
  165. $entry = $feed->current();
  166. $this->assertEquals($authors, $entry->getAuthors());
  167. }
  168. /**
  169. * Get Author (Unencoded Text)
  170. */
  171. public function testGetsAuthorFromAtom03()
  172. {
  173. $feed = Zend_Feed_Reader::importString(
  174. file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
  175. );
  176. $entry = $feed->current();
  177. $this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
  178. }
  179. public function testGetsAuthorFromAtom10()
  180. {
  181. $feed = Zend_Feed_Reader::importString(
  182. file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
  183. );
  184. $entry = $feed->current();
  185. $this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
  186. }
  187. /**
  188. * Get Description (Unencoded Text)
  189. */
  190. public function testGetsDescriptionFromAtom03()
  191. {
  192. $feed = Zend_Feed_Reader::importString(
  193. file_get_contents($this->_feedSamplePath . '/description/plain/atom03.xml')
  194. );
  195. $entry = $feed->current();
  196. $this->assertEquals('Entry Description', $entry->getDescription());
  197. }
  198. public function testGetsDescriptionFromAtom10()
  199. {
  200. $feed = Zend_Feed_Reader::importString(
  201. file_get_contents($this->_feedSamplePath . '/description/plain/atom10.xml')
  202. );
  203. $entry = $feed->current();
  204. $this->assertEquals('Entry Description', $entry->getDescription());
  205. }
  206. /**
  207. * Get enclosure
  208. */
  209. public function testGetsEnclosureFromAtom03()
  210. {
  211. $feed = Zend_Feed_Reader::importString(
  212. file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom03.xml')
  213. );
  214. $entry = $feed->current();
  215. $expected = new stdClass();
  216. $expected->url = 'http://www.example.org/myaudiofile.mp3';
  217. $expected->length = '1234';
  218. $expected->type = 'audio/mpeg';
  219. $this->assertEquals($expected, $entry->getEnclosure());
  220. }
  221. public function testGetsEnclosureFromAtom10()
  222. {
  223. $feed = Zend_Feed_Reader::importString(
  224. file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom10.xml')
  225. );
  226. $entry = $feed->current();
  227. $expected = new stdClass();
  228. $expected->url = 'http://www.example.org/myaudiofile.mp3';
  229. $expected->length = '1234';
  230. $expected->type = 'audio/mpeg';
  231. $this->assertEquals($expected, $entry->getEnclosure());
  232. }
  233. /**
  234. * Get Content (Unencoded Text)
  235. */
  236. public function testGetsContentFromAtom03()
  237. {
  238. $feed = Zend_Feed_Reader::importString(
  239. file_get_contents($this->_feedSamplePath . '/content/plain/atom03.xml')
  240. );
  241. $entry = $feed->current();
  242. $this->assertEquals('Entry Content', $entry->getContent());
  243. }
  244. public function testGetsContentFromAtom10()
  245. {
  246. $feed = Zend_Feed_Reader::importString(
  247. file_get_contents($this->_feedSamplePath . '/content/plain/atom10.xml')
  248. );
  249. $entry = $feed->current();
  250. $this->assertEquals('Entry Content', $entry->getContent());
  251. }
  252. /**
  253. * Get Link (Unencoded Text)
  254. */
  255. public function testGetsLinkFromAtom03()
  256. {
  257. $feed = Zend_Feed_Reader::importString(
  258. file_get_contents($this->_feedSamplePath . '/link/plain/atom03.xml')
  259. );
  260. $entry = $feed->current();
  261. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  262. }
  263. public function testGetsLinkFromAtom10()
  264. {
  265. $feed = Zend_Feed_Reader::importString(
  266. file_get_contents($this->_feedSamplePath . '/link/plain/atom10.xml')
  267. );
  268. $entry = $feed->current();
  269. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  270. }
  271. public function testGetsLinkFromAtom10_WithNoRelAttribute()
  272. {
  273. $feed = Zend_Feed_Reader::importString(
  274. file_get_contents($this->_feedSamplePath . '/link/plain/atom10-norel.xml')
  275. );
  276. $entry = $feed->current();
  277. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  278. }
  279. public function testGetsLinkFromAtom10_WithRelativeUrl()
  280. {
  281. $feed = Zend_Feed_Reader::importString(
  282. file_get_contents($this->_feedSamplePath . '/link/plain/atom10-relative.xml')
  283. );
  284. $entry = $feed->current();
  285. $this->assertEquals('http://www.example.com/entry', $entry->getLink());
  286. }
  287. /**
  288. * Get Base Uri
  289. */
  290. public function testGetsBaseUriFromAtom10_FromFeedElement()
  291. {
  292. $feed = Zend_Feed_Reader::importString(
  293. file_get_contents($this->_feedSamplePath . '/baseurl/plain/atom10-feedlevel.xml')
  294. );
  295. $entry = $feed->current();
  296. $this->assertEquals('http://www.example.com', $entry->getBaseUrl());
  297. }
  298. public function testGetsBaseUriFromAtom10_FromEntryElement()
  299. {
  300. $feed = Zend_Feed_Reader::importString(
  301. file_get_contents($this->_feedSamplePath . '/baseurl/plain/atom10-entrylevel.xml')
  302. );
  303. $entry = $feed->current();
  304. $this->assertEquals('http://www.example.com/', $entry->getBaseUrl());
  305. }
  306. /**
  307. * Get Comment HTML Link
  308. */
  309. public function testGetsCommentLinkFromAtom03()
  310. {
  311. $feed = Zend_Feed_Reader::importString(
  312. file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom03.xml')
  313. );
  314. $entry = $feed->current();
  315. $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
  316. }
  317. public function testGetsCommentLinkFromAtom10()
  318. {
  319. $feed = Zend_Feed_Reader::importString(
  320. file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom10.xml')
  321. );
  322. $entry = $feed->current();
  323. $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
  324. }
  325. public function testGetsCommentLinkFromAtom10_RelativeLinks()
  326. {
  327. $feed = Zend_Feed_Reader::importString(
  328. file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom10-relative.xml')
  329. );
  330. $entry = $feed->current();
  331. $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
  332. }
  333. }