EntryTest.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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-2010 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(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  23. require_once 'Zend/Feed/Writer/Entry.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Feed
  27. * @subpackage UnitTests
  28. * @group Zend_Feed
  29. * @group Zend_Feed_Writer
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Feed_Writer_Extension_ITunes_EntryTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function testSetBlock()
  36. {
  37. $entry = new Zend_Feed_Writer_Entry;
  38. $entry->setItunesBlock('yes');
  39. $this->assertEquals('yes', $entry->getItunesBlock());
  40. }
  41. /**
  42. * @expectedException Zend_Feed_Exception
  43. */
  44. public function testSetBlockThrowsExceptionOnNonAlphaValue()
  45. {
  46. $entry = new Zend_Feed_Writer_Entry;
  47. $entry->setItunesBlock('123');
  48. }
  49. /**
  50. * @expectedException Zend_Feed_Exception
  51. */
  52. public function testSetBlockThrowsExceptionIfValueGreaterThan255CharsLength()
  53. {
  54. $entry = new Zend_Feed_Writer_Entry;
  55. $entry->setItunesBlock(str_repeat('a', 256));
  56. }
  57. public function testAddAuthors()
  58. {
  59. $entry = new Zend_Feed_Writer_Entry;
  60. $entry->addItunesAuthors(array('joe', 'jane'));
  61. $this->assertEquals(array('joe', 'jane'), $entry->getItunesAuthors());
  62. }
  63. public function testAddAuthor()
  64. {
  65. $entry = new Zend_Feed_Writer_Entry;
  66. $entry->addItunesAuthor('joe');
  67. $this->assertEquals(array('joe'), $entry->getItunesAuthors());
  68. }
  69. /**
  70. * @expectedException Zend_Feed_Exception
  71. */
  72. public function testAddAuthorThrowsExceptionIfValueGreaterThan255CharsLength()
  73. {
  74. $entry = new Zend_Feed_Writer_Entry;
  75. $entry->addItunesAuthor(str_repeat('a', 256));
  76. }
  77. public function testSetDurationAsSeconds()
  78. {
  79. $entry = new Zend_Feed_Writer_Entry;
  80. $entry->setItunesDuration(23);
  81. $this->assertEquals(23, $entry->getItunesDuration());
  82. }
  83. public function testSetDurationAsMinutesAndSeconds()
  84. {
  85. $entry = new Zend_Feed_Writer_Entry;
  86. $entry->setItunesDuration('23:23');
  87. $this->assertEquals('23:23', $entry->getItunesDuration());
  88. }
  89. public function testSetDurationAsHoursMinutesAndSeconds()
  90. {
  91. $entry = new Zend_Feed_Writer_Entry;
  92. $entry->setItunesDuration('23:23:23');
  93. $this->assertEquals('23:23:23', $entry->getItunesDuration());
  94. }
  95. /**
  96. * @expectedException Zend_Feed_Exception
  97. */
  98. public function testSetDurationThrowsExceptionOnUnknownFormat()
  99. {
  100. $entry = new Zend_Feed_Writer_Entry;
  101. $entry->setItunesDuration('abc');
  102. }
  103. /**
  104. * @expectedException Zend_Feed_Exception
  105. */
  106. public function testSetDurationThrowsExceptionOnInvalidSeconds()
  107. {
  108. $entry = new Zend_Feed_Writer_Entry;
  109. $entry->setItunesDuration('23:456');
  110. }
  111. /**
  112. * @expectedException Zend_Feed_Exception
  113. */
  114. public function testSetDurationThrowsExceptionOnInvalidMinutes()
  115. {
  116. $entry = new Zend_Feed_Writer_Entry;
  117. $entry->setItunesDuration('23:234:45');
  118. }
  119. public function testSetExplicitToYes()
  120. {
  121. $entry = new Zend_Feed_Writer_Entry;
  122. $entry->setItunesExplicit('yes');
  123. $this->assertEquals('yes', $entry->getItunesExplicit());
  124. }
  125. public function testSetExplicitToNo()
  126. {
  127. $entry = new Zend_Feed_Writer_Entry;
  128. $entry->setItunesExplicit('no');
  129. $this->assertEquals('no', $entry->getItunesExplicit());
  130. }
  131. public function testSetExplicitToClean()
  132. {
  133. $entry = new Zend_Feed_Writer_Entry;
  134. $entry->setItunesExplicit('clean');
  135. $this->assertEquals('clean', $entry->getItunesExplicit());
  136. }
  137. /**
  138. * @expectedException Zend_Feed_Exception
  139. */
  140. public function testSetExplicitThrowsExceptionOnUnknownTerm()
  141. {
  142. $entry = new Zend_Feed_Writer_Entry;
  143. $entry->setItunesExplicit('abc');
  144. }
  145. public function testSetKeywords()
  146. {
  147. $entry = new Zend_Feed_Writer_Entry;
  148. $words = array(
  149. 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'a10', 'a11', 'a12'
  150. );
  151. $entry->setItunesKeywords($words);
  152. $this->assertEquals($words, $entry->getItunesKeywords());
  153. }
  154. /**
  155. * @expectedException Zend_Feed_Exception
  156. */
  157. public function testSetKeywordsThrowsExceptionIfMaxKeywordsExceeded()
  158. {
  159. $entry = new Zend_Feed_Writer_Entry;
  160. $words = array(
  161. 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'a10', 'a11', 'a12', 'a13'
  162. );
  163. $entry->setItunesKeywords($words);
  164. }
  165. /**
  166. * @expectedException Zend_Feed_Exception
  167. */
  168. public function testSetKeywordsThrowsExceptionIfFormattedKeywordsExceeds255CharLength()
  169. {
  170. $entry = new Zend_Feed_Writer_Entry;
  171. $words = array(
  172. str_repeat('a', 253), str_repeat('b', 2)
  173. );
  174. $entry->setItunesKeywords($words);
  175. }
  176. public function testSetSubtitle()
  177. {
  178. $entry = new Zend_Feed_Writer_Entry;
  179. $entry->setItunesSubtitle('abc');
  180. $this->assertEquals('abc', $entry->getItunesSubtitle());
  181. }
  182. /**
  183. * @expectedException Zend_Feed_Exception
  184. */
  185. public function testSetSubtitleThrowsExceptionWhenValueExceeds255Chars()
  186. {
  187. $entry = new Zend_Feed_Writer_Entry;
  188. $entry->setItunesSubtitle(str_repeat('a', 256));
  189. }
  190. public function testSetSummary()
  191. {
  192. $entry = new Zend_Feed_Writer_Entry;
  193. $entry->setItunesSummary('abc');
  194. $this->assertEquals('abc', $entry->getItunesSummary());
  195. }
  196. /**
  197. * @expectedException Zend_Feed_Exception
  198. */
  199. public function testSetSummaryThrowsExceptionWhenValueExceeds255Chars()
  200. {
  201. $entry = new Zend_Feed_Writer_Entry;
  202. $entry->setItunesSummary(str_repeat('a', 4001));
  203. }
  204. }