2
0

EntryTest.php 6.5 KB

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