2
0

PostTest.php 6.0 KB

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