PodcastRss2Test.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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-2015 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 'Zend/Feed/Reader.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Feed
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2015 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_Integration_PodcastRss2Test extends PHPUnit_Framework_TestCase
  33. {
  34. protected $_feedSamplePath = null;
  35. public function setup()
  36. {
  37. Zend_Feed_Reader::reset();
  38. $this->_feedSamplePath = dirname(__FILE__) . '/_files/podcast.xml';
  39. $this->_options = Zend_Date::setOptions();
  40. foreach($this->_options as $k=>$v) {
  41. if (is_null($v)) {
  42. unset($this->_options[$k]);
  43. }
  44. }
  45. Zend_Date::setOptions(array('format_type'=>'iso'));
  46. }
  47. public function teardown()
  48. {
  49. Zend_Date::setOptions($this->_options);
  50. }
  51. /**
  52. * Feed level testing
  53. */
  54. public function testGetsNewFeedUrl()
  55. {
  56. $feed = Zend_Feed_Reader::importString(
  57. file_get_contents($this->_feedSamplePath)
  58. );
  59. $this->assertEquals('http://newlocation.com/example.rss', $feed->getNewFeedUrl());
  60. }
  61. public function testGetsOwner()
  62. {
  63. $feed = Zend_Feed_Reader::importString(
  64. file_get_contents($this->_feedSamplePath)
  65. );
  66. $this->assertEquals('john.doe@example.com (John Doe)', $feed->getOwner());
  67. }
  68. /*
  69. public function testGetsCategories()
  70. {
  71. $feed = Zend_Feed_Reader::importString(
  72. file_get_contents($this->_feedSamplePath)
  73. );
  74. $this->assertEquals(array(
  75. 'Technology' => array(
  76. 'Gadgets' => null
  77. ),
  78. 'TV & Film' => null
  79. ), $feed->getCategories());
  80. }
  81. */
  82. public function testGetsTitle()
  83. {
  84. $feed = Zend_Feed_Reader::importString(
  85. file_get_contents($this->_feedSamplePath)
  86. );
  87. $this->assertEquals('All About Everything', $feed->getTitle());
  88. }
  89. public function testGetsCastAuthor()
  90. {
  91. $feed = Zend_Feed_Reader::importString(
  92. file_get_contents($this->_feedSamplePath)
  93. );
  94. $this->assertEquals('John Doe', $feed->getCastAuthor());
  95. }
  96. public function testGetsFeedBlock()
  97. {
  98. $feed = Zend_Feed_Reader::importString(
  99. file_get_contents($this->_feedSamplePath)
  100. );
  101. $this->assertEquals('no', $feed->getBlock());
  102. }
  103. public function testGetsCopyright()
  104. {
  105. $feed = Zend_Feed_Reader::importString(
  106. file_get_contents($this->_feedSamplePath)
  107. );
  108. $this->assertEquals('℗ & © 2005 John Doe & Family', $feed->getCopyright());
  109. }
  110. public function testGetsDescription()
  111. {
  112. $feed = Zend_Feed_Reader::importString(
  113. file_get_contents($this->_feedSamplePath)
  114. );
  115. $this->assertEquals('All About Everything is a show about everything.
  116. Each week we dive into any subject known to man and talk
  117. about it as much as we can. Look for our Podcast in the
  118. iTunes Store', $feed->getDescription());
  119. }
  120. public function testGetsLanguage()
  121. {
  122. $feed = Zend_Feed_Reader::importString(
  123. file_get_contents($this->_feedSamplePath)
  124. );
  125. $this->assertEquals('en-us', $feed->getLanguage());
  126. }
  127. public function testGetsLink()
  128. {
  129. $feed = Zend_Feed_Reader::importString(
  130. file_get_contents($this->_feedSamplePath)
  131. );
  132. $this->assertEquals('http://www.example.com/podcasts/everything/index.html', $feed->getLink());
  133. }
  134. public function testGetsEncoding()
  135. {
  136. $feed = Zend_Feed_Reader::importString(
  137. file_get_contents($this->_feedSamplePath)
  138. );
  139. $this->assertEquals('UTF-8', $feed->getEncoding());
  140. }
  141. public function testGetsFeedExplicit()
  142. {
  143. $feed = Zend_Feed_Reader::importString(
  144. file_get_contents($this->_feedSamplePath)
  145. );
  146. $this->assertEquals('yes', $feed->getExplicit());
  147. }
  148. public function testGetsEntryCount()
  149. {
  150. $feed = Zend_Feed_Reader::importString(
  151. file_get_contents($this->_feedSamplePath)
  152. );
  153. $this->assertEquals(3, $feed->count());
  154. }
  155. /*
  156. public function testGetsImage()
  157. {
  158. $feed = Zend_Feed_Reader::importString(
  159. file_get_contents($this->_feedSamplePath)
  160. );
  161. $this->assertEquals('http://example.com/podcasts/everything/AllAboutEverything.jpg', $feed->getImage());
  162. }
  163. */
  164. /**
  165. * Entry level testing
  166. */
  167. public function testGetsEntryBlock()
  168. {
  169. $feed = Zend_Feed_Reader::importString(
  170. file_get_contents($this->_feedSamplePath)
  171. );
  172. $entry = $feed->current();
  173. $this->assertEquals('yes', $entry->getBlock());
  174. }
  175. public function testGetsEntryId()
  176. {
  177. $feed = Zend_Feed_Reader::importString(
  178. file_get_contents($this->_feedSamplePath)
  179. );
  180. $entry = $feed->current();
  181. $this->assertEquals('http://example.com/podcasts/archive/aae20050615.m4a', $entry->getId());
  182. }
  183. public function testGetsEntryTitle()
  184. {
  185. $feed = Zend_Feed_Reader::importString(
  186. file_get_contents($this->_feedSamplePath)
  187. );
  188. $entry = $feed->current();
  189. $this->assertEquals('Shake Shake Shake Your Spices', $entry->getTitle());
  190. }
  191. public function testGetsEntryCastAuthor()
  192. {
  193. $feed = Zend_Feed_Reader::importString(
  194. file_get_contents($this->_feedSamplePath)
  195. );
  196. $entry = $feed->current();
  197. $this->assertEquals('John Doe', $entry->getCastAuthor());
  198. }
  199. public function testGetsEntryExplicit()
  200. {
  201. $feed = Zend_Feed_Reader::importString(
  202. file_get_contents($this->_feedSamplePath)
  203. );
  204. $entry = $feed->current();
  205. $this->assertEquals('no', $entry->getExplicit());
  206. }
  207. public function testGetsSubtitle()
  208. {
  209. $feed = Zend_Feed_Reader::importString(
  210. file_get_contents($this->_feedSamplePath)
  211. );
  212. $entry = $feed->current();
  213. $this->assertEquals('A short primer on table spices
  214. ', $entry->getSubtitle());
  215. }
  216. public function testGetsSummary()
  217. {
  218. $feed = Zend_Feed_Reader::importString(
  219. file_get_contents($this->_feedSamplePath)
  220. );
  221. $entry = $feed->current();
  222. $this->assertEquals('This week we talk about salt and pepper
  223. shakers, comparing and contrasting pour rates,
  224. construction materials, and overall aesthetics. Come and
  225. join the party!', $entry->getSummary());
  226. }
  227. public function testGetsDuration()
  228. {
  229. $feed = Zend_Feed_Reader::importString(
  230. file_get_contents($this->_feedSamplePath)
  231. );
  232. $entry = $feed->current();
  233. $this->assertEquals('7:04', $entry->getDuration());
  234. }
  235. public function testGetsKeywords()
  236. {
  237. $feed = Zend_Feed_Reader::importString(
  238. file_get_contents($this->_feedSamplePath)
  239. );
  240. $entry = $feed->current();
  241. $this->assertEquals('salt, pepper, shaker, exciting
  242. ', $entry->getKeywords());
  243. }
  244. public function testGetsEntryEncoding()
  245. {
  246. $feed = Zend_Feed_Reader::importString(
  247. file_get_contents($this->_feedSamplePath)
  248. );
  249. $entry = $feed->current();
  250. $this->assertEquals('UTF-8', $entry->getEncoding());
  251. }
  252. public function testGetsEnclosure()
  253. {
  254. $feed = Zend_Feed_Reader::importString(
  255. file_get_contents($this->_feedSamplePath)
  256. );
  257. $entry = $feed->current();
  258. $expected = new stdClass();
  259. $expected->url = 'http://example.com/podcasts/everything/AllAboutEverythingEpisode3.m4a';
  260. $expected->length = '8727310';
  261. $expected->type = 'audio/x-m4a';
  262. $this->assertEquals($expected, $entry->getEnclosure());
  263. }
  264. }