PostTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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_Service_Delicious
  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. /**
  23. * @see Zend_Service_Delicious
  24. */
  25. require_once 'Zend/Service/Delicious.php';
  26. /**
  27. * @see Zend_Service_Delicious_Post
  28. */
  29. require_once 'Zend/Service/Delicious/Post.php';
  30. /**
  31. * @category Zend_Service
  32. * @package Zend_Service_Delicious
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Service
  37. * @group Zend_Service_Delicious
  38. */
  39. class Zend_Service_Delicious_PostTest extends PHPUnit_Framework_TestCase
  40. {
  41. const UNAME = 'zfTestUser';
  42. const PASS = 'zfuser';
  43. /**
  44. * Service consumer object
  45. *
  46. * @var Zend_Service_Delicious
  47. */
  48. protected $_delicious;
  49. /**
  50. * Post object
  51. *
  52. * @var Zend_Service_Delicious_Post
  53. */
  54. protected $_post;
  55. /**
  56. * Creates an instance of Zend_Service_Delicious for each test method
  57. *
  58. * @return void
  59. */
  60. public function setUp()
  61. {
  62. $this->_delicious = new Zend_Service_Delicious(self::UNAME, self::PASS);
  63. $values = array(
  64. 'title' => 'anything',
  65. 'url' => 'anything'
  66. );
  67. $this->_post = new Zend_Service_Delicious_Post($this->_delicious, $values);
  68. }
  69. /**
  70. * Ensures that the constructor throws an exception when the title is missing from the values
  71. *
  72. * @return void
  73. */
  74. public function testConstructExceptionValuesTitleMissing()
  75. {
  76. try {
  77. $post = new Zend_Service_Delicious_Post($this->_delicious, array('url' => 'anything'));
  78. $this->fail('Expected Zend_Service_Delicious_Exception not thrown');
  79. } catch (Zend_Service_Delicious_Exception $e) {
  80. $this->assertContains("'url' and 'title'", $e->getMessage());
  81. }
  82. }
  83. /**
  84. * Ensures that the constructor throws an exception when the URL is missing from the values
  85. *
  86. * @return void
  87. */
  88. public function testConstructExceptionValuesUrlMissing()
  89. {
  90. try {
  91. $post = new Zend_Service_Delicious_Post($this->_delicious, array('title' => 'anything'));
  92. $this->fail('Expected Zend_Service_Delicious_Exception not thrown');
  93. } catch (Zend_Service_Delicious_Exception $e) {
  94. $this->assertContains("'url' and 'title'", $e->getMessage());
  95. }
  96. }
  97. /**
  98. * Ensures that the constructor throws an exception when the date value is not an instance of Zend_Date
  99. *
  100. * @return void
  101. */
  102. public function testConstructExceptionValuesDateInvalid()
  103. {
  104. $values = array(
  105. 'title' => 'anything',
  106. 'url' => 'anything',
  107. 'date' => 'invalid'
  108. );
  109. try {
  110. $post = new Zend_Service_Delicious_Post($this->_delicious, $values);
  111. $this->fail('Expected Zend_Service_Delicious_Exception not thrown');
  112. } catch (Zend_Service_Delicious_Exception $e) {
  113. $this->assertContains('instance of Zend_Date', $e->getMessage());
  114. }
  115. }
  116. /**
  117. * Ensures that setTitle() provides a fluent interface
  118. *
  119. * @return void
  120. */
  121. public function testSetTitleFluent()
  122. {
  123. $this->assertSame($this->_post, $this->_post->setTitle('something'));
  124. }
  125. /**
  126. * Ensures that setNotes() provides a fluent interface
  127. *
  128. * @return void
  129. */
  130. public function testSetNotesFluent()
  131. {
  132. $this->assertSame($this->_post, $this->_post->setNotes('something'));
  133. }
  134. /**
  135. * Ensures that setTags() provides a fluent interface
  136. *
  137. * @return void
  138. */
  139. public function testSetTagsFluent()
  140. {
  141. $this->assertSame($this->_post, $this->_post->setTags(array('something')));
  142. }
  143. /**
  144. * Ensures that addTag() provides a fluent interface
  145. *
  146. * @return void
  147. */
  148. public function testAddTagFluent()
  149. {
  150. $this->assertSame($this->_post, $this->_post->addTag('another'));
  151. }
  152. /**
  153. * Ensures that removeTag() provides a fluent interface
  154. *
  155. * @return void
  156. */
  157. public function testRemoveTagFluent()
  158. {
  159. $this->assertSame($this->_post, $this->_post->removeTag('missing'));
  160. }
  161. /**
  162. * Ensures that getDate() provides expected behavior
  163. *
  164. * @return void
  165. */
  166. public function testGetDate()
  167. {
  168. $this->assertNull($this->_post->getDate());
  169. }
  170. /**
  171. * Ensures that getOthers() provides expected behavior
  172. *
  173. * @return void
  174. */
  175. public function testGetOthers()
  176. {
  177. $this->assertNull($this->_post->getOthers());
  178. }
  179. /**
  180. * Ensures that getHash() provides expected behavior
  181. *
  182. * @return void
  183. */
  184. public function testGetHash()
  185. {
  186. $this->assertNull($this->_post->getHash());
  187. }
  188. /**
  189. * Ensures that getShared() provides expected behavior
  190. *
  191. * @return void
  192. */
  193. public function testGetShared()
  194. {
  195. $this->assertTrue($this->_post->getShared());
  196. }
  197. /**
  198. * Ensures that setShared() provides a fluent interface
  199. *
  200. * @return void
  201. */
  202. public function testSetSharedFluent()
  203. {
  204. $this->assertSame($this->_post, $this->_post->setShared(true));
  205. }
  206. }