/tests/Zend/Feed/Writer/Extension/ITunes/EntryTest.php

https://github.com/leerbag/zf2 · PHP · 232 lines · 142 code · 26 blank · 64 comment · 0 complexity · a40e4b42f5676331a9cad769dd842bd1 MD5 · raw file

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