2
0

PostTest.php 5.9 KB

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