PodcastRss2Test.php 8.4 KB

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