PodcastRss2Test.php 7.4 KB

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