TwitterTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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_Twitter
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: TwitterTest.php 22318 2010-05-29 18:24:27Z padraic $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Service_Twitter_TwitterTest2::main');
  24. }
  25. /**
  26. * Test helper
  27. */
  28. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  29. /** Zend_Service_Twitter */
  30. require_once 'Zend/Service/Twitter.php';
  31. /** Zend_Http_Client */
  32. require_once 'Zend/Http/Client.php';
  33. /** Zend_Http_Client_Adapter_Test */
  34. require_once 'Zend/Http/Client/Adapter/Test.php';
  35. /**
  36. * @category Zend
  37. * @package Zend_Service_Twitter
  38. * @subpackage UnitTests
  39. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. * @group Zend_Service
  42. * @group Zend_Service_Twitter
  43. */
  44. class Zend_Service_Twitter_TwitterTest extends PHPUnit_Framework_TestCase
  45. {
  46. /**
  47. * Runs the test methods of this class.
  48. *
  49. * @return void
  50. */
  51. public static function main()
  52. {
  53. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  54. $result = PHPUnit_TextUI_TestRunner::run($suite);
  55. }
  56. public function teardown()
  57. {
  58. Zend_Service_Abstract::setHttpClient(new Zend_Http_Client);
  59. }
  60. /**
  61. * Quick reusable Twitter Service stub setup. Its purpose is to fake
  62. * interactions with Twitter so the component can focus on what matters:
  63. * 1. Makes correct requests (URI, parameters and HTTP method)
  64. * 2. Parses all responses and returns a Zend_Rest_Client_Result
  65. * 3. TODO: Correctly utilises all optional parameters
  66. *
  67. * If used correctly, tests will be fast, efficient, and focused on
  68. * Zend_Service_Twitter's behaviour only. No other dependencies need be
  69. * tested. The Twitter API Changelog should be regularly reviewed to
  70. * ensure the component is synchronised to the API.
  71. *
  72. * @param string $path Path appended to Twitter API endpoint
  73. * @param string $method Do we expect HTTP GET or POST?
  74. * @param string $responseFile File containing a valid XML response to the request
  75. * @param array $params Expected GET/POST parameters for the request
  76. * @return Zend_Http_Client
  77. */
  78. protected function _stubTwitter($path, $method, $responseFile = null, array $params = null)
  79. {
  80. $client = $this->getMock('Zend_Http_Client');
  81. $client->expects($this->any())->method('resetParameters')
  82. ->will($this->returnValue($client));
  83. $client->expects($this->once())->method('setUri')
  84. ->with('http://api.twitter.com/1/' . $path);
  85. $response = $this->getMock('Zend_Http_Response', array(), array(), '', false);
  86. if (!is_null($params)) {
  87. $setter = 'setParameter' . ucfirst(strtolower($method));
  88. $client->expects($this->once())->method($setter)->with($params);
  89. }
  90. $client->expects($this->once())->method('request')->with($method)
  91. ->will($this->returnValue($response));
  92. $response->expects($this->any())->method('getBody')
  93. ->will($this->returnValue(
  94. isset($responseFile) ? file_get_contents(dirname(__FILE__) . '/_files/' . $responseFile) : ''
  95. ));
  96. return $client;
  97. }
  98. /**
  99. * OAuth tests
  100. */
  101. public function testProvidingAccessTokenInOptionsSetsHttpClientFromAccessToken()
  102. {
  103. $token = $this->getMock('Zend_Oauth_Token_Access', array(), array(), '', false);
  104. $client = $this->getMock('Zend_Oauth_Client', array(), array(), '', false);
  105. $token->expects($this->once())->method('getHttpClient')
  106. ->with(array('accessToken'=>$token, 'opt1'=>'val1', 'siteUrl'=>'http://twitter.com/oauth'))
  107. ->will($this->returnValue($client));
  108. $twitter = new Zend_Service_Twitter(array('accessToken'=>$token, 'opt1'=>'val1'));
  109. $this->assertTrue($client === $twitter->getLocalHttpClient());
  110. }
  111. public function testNotAuthorisedWithoutToken()
  112. {
  113. $twitter = new Zend_Service_Twitter;
  114. $this->assertFalse($twitter->isAuthorised());
  115. }
  116. public function testChecksAuthenticatedStateBasedOnAvailabilityOfAccessTokenBasedClient()
  117. {
  118. $token = $this->getMock('Zend_Oauth_Token_Access', array(), array(), '', false);
  119. $client = $this->getMock('Zend_Oauth_Client', array(), array(), '', false);
  120. $token->expects($this->once())->method('getHttpClient')
  121. ->with(array('accessToken'=>$token, 'siteUrl'=>'http://twitter.com/oauth'))
  122. ->will($this->returnValue($client));
  123. $twitter = new Zend_Service_Twitter(array('accessToken'=>$token));
  124. $this->assertTrue($twitter->isAuthorised());
  125. }
  126. public function testRelaysMethodsToInternalOAuthInstance()
  127. {
  128. $oauth = $this->getMock('Zend_Oauth_Consumer', array(), array(), '', false);
  129. $oauth->expects($this->once())->method('getRequestToken')->will($this->returnValue('foo'));
  130. $oauth->expects($this->once())->method('getRedirectUrl')->will($this->returnValue('foo'));
  131. $oauth->expects($this->once())->method('redirect')->will($this->returnValue('foo'));
  132. $oauth->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo'));
  133. $oauth->expects($this->once())->method('getToken')->will($this->returnValue('foo'));
  134. $twitter = new Zend_Service_Twitter(array('opt1'=>'val1'), $oauth);
  135. $this->assertEquals('foo', $twitter->getRequestToken());
  136. $this->assertEquals('foo', $twitter->getRedirectUrl());
  137. $this->assertEquals('foo', $twitter->redirect());
  138. $this->assertEquals('foo', $twitter->getAccessToken(array(), $this->getMock('Zend_Oauth_Token_Request')));
  139. $this->assertEquals('foo', $twitter->getToken());
  140. }
  141. public function testResetsHttpClientOnReceiptOfAccessTokenToOauthClient()
  142. {
  143. $oauth = $this->getMock('Zend_Oauth_Consumer', array(), array(), '', false);
  144. $client = $this->getMock('Zend_Oauth_Client', array(), array(), '', false);
  145. $token = $this->getMock('Zend_Oauth_Token_Access', array(), array(), '', false);
  146. $token->expects($this->once())->method('getHttpClient')->will($this->returnValue($client));
  147. $oauth->expects($this->once())->method('getAccessToken')->will($this->returnValue($token));
  148. $twitter = new Zend_Service_Twitter(array(), $oauth);
  149. $twitter->getAccessToken(array(), $this->getMock('Zend_Oauth_Token_Request'));
  150. $this->assertTrue($client === $twitter->getLocalHttpClient());
  151. }
  152. /**
  153. * @group ZF-8218
  154. */
  155. public function testUserNameNotRequired()
  156. {
  157. $twitter = new Zend_Service_Twitter();
  158. $twitter->setLocalHttpClient($this->_stubTwitter(
  159. 'users/show.xml', Zend_Http_Client::GET, 'users.show.twitter.xml',
  160. array('id'=>'twitter')
  161. ));
  162. $exists = $twitter->user->show('twitter')->id() !== null;
  163. $this->assertTrue($exists);
  164. }
  165. /**
  166. * @group ZF-7781
  167. */
  168. public function testRetrievingStatusesWithValidScreenNameThrowsNoInvalidScreenNameException()
  169. {
  170. $twitter = new Zend_Service_Twitter();
  171. $twitter->setLocalHttpClient($this->_stubTwitter(
  172. 'statuses/user_timeline.xml', Zend_Http_Client::GET, 'user_timeline.twitter.xml'
  173. ));
  174. $twitter->status->userTimeline(array('screen_name' => 'twitter'));
  175. }
  176. /**
  177. * @group ZF-7781
  178. * @expectedException Zend_Service_Twitter_Exception
  179. */
  180. public function testRetrievingStatusesWithInvalidScreenNameCharacterThrowsInvalidScreenNameException()
  181. {
  182. $twitter = new Zend_Service_Twitter();
  183. $twitter->status->userTimeline(array('screen_name' => 'abc.def'));
  184. }
  185. /**
  186. * @group ZF-7781
  187. */
  188. public function testRetrievingStatusesWithInvalidScreenNameLengthThrowsInvalidScreenNameException()
  189. {
  190. $this->setExpectedException('Zend_Service_Twitter_Exception');
  191. $twitter = new Zend_Service_Twitter();
  192. $twitter->status->userTimeline(array('screen_name' => 'abcdef_abc123_abc123x'));
  193. }
  194. /**
  195. * @group ZF-7781
  196. */
  197. public function testStatusUserTimelineConstructsExpectedGetUriAndOmitsInvalidParams()
  198. {
  199. $twitter = new Zend_Service_Twitter;
  200. $twitter->setLocalHttpClient($this->_stubTwitter(
  201. 'statuses/user_timeline/783214.xml', Zend_Http_Client::GET, 'user_timeline.twitter.xml', array(
  202. 'page' => '1',
  203. 'count' => '123',
  204. 'user_id' => '783214',
  205. 'since_id' => '10000',
  206. 'max_id' => '20000',
  207. 'screen_name' => 'twitter'
  208. )
  209. ));
  210. $twitter->status->userTimeline(array(
  211. 'id' => '783214',
  212. 'since' => '+2 days', /* invalid param since Apr 2009 */
  213. 'page' => '1',
  214. 'count' => '123',
  215. 'user_id' => '783214',
  216. 'since_id' => '10000',
  217. 'max_id' => '20000',
  218. 'screen_name' => 'twitter'
  219. ));
  220. }
  221. public function testOverloadingGetShouldReturnObjectInstanceWithValidMethodType()
  222. {
  223. $twitter = new Zend_Service_Twitter;
  224. $return = $twitter->status;
  225. $this->assertSame($twitter, $return);
  226. }
  227. /**
  228. * @expectedException Zend_Service_Twitter_Exception
  229. */
  230. public function testOverloadingGetShouldthrowExceptionWithInvalidMethodType()
  231. {
  232. $twitter = new Zend_Service_Twitter;
  233. $return = $twitter->foo;
  234. }
  235. /**
  236. * @expectedException Zend_Service_Twitter_Exception
  237. */
  238. public function testOverloadingGetShouldthrowExceptionWithInvalidFunction()
  239. {
  240. $twitter = new Zend_Service_Twitter;
  241. $return = $twitter->foo();
  242. }
  243. public function testMethodProxyingDoesNotThrowExceptionsWithValidMethods()
  244. {
  245. $twitter = new Zend_Service_Twitter;
  246. $twitter->setLocalHttpClient($this->_stubTwitter(
  247. 'statuses/public_timeline.xml', Zend_Http_Client::GET, 'public_timeline.xml'
  248. ));
  249. $twitter->status->publicTimeline();
  250. }
  251. /**
  252. * @expectedException Zend_Service_Twitter_Exception
  253. */
  254. public function testMethodProxyingThrowExceptionsWithInvalidMethods()
  255. {
  256. $twitter = new Zend_Service_Twitter;
  257. $twitter->status->foo();
  258. }
  259. public function testVerifiedCredentials()
  260. {
  261. $twitter = new Zend_Service_Twitter;
  262. $twitter->setLocalHttpClient($this->_stubTwitter(
  263. 'account/verify_credentials.xml', Zend_Http_Client::GET, 'account.verify_credentials.xml'
  264. ));
  265. $response = $twitter->account->verifyCredentials();
  266. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  267. }
  268. public function testPublicTimelineStatusReturnsResults()
  269. {
  270. $twitter = new Zend_Service_Twitter;
  271. $twitter->setLocalHttpClient($this->_stubTwitter(
  272. 'statuses/public_timeline.xml', Zend_Http_Client::GET, 'public_timeline.xml'
  273. ));
  274. $response = $twitter->status->publicTimeline();
  275. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  276. }
  277. public function testRateLimitStatusReturnsResults()
  278. {
  279. $twitter = new Zend_Service_Twitter;
  280. $twitter->setLocalHttpClient($this->_stubTwitter(
  281. 'account/rate_limit_status.xml', Zend_Http_Client::GET, 'rate_limit_status.xml'
  282. ));
  283. $response = $twitter->account->rateLimitStatus();
  284. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  285. }
  286. public function testRateLimitStatusHasHitsLeft()
  287. {
  288. $twitter = new Zend_Service_Twitter;
  289. $twitter->setLocalHttpClient($this->_stubTwitter(
  290. 'account/rate_limit_status.xml', Zend_Http_Client::GET, 'rate_limit_status.xml'
  291. ));
  292. $response = $twitter->account->rateLimitStatus();
  293. $remaining_hits = $response->toValue($response->{'remaining-hits'});
  294. $this->assertEquals(150, $remaining_hits);
  295. }
  296. public function testAccountEndSession()
  297. {
  298. $twitter = new Zend_Service_Twitter;
  299. $twitter->setLocalHttpClient($this->_stubTwitter(
  300. 'account/end_session', Zend_Http_Client::GET
  301. ));
  302. $response = $twitter->account->endSession();
  303. $this->assertTrue($response);
  304. }
  305. /**
  306. * TODO: Check actual purpose. New friend returns XML response, existing
  307. * friend returns a 403 code.
  308. */
  309. public function testFriendshipCreate()
  310. {
  311. $twitter = new Zend_Service_Twitter;
  312. $twitter->setLocalHttpClient($this->_stubTwitter(
  313. 'friendships/create/twitter.xml', Zend_Http_Client::POST, 'friendships.create.twitter.xml'
  314. ));
  315. $response = $twitter->friendship->create('twitter');
  316. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  317. }
  318. /**
  319. * TODO: Mismatched behaviour from API. Per the API this can assert the
  320. * existence of a friendship between any two users (not just the current
  321. * user). We should expand the method or add a better fit method for
  322. * general use.
  323. */
  324. public function testFriendshipExists()
  325. {
  326. $twitter = new Zend_Service_Twitter(array('username'=>'padraicb'));
  327. $twitter->setLocalHttpClient($this->_stubTwitter(
  328. 'friendships/exists.xml', Zend_Http_Client::GET, 'friendships.exists.twitter.xml',
  329. array('user_a'=>'padraicb', 'user_b'=>'twitter')
  330. ));
  331. $response = $twitter->friendship->exists('twitter');
  332. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  333. }
  334. /**
  335. * TODO: Add verification for ALL optional parameters
  336. */
  337. public function testFriendsTimelineWithPageReturnsResults()
  338. {
  339. $twitter = new Zend_Service_Twitter;
  340. $twitter->setLocalHttpClient($this->_stubTwitter(
  341. 'statuses/friends_timeline.xml', Zend_Http_Client::GET, 'statuses.friends_timeline.page.xml',
  342. array('page'=>3)
  343. ));
  344. $response = $twitter->status->friendsTimeline(array('page' => 3));
  345. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  346. }
  347. /**
  348. * TODO: Add verification for ALL optional parameters
  349. */
  350. public function testUserTimelineReturnsResults()
  351. {
  352. $twitter = new Zend_Service_Twitter;
  353. $twitter->setLocalHttpClient($this->_stubTwitter(
  354. 'statuses/user_timeline/twitter.xml', Zend_Http_Client::GET, 'user_timeline.twitter.xml'
  355. ));
  356. $response = $twitter->status->userTimeline(array('id' => 'twitter'));
  357. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  358. }
  359. /**
  360. * TODO: Add verification for ALL optional parameters
  361. */
  362. public function testPostStatusUpdateReturnsResponse()
  363. {
  364. $twitter = new Zend_Service_Twitter;
  365. $twitter->setLocalHttpClient($this->_stubTwitter(
  366. 'statuses/update.xml', Zend_Http_Client::POST, 'statuses.update.xml',
  367. array('status'=>'Test Message 1')
  368. ));
  369. $response = $twitter->status->update('Test Message 1');
  370. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  371. }
  372. /**
  373. * @expectedException Zend_Service_Twitter_Exception
  374. */
  375. public function testPostStatusUpdateToLongShouldThrowException()
  376. {
  377. $twitter = new Zend_Service_Twitter;
  378. $twitter->status->update('Test Message - ' . str_repeat(' Hello ', 140));
  379. }
  380. /**
  381. * @expectedException Zend_Service_Twitter_Exception
  382. */
  383. public function testPostStatusUpdateEmptyShouldThrowException()
  384. {
  385. $twitter = new Zend_Service_Twitter;
  386. $twitter->status->update('');
  387. }
  388. public function testShowStatusReturnsResponse()
  389. {
  390. $twitter = new Zend_Service_Twitter;
  391. $twitter->setLocalHttpClient($this->_stubTwitter(
  392. 'statuses/show/15042159587.xml', Zend_Http_Client::GET, 'statuses.show.xml'
  393. ));
  394. $response = $twitter->status->show(15042159587);
  395. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  396. }
  397. public function testCreateFavoriteStatusReturnsResponse()
  398. {
  399. $twitter = new Zend_Service_Twitter;
  400. $twitter->setLocalHttpClient($this->_stubTwitter(
  401. 'favorites/create/15042159587.xml', Zend_Http_Client::POST, 'favorites.create.xml'
  402. ));
  403. $response = $twitter->favorite->create(15042159587);
  404. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  405. }
  406. public function testFavoriteFavoriesReturnsResponse()
  407. {
  408. $twitter = new Zend_Service_Twitter;
  409. $twitter->setLocalHttpClient($this->_stubTwitter(
  410. 'favorites.xml', Zend_Http_Client::GET, 'favorites.xml'
  411. ));
  412. $response = $twitter->favorite->favorites();
  413. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  414. }
  415. /**
  416. * TODO: Can we use a HTTP DELETE?
  417. */
  418. public function testDestroyFavoriteReturnsResponse()
  419. {
  420. $twitter = new Zend_Service_Twitter;
  421. $twitter->setLocalHttpClient($this->_stubTwitter(
  422. 'favorites/destroy/15042159587.xml', Zend_Http_Client::POST, 'favorites.destroy.xml'
  423. ));
  424. $response = $twitter->favorite->destroy(15042159587);
  425. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  426. }
  427. public function testStatusDestroyReturnsResult()
  428. {
  429. $twitter = new Zend_Service_Twitter;
  430. $twitter->setLocalHttpClient($this->_stubTwitter(
  431. 'statuses/destroy/15042159587.xml', Zend_Http_Client::POST, 'statuses.destroy.xml'
  432. ));
  433. $response = $twitter->status->destroy(15042159587);
  434. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  435. }
  436. /**
  437. * TODO: Add verification for ALL optional parameters
  438. */
  439. public function testUserFriendsReturnsResults()
  440. {
  441. $twitter = new Zend_Service_Twitter;
  442. $twitter->setLocalHttpClient($this->_stubTwitter(
  443. 'statuses/friends.xml', Zend_Http_Client::GET, 'statuses.friends.xml'
  444. ));
  445. $response = $twitter->user->friends();
  446. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  447. }
  448. /**
  449. * TODO: Add verification for ALL optional parameters
  450. * Note: Implementation does not currently accept ANY optional parameters
  451. */
  452. public function testUserFollowersReturnsResults()
  453. {
  454. $twitter = new Zend_Service_Twitter;
  455. $twitter->setLocalHttpClient($this->_stubTwitter(
  456. 'statuses/followers.xml', Zend_Http_Client::GET, 'statuses.followers.xml'
  457. ));
  458. $response = $twitter->user->followers();
  459. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  460. }
  461. public function testUserShowByIdReturnsResults()
  462. {
  463. $twitter = new Zend_Service_Twitter;
  464. $twitter->setLocalHttpClient($this->_stubTwitter(
  465. 'users/show.xml', Zend_Http_Client::GET, 'users.show.twitter.xml',
  466. array('id'=>'twitter')
  467. ));
  468. $response = $twitter->user->show('twitter');
  469. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  470. }
  471. /**
  472. * TODO: Add verification for ALL optional parameters
  473. */
  474. public function testStatusRepliesReturnsResults()
  475. {
  476. $twitter = new Zend_Service_Twitter;
  477. $twitter->setLocalHttpClient($this->_stubTwitter(
  478. 'statuses/mentions.xml', Zend_Http_Client::GET, 'statuses.mentions.xml'
  479. ));
  480. $response = $twitter->status->replies();
  481. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  482. }
  483. /**
  484. * TODO: Add verification for ALL optional parameters
  485. */
  486. public function testFriendshipDestroy()
  487. {
  488. $twitter = new Zend_Service_Twitter;
  489. $twitter->setLocalHttpClient($this->_stubTwitter(
  490. 'friendships/destroy/twitter.xml', Zend_Http_Client::POST, 'friendships.destroy.twitter.xml'
  491. ));
  492. $response = $twitter->friendship->destroy('twitter');
  493. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  494. }
  495. public function testBlockingCreate()
  496. {
  497. $twitter = new Zend_Service_Twitter;
  498. $twitter->setLocalHttpClient($this->_stubTwitter(
  499. 'blocks/create/twitter.xml', Zend_Http_Client::POST, 'blocks.create.twitter.xml'
  500. ));
  501. $response = $twitter->block->create('twitter');
  502. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  503. }
  504. public function testBlockingExistsReturnsTrueWhenBlockExists()
  505. {
  506. $twitter = new Zend_Service_Twitter;
  507. $twitter->setLocalHttpClient($this->_stubTwitter(
  508. 'blocks/exists/twitter.xml', Zend_Http_Client::GET, 'blocks.exists.twitter.xml'
  509. ));
  510. $this->assertTrue($twitter->block->exists('twitter'));
  511. }
  512. public function testBlockingBlocked()
  513. {
  514. $twitter = new Zend_Service_Twitter;
  515. $twitter->setLocalHttpClient($this->_stubTwitter(
  516. 'blocks/blocking.xml', Zend_Http_Client::GET, 'blocks.blocking.xml'
  517. ));
  518. $response = $twitter->block->blocking();
  519. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  520. }
  521. public function testBlockingBlockedReturnsIds()
  522. {
  523. $twitter = new Zend_Service_Twitter;
  524. $twitter->setLocalHttpClient($this->_stubTwitter(
  525. 'blocks/blocking/ids.xml', Zend_Http_Client::GET, 'blocks.blocking.ids.xml',
  526. array('page'=>1)
  527. ));
  528. $response = $twitter->block->blocking(1, true);
  529. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  530. $this->assertEquals('23836616', (string) $response->id);
  531. }
  532. public function testBlockingDestroy()
  533. {
  534. $twitter = new Zend_Service_Twitter;
  535. $twitter->setLocalHttpClient($this->_stubTwitter(
  536. 'blocks/destroy/twitter.xml', Zend_Http_Client::POST, 'blocks.destroy.twitter.xml'
  537. ));
  538. $response = $twitter->block->destroy('twitter');
  539. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  540. }
  541. public function testBlockingExistsReturnsFalseWhenBlockDoesNotExists()
  542. {
  543. $twitter = new Zend_Service_Twitter;
  544. $twitter->setLocalHttpClient($this->_stubTwitter(
  545. 'blocks/exists/padraicb.xml', Zend_Http_Client::GET, 'blocks.exists.padraicb.xml'
  546. ));
  547. $this->assertFalse($twitter->block->exists('padraicb'));
  548. }
  549. public function testBlockingExistsReturnsObjectWhenFlagPassed()
  550. {
  551. $twitter = new Zend_Service_Twitter;
  552. $twitter->setLocalHttpClient($this->_stubTwitter(
  553. 'blocks/exists/padraicb.xml', Zend_Http_Client::GET, 'blocks.exists.padraicb.xml'
  554. ));
  555. $response = $twitter->block->exists('padraicb', true);
  556. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  557. }
  558. /**
  559. * @group ZF-6284
  560. */
  561. public function testTwitterObjectsSoNotShareSameHttpClientToPreventConflictingAuthentication()
  562. {
  563. $twitter1 = new Zend_Service_Twitter(array('username'=>'zftestuser1'));
  564. $twitter2 = new Zend_Service_Twitter(array('username'=>'zftestuser2'));
  565. $this->assertFalse($twitter1->getLocalHttpClient() === $twitter2->getLocalHttpClient());
  566. }
  567. }
  568. if (PHPUnit_MAIN_METHOD == 'Zend_Service_TwitterTest2::main') {
  569. Zend_Service_TwitterTest2::main();
  570. }