TwitterTest.php 26 KB

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