AtomTest.php 12 KB

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