TwitterTest.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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) 2006 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once 'PHPUnit/Framework/TestCase.php';
  22. require_once 'PHPUnit/Framework/TestSuite.php';
  23. /** Zend_Service_Twitter */
  24. require_once 'Zend/Service/Twitter.php';
  25. /** Zend_Http_Client */
  26. require_once 'Zend/Http/Client.php';
  27. /** Zend_Http_Client_Adapter_Test */
  28. require_once 'Zend/Http/Client/Adapter/Test.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Service_Twitter
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Service_TwitterTest extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * Change these to your login credentials for testing
  40. */
  41. const TWITTER_USER = 'zftestuser';
  42. const TWITTER_PASS = 'zftestuser';
  43. /**
  44. * Runs the test methods of this class.
  45. *
  46. * @return void
  47. */
  48. public static function main()
  49. {
  50. require_once 'PHPUnit/TextUI/TestRunner.php';
  51. $suite = new PHPUnit_Framework_TestSuite('Zend_Service_TwitterTest');
  52. $result = PHPUnit_TextUI_TestRunner::run($suite);
  53. }
  54. /**
  55. * Sets up the fixture, for example, open a network connection.
  56. * This method is called before a test is executed.
  57. *
  58. * @return void
  59. */
  60. protected function setUp()
  61. {
  62. Zend_Service_Abstract::getHttpClient()->setAdapter('Zend_Http_Client_Adapter_Socket');
  63. $this->twitter = new Zend_Service_Twitter(self::TWITTER_USER, self::TWITTER_PASS);
  64. /*$adapter = new Zend_Http_Client_Adapter_Test();
  65. $client = new Zend_Http_Client(null, array(
  66. 'adapter' => $adapter
  67. ));
  68. $this->adapter = $adapter;
  69. Zend_Service_Twitter::setHttpClient($client);*/
  70. }
  71. /**
  72. * Tears down the fixture, for example, close a network connection.
  73. * This method is called after a test is executed.
  74. *
  75. * @return void
  76. */
  77. protected function tearDown()
  78. {
  79. // unset($this->adapter);
  80. }
  81. /**
  82. * @return void
  83. */
  84. public function testConstructorShouldSetUsernameAndPassword()
  85. {
  86. $this->assertEquals('zftestuser', $this->twitter->getUsername());
  87. $this->assertEquals('zftestuser', $this->twitter->getPassword());
  88. }
  89. /**
  90. * @return void
  91. */
  92. public function testUsernameAccessorsShouldAllowSettingAndRetrievingUsername()
  93. {
  94. $this->twitter->setUsername('foo');
  95. $this->assertEquals('foo', $this->twitter->getUsername());
  96. }
  97. /**
  98. * @return void
  99. */
  100. public function testPasswordAccessorsShouldAllowSettingAndRetrievingPassword()
  101. {
  102. $this->twitter->setPassword('foo');
  103. $this->assertEquals('foo', $this->twitter->getPassword());
  104. }
  105. /**
  106. * @return void
  107. */
  108. public function testOverloadingGetShouldReturnObjectInstanceWithValidMethodType()
  109. {
  110. try {
  111. $return = $this->twitter->status;
  112. $this->assertSame($this->twitter, $return);
  113. } catch (Exception $e) {
  114. $this->fail('Property overloading with a valid method type should not throw an exception');
  115. }
  116. }
  117. /**
  118. * @return void
  119. */
  120. public function testOverloadingGetShouldthrowExceptionWithInvalidMethodType()
  121. {
  122. try {
  123. $return = $this->twitter->foo;
  124. $this->fail('Property overloading with an invalid method type should throw an exception');
  125. } catch (Exception $e) {
  126. }
  127. }
  128. /**
  129. * @return void
  130. */
  131. public function testOverloadingGetShouldthrowExceptionWithInvalidFunction()
  132. {
  133. try {
  134. $return = $this->twitter->foo();
  135. $this->fail('Property overloading with an invalid function should throw an exception');
  136. } catch (Exception $e) {
  137. }
  138. }
  139. /**
  140. * @return void
  141. */
  142. public function testMethodProxyingDoesNotThrowExceptionsWithValidMethods()
  143. {
  144. try {
  145. $this->twitter->status->publicTimeline();
  146. } catch (Exception $e) {
  147. $this->fail('Method proxying should not throw an exception with valid methods; exception: ' . $e->getMessage());
  148. }
  149. }
  150. /**
  151. * @return void
  152. */
  153. public function testMethodProxyingThrowExceptionsWithInvalidMethods()
  154. {
  155. try {
  156. $this->twitter->status->foo();
  157. $this->fail('Method proxying should throw an exception with invalid methods');
  158. } catch (Exception $e) {
  159. }
  160. }
  161. /**
  162. * @return void
  163. */
  164. public function testVerifiedCredentials()
  165. {
  166. $response = $this->twitter->account->verifyCredentials();
  167. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  168. $httpClient = Zend_Service_Twitter::getHttpClient();
  169. $httpRequest = $httpClient->getLastRequest();
  170. $httpResponse = $httpClient->getLastResponse();
  171. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  172. }
  173. /**
  174. * @return void
  175. */
  176. public function testPublicTimelineStatusReturnsResults()
  177. {
  178. $response = $this->twitter->status->publicTimeline();
  179. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  180. $httpClient = Zend_Service_Twitter::getHttpClient();
  181. $httpRequest = $httpClient->getLastRequest();
  182. $httpResponse = $httpClient->getLastResponse();
  183. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  184. $this->assertTrue(isset($response->status));
  185. }
  186. /**
  187. * @return void
  188. */
  189. public function testUsersFeaturedStatusReturnsResults()
  190. {
  191. $response = $this->twitter->user->featured();
  192. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  193. $httpClient = Zend_Service_Twitter::getHttpClient();
  194. $httpRequest = $httpClient->getLastRequest();
  195. $httpResponse = $httpClient->getLastResponse();
  196. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  197. $this->assertTrue(isset($response->status));
  198. }
  199. public function testRateLimitStatusReturnsResults()
  200. {
  201. /* @var $response Zend_Rest_Client_Result */
  202. $response = $this->twitter->account->rateLimitStatus();
  203. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  204. $httpClient = Zend_Service_Twitter::getHttpClient();
  205. $httpRequest = $httpClient->getLastRequest();
  206. $httpResponse = $httpClient->getLastResponse();
  207. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  208. }
  209. public function testRateLimitStatusHasHitsLeft()
  210. {
  211. /* @var $response Zend_Rest_Client_Result */
  212. $response = $this->twitter->account->rateLimitStatus();
  213. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  214. $remaining_hits = $response->toValue($response->{'remaining-hits'});
  215. $this->assertType('numeric', $remaining_hits);
  216. $this->assertGreaterThan(0, $remaining_hits);
  217. }
  218. /**
  219. * @return void
  220. */
  221. public function testAccountEndSession()
  222. {
  223. $response = $this->twitter->account->endSession();
  224. $this->assertTrue($response);
  225. }
  226. /**
  227. * @return void
  228. */
  229. public function testFriendshipCreate()
  230. {
  231. $response = $this->twitter->friendship->create('zftestuser1');
  232. $httpClient = Zend_Service_Twitter::getHttpClient();
  233. $httpResponse = $httpClient->getLastResponse();
  234. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  235. }
  236. /**
  237. * @return void
  238. */
  239. public function testFriendshipExists()
  240. {
  241. /* @var $response Zend_Rest_Client_Result */
  242. $response = $this->twitter->friendship->exists('zftestuser1');
  243. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  244. $httpClient = Zend_Service_Twitter::getHttpClient();
  245. $httpRequest = $httpClient->getLastRequest();
  246. $httpResponse = $httpClient->getLastResponse();
  247. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  248. }
  249. /**
  250. * @return void
  251. */
  252. public function testFriendsTimelineWithInvalidParamReturnsResults()
  253. {
  254. /* @var $response Zend_Rest_Client_Result */
  255. $response = $this->twitter->status->friendsTimeline( array('foo' => 'bar') );
  256. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  257. $httpClient = Zend_Service_Twitter::getHttpClient();
  258. $httpRequest = $httpClient->getLastRequest();
  259. $httpResponse = $httpClient->getLastResponse();
  260. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  261. $this->assertTrue(isset($response->status));
  262. }
  263. /**
  264. * @return void
  265. */
  266. public function testFriendsTimelineStatusWithFriendSpecifiedReturnsResults()
  267. {
  268. /* @var $response Zend_Rest_Client_Result */
  269. $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1') );
  270. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  271. $httpClient = Zend_Service_Twitter::getHttpClient();
  272. $httpRequest = $httpClient->getLastRequest();
  273. $httpResponse = $httpClient->getLastResponse();
  274. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  275. $this->assertTrue(isset($response->status));
  276. }
  277. /**
  278. * @return void
  279. */
  280. public function testUserTimelineStatusSinceTwoDaysAgoDateAsStringReturnsResults()
  281. {
  282. $this->insertTestTwitterData();
  283. $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'since' => '-2 days') );
  284. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  285. $httpClient = Zend_Service_Twitter::getHttpClient();
  286. $httpRequest = $httpClient->getLastRequest();
  287. $httpResponse = $httpClient->getLastResponse();
  288. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  289. $this->assertTrue(isset($response->status));
  290. }
  291. /**
  292. * @return void
  293. */
  294. public function testUserTimelineStatusSinceTwoDaysAgoDateAsIntegerReturnsResults()
  295. {
  296. $this->insertTestTwitterData();
  297. $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'since' => strtotime('-2 days')) );
  298. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  299. $httpClient = Zend_Service_Twitter::getHttpClient();
  300. $httpRequest = $httpClient->getLastRequest();
  301. $httpResponse = $httpClient->getLastResponse();
  302. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  303. $this->assertTrue(isset($response->status));
  304. }
  305. /**
  306. * @return void
  307. */
  308. public function testFriendsTimelineStatusSinceTwoDaysAgoReturnsResults()
  309. {
  310. /* @var $response Zend_Rest_Client_Result */
  311. $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1', 'since' => '-2 days') );
  312. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  313. $httpClient = Zend_Service_Twitter::getHttpClient();
  314. $httpRequest = $httpClient->getLastRequest();
  315. $httpResponse = $httpClient->getLastResponse();
  316. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  317. $this->assertTrue(isset($response->status));
  318. }
  319. /**
  320. * @return void
  321. */
  322. public function testFriendsTimelineWithPageReturnsResults()
  323. {
  324. /* @var $response Zend_Rest_Client_Result */
  325. $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1', 'page' => '2') );
  326. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  327. $httpClient = Zend_Service_Twitter::getHttpClient();
  328. $httpRequest = $httpClient->getLastRequest();
  329. $httpResponse = $httpClient->getLastResponse();
  330. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  331. $this->assertTrue(isset($response->status));
  332. }
  333. /**
  334. * @return void
  335. */
  336. public function testFriendsTimelineWithCountReturnsResults()
  337. {
  338. /* @var $response Zend_Rest_Client_Result */
  339. $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1', 'count' => '2') );
  340. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  341. $httpClient = Zend_Service_Twitter::getHttpClient();
  342. $httpRequest = $httpClient->getLastRequest();
  343. $httpResponse = $httpClient->getLastResponse();
  344. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  345. $this->assertTrue(isset($response->status));
  346. $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  347. }
  348. /**
  349. * @return void
  350. */
  351. public function testUserTimelineStatusWithPageAndTwoTweetsReturnsResults()
  352. {
  353. /* @var $response Zend_Rest_Client_Result */
  354. $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'count' => 2) );
  355. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  356. $httpClient = Zend_Service_Twitter::getHttpClient();
  357. $httpRequest = $httpClient->getLastRequest();
  358. $httpResponse = $httpClient->getLastResponse();
  359. $raw_response = $httpResponse->getHeadersAsString() . $httpResponse->getBody();
  360. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  361. $this->assertTrue(isset($response->status));
  362. $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  363. }
  364. public function testUserTimelineStatusShouldReturnFortyResults()
  365. {
  366. /* @var $response Zend_Rest_Client_Result */
  367. $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'count' => 40) );
  368. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  369. $httpClient = Zend_Service_Twitter::getHttpClient();
  370. $httpRequest = $httpClient->getLastRequest();
  371. $httpResponse = $httpClient->getLastResponse();
  372. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  373. $this->assertTrue(isset($response->status));
  374. $this->assertEquals(40, count($response->status));
  375. }
  376. /**
  377. * @return void
  378. */
  379. public function testPostStatusUpdateReturnsResponse()
  380. {
  381. /* @var $response Zend_Rest_Client_Result */
  382. $response = $this->twitter->status->update( 'Test Message - ' . rand() );
  383. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  384. $httpClient = Zend_Service_Twitter::getHttpClient();
  385. $httpRequest = $httpClient->getLastRequest();
  386. $httpResponse = $httpClient->getLastResponse();
  387. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  388. $this->assertTrue(isset($response->status));
  389. }
  390. /**
  391. * $return void
  392. */
  393. public function testPostStatusUpdateToLongShouldThrowException()
  394. {
  395. try {
  396. $response = $this->twitter->status->update( 'Test Message - ' . str_repeat(' Hello ', 140) );
  397. $this->fail('Trying to post a status with > 140 character should throw exception');
  398. } catch (Exception $e) {
  399. }
  400. }
  401. public function testPostStatusUpdateUTF8ShouldNotThrowException()
  402. {
  403. try {
  404. $response = $this->twitter->status->update( str_repeat('M�r', 46) . 'M�' );
  405. } catch (Exception $e) {
  406. $this->fail('Trying to post a utf8 string of 140 chars should not throw exception');
  407. }
  408. }
  409. /**
  410. * $return void
  411. */
  412. public function testPostStatusUpdateEmptyShouldThrowException()
  413. {
  414. try {
  415. $response = $this->twitter->status->update('');
  416. $this->fail('Trying to post an empty status should throw exception');
  417. } catch (Exception $e) {
  418. }
  419. }
  420. /**
  421. * @return void
  422. */
  423. public function testShowStatusReturnsResponse()
  424. {
  425. $response = $this->twitter->status->publicTimeline();
  426. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  427. $status_id = $response->toValue($response->status->id);
  428. $this->assertType('numeric', $status_id);
  429. $response2 = $this->twitter->status->show($status_id);
  430. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  431. $httpClient = Zend_Service_Twitter::getHttpClient();
  432. $httpRequest = $httpClient->getLastRequest();
  433. $httpResponse = $httpClient->getLastResponse();
  434. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  435. $this->assertTrue(isset($response->status));
  436. }
  437. /**
  438. * @return void
  439. */
  440. public function testCreateFavoriteStatusReturnsResponse()
  441. {
  442. /* @var $response Zend_Rest_Client_Result */
  443. $response = $this->twitter->status->userTimeline();
  444. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  445. $update_id = $response->toValue($response->status->id);
  446. $this->assertType('numeric', $update_id);
  447. $response2 = $this->twitter->favorite->create($update_id);
  448. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  449. $httpClient = Zend_Service_Twitter::getHttpClient();
  450. $httpRequest = $httpClient->getLastRequest();
  451. $httpResponse = $httpClient->getLastResponse();
  452. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  453. $this->assertTrue(isset($response->status));
  454. }
  455. /**
  456. * @return void
  457. */
  458. public function testFavoriteFavoriesReturnsResponse()
  459. {
  460. $response = $this->twitter->favorite->favorites();
  461. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  462. $httpClient = Zend_Service_Twitter::getHttpClient();
  463. $httpRequest = $httpClient->getLastRequest();
  464. $httpResponse = $httpClient->getLastResponse();
  465. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  466. $this->assertTrue(isset($response->status));
  467. }
  468. public function testDestroyFavoriteReturnsResponse()
  469. {
  470. $response = $this->twitter->favorite->favorites();
  471. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  472. $update_id = $response->toValue($response->status->id);
  473. $this->assertType('numeric', $update_id);
  474. $response2 = $this->twitter->favorite->destroy($update_id);
  475. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  476. $httpClient = Zend_Service_Twitter::getHttpClient();
  477. $httpRequest = $httpClient->getLastRequest();
  478. $httpResponse = $httpClient->getLastResponse();
  479. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  480. $this->assertTrue(isset($response->status));
  481. }
  482. public function testStatusDestroyReturnsResult()
  483. {
  484. /* @var $response Zend_Rest_Client_Result */
  485. $response = $this->twitter->status->userTimeline();
  486. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  487. $update_id = $response->toValue($response->status->id);
  488. $this->assertType('numeric', $update_id);
  489. $response2 = $this->twitter->status->destroy($update_id);
  490. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  491. $httpClient = Zend_Service_Twitter::getHttpClient();
  492. $httpRequest = $httpClient->getLastRequest();
  493. $httpResponse = $httpClient->getLastResponse();
  494. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  495. $this->assertTrue(isset($response->status));
  496. }
  497. public function testUserFriendsReturnsResults()
  498. {
  499. $response = $this->twitter->user->friends();
  500. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  501. $httpClient = Zend_Service_Twitter::getHttpClient();
  502. $httpRequest = $httpClient->getLastRequest();
  503. $httpResponse = $httpClient->getLastResponse();
  504. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  505. $this->assertTrue(isset($response->status));
  506. }
  507. public function testUserFolloersReturnsResults()
  508. {
  509. $response = $this->twitter->user->followers(array('id' =>'zftestuser1'));
  510. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  511. $httpClient = Zend_Service_Twitter::getHttpClient();
  512. $httpRequest = $httpClient->getLastRequest();
  513. $httpResponse = $httpClient->getLastResponse();
  514. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  515. $this->assertTrue(isset($response->status));
  516. }
  517. public function testUserFriendsSpecificUserReturnsResults()
  518. {
  519. $response = $this->twitter->user->friends(array('id' =>'zftestuser1'));
  520. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  521. $httpClient = Zend_Service_Twitter::getHttpClient();
  522. $httpRequest = $httpClient->getLastRequest();
  523. $httpResponse = $httpClient->getLastResponse();
  524. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  525. $this->assertTrue(isset($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  526. return $response;
  527. }
  528. public function testUserShowReturnsResults()
  529. {
  530. $userInfo = $this->testUserFriendsSpecificUserReturnsResults();
  531. $userId = $userInfo->toValue($userInfo->user->id);
  532. $response = $this->twitter->user->show($userId);
  533. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  534. $this->assertEquals($userInfo->toValue($userInfo->user->name), $response->toValue($response->name));
  535. $this->assertEquals($userId, $response->toValue($response->id));
  536. }
  537. public function testStatusRepliesReturnsResults()
  538. {
  539. $response = $this->twitter->status->replies(array('since' => '-800 days', 'page' => 1, 'since_id' => 10000, 'invalid_option' => 'doh'));
  540. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  541. $httpClient = Zend_Service_Twitter::getHttpClient();
  542. $httpRequest = $httpClient->getLastRequest();
  543. $httpResponse = $httpClient->getLastResponse();
  544. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  545. }
  546. /**
  547. * @return void
  548. */
  549. public function testFriendshipDestory()
  550. {
  551. $response = $this->twitter->friendship->destroy('zftestuser1');
  552. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  553. $httpClient = Zend_Service_Twitter::getHttpClient();
  554. $httpRequest = $httpClient->getLastRequest();
  555. $httpResponse = $httpClient->getLastResponse();
  556. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  557. }
  558. /**
  559. * Insert Test Data
  560. *
  561. */
  562. protected function insertTestTwitterData()
  563. {
  564. $twitter = new Zend_Service_Twitter('zftestuser1','zftestuser1');
  565. // create 10 new entries
  566. for($x=0; $x<10; $x++) {
  567. $twitter->status->update( 'Test Message - ' . $x);
  568. }
  569. $twitter->account->endSession();
  570. }
  571. }