TwitterTest2.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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_TwitterTest2 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. * @group ZF-8218
  62. */
  63. public function testUserNameNotRequired()
  64. {
  65. $twitter = new Zend_Service_Twitter();
  66. $twitter->setLocalHttpClient($this->_stubTwitter(
  67. 'users/show/twitter.xml', Zend_Http_Client::GET, 'users.show.twitter.xml'
  68. ));
  69. $exists = $twitter->user->show('twitter')->id() !== null;
  70. $this->assertTrue($exists);
  71. }
  72. /**
  73. * @group ZF-7781
  74. */
  75. public function testRetrievingStatusesWithValidScreenNameThrowsNoInvalidScreenNameException()
  76. {
  77. $twitter = new Zend_Service_Twitter();
  78. $twitter->setLocalHttpClient($this->_stubTwitter(
  79. 'statuses/user_timeline.xml', Zend_Http_Client::GET, 'user_timeline.twitter.xml'
  80. ));
  81. $twitter->status->userTimeline(array('screen_name' => 'twitter'));
  82. }
  83. /**
  84. * @group ZF-7781
  85. * @expectedException Zend_Service_Twitter_Exception
  86. */
  87. public function testRetrievingStatusesWithInvalidScreenNameCharacterThrowsInvalidScreenNameException()
  88. {
  89. $twitter = new Zend_Service_Twitter();
  90. $twitter->status->userTimeline(array('screen_name' => 'abc.def'));
  91. }
  92. /**
  93. * @group ZF-7781
  94. */
  95. public function testRetrievingStatusesWithInvalidScreenNameLengthThrowsInvalidScreenNameException()
  96. {
  97. $this->setExpectedException('Zend_Service_Twitter_Exception');
  98. $twitter = new Zend_Service_Twitter();
  99. $twitter->status->userTimeline(array('screen_name' => 'abcdef_abc123_abc123x'));
  100. }
  101. /**
  102. * @group ZF-7781
  103. */
  104. public function testStatusUserTimelineConstructsExpectedGetUriAndOmitsInvalidParams()
  105. {
  106. $twitter = new Zend_Service_Twitter;
  107. $twitter->setLocalHttpClient($this->_stubTwitter(
  108. 'statuses/user_timeline/783214.xml', Zend_Http_Client::GET, 'user_timeline.twitter.xml', array(
  109. 'page' => '1',
  110. 'count' => '123',
  111. 'user_id' => '783214',
  112. 'since_id' => '10000',
  113. 'max_id' => '20000',
  114. 'screen_name' => 'twitter'
  115. )
  116. ));
  117. $twitter->status->userTimeline(array(
  118. 'id' => '783214',
  119. 'since' => '+2 days', /* invalid param since Apr 2009 */
  120. 'page' => '1',
  121. 'count' => '123',
  122. 'user_id' => '783214',
  123. 'since_id' => '10000',
  124. 'max_id' => '20000',
  125. 'screen_name' => 'twitter'
  126. ));
  127. }
  128. public function testOverloadingGetShouldReturnObjectInstanceWithValidMethodType()
  129. {
  130. $twitter = new Zend_Service_Twitter;
  131. $return = $twitter->status;
  132. $this->assertSame($twitter, $return);
  133. }
  134. /**
  135. * @expectedException Zend_Service_Twitter_Exception
  136. */
  137. public function testOverloadingGetShouldthrowExceptionWithInvalidMethodType()
  138. {
  139. $twitter = new Zend_Service_Twitter;
  140. $return = $twitter->foo;
  141. }
  142. /**
  143. * @expectedException Zend_Service_Twitter_Exception
  144. */
  145. public function testOverloadingGetShouldthrowExceptionWithInvalidFunction()
  146. {
  147. $twitter = new Zend_Service_Twitter;
  148. $return = $twitter->foo();
  149. }
  150. public function testMethodProxyingDoesNotThrowExceptionsWithValidMethods()
  151. {
  152. $twitter = new Zend_Service_Twitter;
  153. $twitter->setLocalHttpClient($this->_stubTwitter(
  154. 'statuses/public_timeline.xml', Zend_Http_Client::GET, 'public_timeline.xml'
  155. ));
  156. $twitter->status->publicTimeline();
  157. }
  158. /**
  159. * @expectedException Zend_Service_Twitter_Exception
  160. */
  161. public function testMethodProxyingThrowExceptionsWithInvalidMethods()
  162. {
  163. $twitter = new Zend_Service_Twitter;
  164. $twitter->status->foo();
  165. }
  166. public function testVerifiedCredentials()
  167. {
  168. $twitter = new Zend_Service_Twitter;
  169. $twitter->setLocalHttpClient($this->_stubTwitter(
  170. 'account/verify_credentials.xml', Zend_Http_Client::GET, 'account.verify_credentials.xml'
  171. ));
  172. $response = $twitter->account->verifyCredentials();
  173. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  174. }
  175. public function testPublicTimelineStatusReturnsResults()
  176. {
  177. $twitter = new Zend_Service_Twitter;
  178. $twitter->setLocalHttpClient($this->_stubTwitter(
  179. 'statuses/public_timeline.xml', Zend_Http_Client::GET, 'public_timeline.xml'
  180. ));
  181. $response = $twitter->status->publicTimeline();
  182. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  183. }
  184. public function testRateLimitStatusReturnsResults()
  185. {
  186. $twitter = new Zend_Service_Twitter;
  187. $twitter->setLocalHttpClient($this->_stubTwitter(
  188. 'account/rate_limit_status.xml', Zend_Http_Client::GET, 'rate_limit_status.xml'
  189. ));
  190. $response = $twitter->account->rateLimitStatus();
  191. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  192. }
  193. public function testRateLimitStatusHasHitsLeft()
  194. {
  195. $twitter = new Zend_Service_Twitter;
  196. $twitter->setLocalHttpClient($this->_stubTwitter(
  197. 'account/rate_limit_status.xml', Zend_Http_Client::GET, 'rate_limit_status.xml'
  198. ));
  199. $response = $twitter->account->rateLimitStatus();
  200. $remaining_hits = $response->toValue($response->{'remaining-hits'});
  201. $this->assertEquals(150, $remaining_hits);
  202. }
  203. public function testAccountEndSession()
  204. {
  205. $twitter = new Zend_Service_Twitter;
  206. $twitter->setLocalHttpClient($this->_stubTwitter(
  207. 'account/end_session', Zend_Http_Client::GET
  208. ));
  209. $response = $twitter->account->endSession();
  210. $this->assertTrue($response);
  211. }
  212. /**
  213. * TODO: Check actual purpose. New friend returns XML response, existing
  214. * friend returns a 403 code.
  215. */
  216. public function testFriendshipCreate()
  217. {
  218. $twitter = new Zend_Service_Twitter;
  219. $twitter->setLocalHttpClient($this->_stubTwitter(
  220. 'friendships/create/twitter.xml', Zend_Http_Client::POST, 'friendships.create.twitter.xml'
  221. ));
  222. $response = $twitter->friendship->create('twitter');
  223. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  224. }
  225. /**
  226. * TODO: Mismatched behaviour from API. Per the API this can assert the
  227. * existence of a friendship between any two users (not just the current
  228. * user). We should expand the method or add a better fit method for
  229. * general use.
  230. */
  231. public function testFriendshipExists()
  232. {
  233. $twitter = new Zend_Service_Twitter('padraicb');
  234. $twitter->setLocalHttpClient($this->_stubTwitter(
  235. 'friendships/exists.xml', Zend_Http_Client::GET, 'friendships.exists.twitter.xml',
  236. array('user_a'=>'padraicb', 'user_b'=>'twitter')
  237. ));
  238. $response = $twitter->friendship->exists('twitter');
  239. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  240. }
  241. public function testFriendsTimelineWithPageReturnsResults()
  242. {
  243. $twitter = new Zend_Service_Twitter;
  244. $twitter->setLocalHttpClient($this->_stubTwitter(
  245. 'statuses/friends_timeline.xml', Zend_Http_Client::GET, 'statuses.friends_timeline.page.xml',
  246. array('page'=>3)
  247. ));
  248. $response = $twitter->status->friendsTimeline(array('page' => 3));
  249. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  250. }
  251. /**
  252. * @return void
  253. */
  254. public function testFriendsTimelineWithCountReturnsResults()
  255. {$this->markTestIncomplete();
  256. /* @var $response Zend_Rest_Client_Result */
  257. $response = $this->twitter->status->friendsTimeline(array('id' => 'zftestuser1', 'count' => '2'));
  258. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  259. $httpClient = $this->twitter->getLocalHttpClient();
  260. $httpRequest = $httpClient->getLastRequest();
  261. $httpResponse = $httpClient->getLastResponse();
  262. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  263. $this->assertTrue(isset($response->status));
  264. $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  265. }
  266. /**
  267. * @return void
  268. */
  269. public function testUserTimelineStatusWithPageAndTwoTweetsReturnsResults()
  270. {$this->markTestIncomplete();
  271. /* @var $response Zend_Rest_Client_Result */
  272. $response = $this->twitter->status->userTimeline(array('id' => 'zftestuser1', 'count' => 2));
  273. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  274. $httpClient = $this->twitter->getLocalHttpClient();
  275. $httpRequest = $httpClient->getLastRequest();
  276. $httpResponse = $httpClient->getLastResponse();
  277. $raw_response = $httpResponse->getHeadersAsString() . $httpResponse->getBody();
  278. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  279. $this->assertTrue(isset($response->status));
  280. $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  281. }
  282. public function testUserTimelineStatusShouldReturnFortyResults()
  283. {$this->markTestIncomplete();
  284. /* @var $response Zend_Rest_Client_Result */
  285. $response = $this->twitter->status->userTimeline(array('id' => 'zftestuser1', 'count' => 40));
  286. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  287. $httpClient = $this->twitter->getLocalHttpClient();
  288. $httpRequest = $httpClient->getLastRequest();
  289. $httpResponse = $httpClient->getLastResponse();
  290. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  291. $this->assertTrue(isset($response->status));
  292. $this->assertEquals(40, count($response->status));
  293. }
  294. /**
  295. * @return void
  296. */
  297. public function testPostStatusUpdateReturnsResponse()
  298. {$this->markTestIncomplete();
  299. /* @var $response Zend_Rest_Client_Result */
  300. $response = $this->twitter->status->update('Test Message - ' . rand());
  301. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  302. $httpClient = $this->twitter->getLocalHttpClient();
  303. $httpRequest = $httpClient->getLastRequest();
  304. $httpResponse = $httpClient->getLastResponse();
  305. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  306. $this->assertTrue(isset($response->status));
  307. }
  308. /**
  309. * $return void
  310. */
  311. public function testPostStatusUpdateToLongShouldThrowException()
  312. {$this->markTestIncomplete();
  313. try {
  314. $response = $this->twitter->status->update('Test Message - ' . str_repeat(' Hello ', 140));
  315. $this->fail('Trying to post a status with > 140 character should throw exception');
  316. } catch (Exception $e) {
  317. }
  318. }
  319. public function testPostStatusUpdateUTF8ShouldNotThrowException()
  320. {$this->markTestIncomplete();
  321. try {
  322. $response = $this->twitter->status->update(str_repeat('M�r', 46) . 'M�');
  323. } catch (Exception $e) {
  324. $this->fail('Trying to post a utf8 string of 140 chars should not throw exception');
  325. }
  326. }
  327. /**
  328. * $return void
  329. */
  330. public function testPostStatusUpdateEmptyShouldThrowException()
  331. {$this->markTestIncomplete();
  332. try {
  333. $response = $this->twitter->status->update('');
  334. $this->fail('Trying to post an empty status should throw exception');
  335. } catch (Exception $e) {
  336. }
  337. }
  338. /**
  339. * @return void
  340. */
  341. public function testShowStatusReturnsResponse()
  342. {$this->markTestIncomplete();
  343. $response = $this->twitter->status->publicTimeline();
  344. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  345. $status_id = $response->toValue($response->status->id);
  346. $this->assertType('numeric', $status_id);
  347. $response2 = $this->twitter->status->show($status_id);
  348. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  349. $httpClient = $this->twitter->getLocalHttpClient();
  350. $httpRequest = $httpClient->getLastRequest();
  351. $httpResponse = $httpClient->getLastResponse();
  352. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  353. $this->assertTrue(isset($response->status));
  354. }
  355. /**
  356. * @return void
  357. */
  358. public function testCreateFavoriteStatusReturnsResponse()
  359. {$this->markTestIncomplete();
  360. /* @var $response Zend_Rest_Client_Result */
  361. $response = $this->twitter->status->userTimeline();
  362. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  363. $update_id = $response->toValue($response->status->id);
  364. $this->assertType('numeric', $update_id);
  365. $response2 = $this->twitter->favorite->create($update_id);
  366. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  367. $httpClient = $this->twitter->getLocalHttpClient();
  368. $httpRequest = $httpClient->getLastRequest();
  369. $httpResponse = $httpClient->getLastResponse();
  370. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  371. $this->assertTrue(isset($response->status));
  372. }
  373. /**
  374. * @return void
  375. */
  376. public function testFavoriteFavoriesReturnsResponse()
  377. {$this->markTestIncomplete();
  378. $response = $this->twitter->favorite->favorites();
  379. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  380. $httpClient = $this->twitter->getLocalHttpClient();
  381. $httpRequest = $httpClient->getLastRequest();
  382. $httpResponse = $httpClient->getLastResponse();
  383. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  384. $this->assertTrue(isset($response->status));
  385. }
  386. public function testDestroyFavoriteReturnsResponse()
  387. {$this->markTestIncomplete();
  388. $response = $this->twitter->favorite->favorites();
  389. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  390. $update_id = $response->toValue($response->status->id);
  391. $this->assertType('numeric', $update_id);
  392. $response2 = $this->twitter->favorite->destroy($update_id);
  393. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  394. $httpClient = $this->twitter->getLocalHttpClient();
  395. $httpRequest = $httpClient->getLastRequest();
  396. $httpResponse = $httpClient->getLastResponse();
  397. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  398. $this->assertTrue(isset($response->status));
  399. }
  400. public function testStatusDestroyReturnsResult()
  401. {$this->markTestIncomplete();
  402. /* @var $response Zend_Rest_Client_Result */
  403. $response = $this->twitter->status->userTimeline();
  404. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  405. $update_id = $response->toValue($response->status->id);
  406. $this->assertType('numeric', $update_id);
  407. $response2 = $this->twitter->status->destroy($update_id);
  408. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  409. $httpClient = $this->twitter->getLocalHttpClient();
  410. $httpRequest = $httpClient->getLastRequest();
  411. $httpResponse = $httpClient->getLastResponse();
  412. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  413. $this->assertTrue(isset($response->status));
  414. }
  415. public function testUserFriendsReturnsResults()
  416. {$this->markTestIncomplete();
  417. $response = $this->twitter->user->friends();
  418. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  419. $httpClient = $this->twitter->getLocalHttpClient();
  420. $httpRequest = $httpClient->getLastRequest();
  421. $httpResponse = $httpClient->getLastResponse();
  422. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  423. $this->assertTrue(isset($response->status));
  424. }
  425. public function testUserFolloersReturnsResults()
  426. {$this->markTestIncomplete();
  427. $response = $this->twitter->user->followers(array('id' => 'zftestuser1'));
  428. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  429. $httpClient = $this->twitter->getLocalHttpClient();
  430. $httpRequest = $httpClient->getLastRequest();
  431. $httpResponse = $httpClient->getLastResponse();
  432. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  433. $this->assertTrue(isset($response->status));
  434. }
  435. public function testUserFriendsSpecificUserReturnsResults()
  436. {$this->markTestIncomplete();
  437. $response = $this->twitter->user->friends(array('id' => 'ZendRssFeed'));
  438. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  439. $httpClient = $this->twitter->getLocalHttpClient();
  440. $httpRequest = $httpClient->getLastRequest();
  441. $httpResponse = $httpClient->getLastResponse();
  442. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  443. $this->assertTrue(isset($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  444. return $response;
  445. }
  446. public function testUserShowByIdReturnsResults()
  447. {$this->markTestIncomplete();
  448. $userInfo = $this->testUserFriendsSpecificUserReturnsResults();
  449. $userId = $userInfo->toValue($userInfo->user->id);
  450. $response = $this->twitter->user->show($userId);
  451. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  452. $this->assertEquals($userInfo->toValue($userInfo->user->name), $response->toValue($response->name));
  453. $this->assertEquals($userId, $response->toValue($response->id));
  454. }
  455. public function testUserShowByNameReturnsResults()
  456. {$this->markTestIncomplete();
  457. $response = $this->twitter->user->show('zftestuser1');
  458. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  459. $this->assertEquals('zftestuser1', $response->toValue($response->screen_name));
  460. }
  461. public function testStatusRepliesReturnsResults()
  462. {$this->markTestIncomplete();
  463. $response = $this->twitter->status->replies(array('page' => 1, 'since_id' => 10000, 'invalid_option' => 'doh'));
  464. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  465. $httpClient = $this->twitter->getLocalHttpClient();
  466. $httpRequest = $httpClient->getLastRequest();
  467. $httpResponse = $httpClient->getLastResponse();
  468. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  469. }
  470. /**
  471. * @return void
  472. */
  473. public function testFriendshipDestory()
  474. {$this->markTestIncomplete();
  475. $response = $this->twitter->friendship->destroy('zftestuser1');
  476. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  477. $httpClient = $this->twitter->getLocalHttpClient();
  478. $httpRequest = $httpClient->getLastRequest();
  479. $httpResponse = $httpClient->getLastResponse();
  480. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  481. }
  482. /**
  483. * @return void
  484. */
  485. public function testBlockingCreate()
  486. {$this->markTestIncomplete();
  487. $response = $this->twitter->block->create('zftestuser1');
  488. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  489. $this->assertEquals('zftestuser1', (string) $response->screen_name);
  490. }
  491. /**
  492. * @return void
  493. */
  494. public function testBlockingExistsReturnsTrueWhenBlockExists()
  495. {$this->markTestIncomplete();
  496. $this->assertTrue($this->twitter->block->exists('zftestuser1'));
  497. }
  498. /**
  499. * @return void
  500. */
  501. public function testBlockingBlocked()
  502. {$this->markTestIncomplete();
  503. $response = $this->twitter->block->blocking();
  504. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  505. $this->assertEquals('zftestuser1', (string) $response->user->screen_name);
  506. }
  507. /**
  508. * @return void
  509. */
  510. public function testBlockingBlockedReturnsIds()
  511. {$this->markTestIncomplete();
  512. $response = $this->twitter->block->blocking(1, true);
  513. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  514. $this->assertEquals('16935247', (string) $response->id);
  515. }
  516. /**
  517. * @return void
  518. */
  519. public function testBlockingDestroy()
  520. {$this->markTestIncomplete();
  521. $response = $this->twitter->block->destroy('zftestuser1');
  522. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  523. $this->assertEquals('zftestuser1', (string) $response->screen_name);
  524. }
  525. /**
  526. * @return void
  527. */
  528. public function testBlockingExistsReturnsFalseWhenBlockDoesNotExists()
  529. {$this->markTestIncomplete();
  530. $this->assertFalse($this->twitter->block->exists('zftestuser1'));
  531. }
  532. /**
  533. * @return void
  534. */
  535. public function testBlockingExistsReturnsOjectWhenFlagPassed()
  536. {$this->markTestIncomplete();
  537. $response = $this->twitter->block->exists('zftestuser1', true);
  538. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  539. }
  540. /**
  541. * Insert Test Data
  542. *
  543. */
  544. protected function insertTestTwitterData()
  545. {$this->markTestIncomplete();
  546. $twitter = new Zend_Service_Twitter('zftestuser1', 'zftestuser1');
  547. // create 10 new entries
  548. for ($x = 0; $x < 10; $x++) {
  549. $twitter->status->update('Test Message - ' . $x);
  550. }
  551. $twitter->account->endSession();
  552. }
  553. /**
  554. * @group ZF-6284
  555. */
  556. public function testTwitterObjectsSoNotShareSameHttpClientToPreventConflictingAuthentication()
  557. {$this->markTestIncomplete();
  558. $twitter1 = new Zend_Service_Twitter('zftestuser1', 'zftestuser1');
  559. $twitter2 = new Zend_Service_Twitter('zftestuser2', 'zftestuser2');
  560. $this->assertFalse($twitter1->getLocalHttpClient() === $twitter2->getLocalHttpClient());
  561. }
  562. /**
  563. * Quick reusable Twitter Service stub setup.
  564. */
  565. protected function _stubTwitter($path, $method, $responseFile = null, array $params = null)
  566. {
  567. $client = $this->getMock('Zend_Http_Client');
  568. $client->expects($this->any())->method('resetParameters')
  569. ->will($this->returnValue($client));
  570. $client->expects($this->once())->method('setUri')
  571. ->with('http://api.twitter.com/1/' . $path);
  572. $response = $this->getMock('Zend_Http_Response', array(), array(), '', false);
  573. if (!is_null($params)) {
  574. $setter = 'setParameter' . ucfirst(strtolower($method));
  575. $client->expects($this->once())->method($setter)->with($params);
  576. }
  577. $client->expects($this->once())->method('request')->with($method)
  578. ->will($this->returnValue($response));
  579. $response->expects($this->any())->method('getBody')
  580. ->will($this->returnValue(
  581. isset($responseFile) ? file_get_contents(dirname(__FILE__) . '/_files/' . $responseFile) : ''
  582. ));
  583. return $client;
  584. }
  585. }
  586. if (PHPUnit_MAIN_METHOD == 'Zend_Service_TwitterTest2::main') {
  587. Zend_Service_TwitterTest2::main();
  588. }