2
0

TwitterTest.php 26 KB

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