TwitterTest.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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. * @issue ZF-7781
  78. */
  79. public function testValidationOfScreenNames_NoError()
  80. {
  81. $response = $this->twitter->status->userTimeline(array('screen_name'=>'abc123_abc123_abc123'));
  82. }
  83. /**
  84. * @issue ZF-7781
  85. */
  86. public function testValidationOfScreenNames_InvalidChar()
  87. {
  88. $this->setExpectedException('Zend_Service_Twitter_Exception');
  89. $response = $this->twitter->status->userTimeline(array('screen_name'=>'abc.def'));
  90. }
  91. /**
  92. * @issue ZF-7781
  93. */
  94. public function testValidationOfScreenNames_InvalidLength()
  95. {
  96. $this->setExpectedException('Zend_Service_Twitter_Exception');
  97. $response = $this->twitter->status->userTimeline(array('screen_name'=>'abcdef_abc123_abc123x'));
  98. }
  99. /**
  100. * @issue ZF-7781
  101. */
  102. public function testStatusUserTimelineConstructsExpectedGetUriAndOmitsInvalidParams()
  103. {
  104. $client = new Zend_Http_Client;
  105. $client->setAdapter(new Zend_Http_Client_Adapter_Test);
  106. Zend_Service_Twitter::setHttpClient($client);
  107. $twitter = new Zend_Service_Twitter(
  108. TESTS_ZEND_SERVICE_TWITTER_USER,
  109. TESTS_ZEND_SERVICE_TWITTER_PASS
  110. );
  111. try {
  112. $twitter->status->userTimeline(array(
  113. 'id' => '123',
  114. 'since' => '+2 days', /* invalid param since Apr 2009 */
  115. 'page' => '1',
  116. 'count' => '123',
  117. 'user_id' => '123',
  118. 'since_id' => '123',
  119. 'max_id' => '123',
  120. 'screen_name'=>'abcdef'
  121. ));
  122. } catch (Zend_Rest_Client_Result_Exception $e) {}
  123. $this->assertContains(
  124. 'GET /statuses/user_timeline/123.xml?page=1&count=123&user_id=123&since_id=123&max_id=123&screen_name=abcdef',
  125. $client->getLastRequest()
  126. );
  127. }
  128. /**
  129. * @return void
  130. */
  131. public function testConstructorShouldSetUsernameAndPassword()
  132. {
  133. $this->assertEquals(TESTS_ZEND_SERVICE_TWITTER_USER, $this->twitter->getUsername());
  134. $this->assertEquals(TESTS_ZEND_SERVICE_TWITTER_PASS, $this->twitter->getPassword());
  135. }
  136. /**
  137. * @return void
  138. */
  139. public function testConstructorShouldAllowUsernamePasswordAsArray()
  140. {
  141. $userInfo = array('username' => 'foo', 'password' => 'bar');
  142. $twit = new Zend_Service_Twitter($userInfo);
  143. $this->assertEquals('foo', $twit->getUsername());
  144. $this->assertEquals('bar', $twit->getPassword());
  145. }
  146. /**
  147. * @return void
  148. */
  149. public function testUsernameAccessorsShouldAllowSettingAndRetrievingUsername()
  150. {
  151. $this->twitter->setUsername('foo');
  152. $this->assertEquals('foo', $this->twitter->getUsername());
  153. }
  154. /**
  155. * @return void
  156. */
  157. public function testPasswordAccessorsShouldAllowSettingAndRetrievingPassword()
  158. {
  159. $this->twitter->setPassword('foo');
  160. $this->assertEquals('foo', $this->twitter->getPassword());
  161. }
  162. /**
  163. * @return void
  164. */
  165. public function testOverloadingGetShouldReturnObjectInstanceWithValidMethodType()
  166. {
  167. try {
  168. $return = $this->twitter->status;
  169. $this->assertSame($this->twitter, $return);
  170. } catch (Exception $e) {
  171. $this->fail('Property overloading with a valid method type should not throw an exception');
  172. }
  173. }
  174. /**
  175. * @return void
  176. */
  177. public function testOverloadingGetShouldthrowExceptionWithInvalidMethodType()
  178. {
  179. try {
  180. $return = $this->twitter->foo;
  181. $this->fail('Property overloading with an invalid method type should throw an exception');
  182. } catch (Exception $e) {
  183. }
  184. }
  185. /**
  186. * @return void
  187. */
  188. public function testOverloadingGetShouldthrowExceptionWithInvalidFunction()
  189. {
  190. try {
  191. $return = $this->twitter->foo();
  192. $this->fail('Property overloading with an invalid function should throw an exception');
  193. } catch (Exception $e) {
  194. }
  195. }
  196. /**
  197. * @return void
  198. */
  199. public function testMethodProxyingDoesNotThrowExceptionsWithValidMethods()
  200. {
  201. try {
  202. $this->twitter->status->publicTimeline();
  203. } catch (Exception $e) {
  204. $this->fail('Method proxying should not throw an exception with valid methods; exception: ' . $e->getMessage());
  205. }
  206. }
  207. /**
  208. * @return void
  209. */
  210. public function testMethodProxyingThrowExceptionsWithInvalidMethods()
  211. {
  212. try {
  213. $this->twitter->status->foo();
  214. $this->fail('Method proxying should throw an exception with invalid methods');
  215. } catch (Exception $e) {
  216. }
  217. }
  218. /**
  219. * @return void
  220. */
  221. public function testVerifiedCredentials()
  222. {
  223. $response = $this->twitter->account->verifyCredentials();
  224. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  225. $httpClient = Zend_Service_Twitter::getHttpClient();
  226. $httpRequest = $httpClient->getLastRequest();
  227. $httpResponse = $httpClient->getLastResponse();
  228. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  229. }
  230. /**
  231. * @return void
  232. */
  233. public function testPublicTimelineStatusReturnsResults()
  234. {
  235. $response = $this->twitter->status->publicTimeline();
  236. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  237. $httpClient = Zend_Service_Twitter::getHttpClient();
  238. $httpRequest = $httpClient->getLastRequest();
  239. $httpResponse = $httpClient->getLastResponse();
  240. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  241. $this->assertTrue(isset($response->status));
  242. }
  243. /**
  244. * @return void
  245. */
  246. public function testUsersFeaturedStatusReturnsResults()
  247. {
  248. $response = $this->twitter->user->featured();
  249. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  250. $httpClient = Zend_Service_Twitter::getHttpClient();
  251. $httpRequest = $httpClient->getLastRequest();
  252. $httpResponse = $httpClient->getLastResponse();
  253. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  254. $this->assertTrue(isset($response->status));
  255. }
  256. public function testRateLimitStatusReturnsResults()
  257. {
  258. /* @var $response Zend_Rest_Client_Result */
  259. $response = $this->twitter->account->rateLimitStatus();
  260. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  261. $httpClient = Zend_Service_Twitter::getHttpClient();
  262. $httpRequest = $httpClient->getLastRequest();
  263. $httpResponse = $httpClient->getLastResponse();
  264. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  265. }
  266. public function testRateLimitStatusHasHitsLeft()
  267. {
  268. /* @var $response Zend_Rest_Client_Result */
  269. $response = $this->twitter->account->rateLimitStatus();
  270. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  271. $remaining_hits = $response->toValue($response->{'remaining-hits'});
  272. $this->assertType('numeric', $remaining_hits);
  273. $this->assertGreaterThan(0, $remaining_hits);
  274. }
  275. /**
  276. * @return void
  277. */
  278. public function testAccountEndSession()
  279. {
  280. $response = $this->twitter->account->endSession();
  281. $this->assertTrue($response);
  282. }
  283. /**
  284. * @return void
  285. */
  286. public function testFriendshipCreate()
  287. {
  288. $response = $this->twitter->friendship->create('zftestuser1');
  289. $httpClient = Zend_Service_Twitter::getHttpClient();
  290. $httpResponse = $httpClient->getLastResponse();
  291. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  292. }
  293. /**
  294. * @return void
  295. */
  296. public function testFriendshipExists()
  297. {
  298. /* @var $response Zend_Rest_Client_Result */
  299. $response = $this->twitter->friendship->exists('zftestuser1');
  300. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  301. $httpClient = Zend_Service_Twitter::getHttpClient();
  302. $httpRequest = $httpClient->getLastRequest();
  303. $httpResponse = $httpClient->getLastResponse();
  304. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  305. }
  306. /**
  307. * @return void
  308. */
  309. public function testFriendsTimelineWithInvalidParamReturnsResults()
  310. {
  311. /* @var $response Zend_Rest_Client_Result */
  312. $response = $this->twitter->status->friendsTimeline( array('foo' => 'bar') );
  313. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  314. $httpClient = Zend_Service_Twitter::getHttpClient();
  315. $httpRequest = $httpClient->getLastRequest();
  316. $httpResponse = $httpClient->getLastResponse();
  317. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  318. $this->assertTrue(isset($response->status));
  319. }
  320. /**
  321. * @return void
  322. */
  323. public function testFriendsTimelineStatusWithFriendSpecifiedReturnsResults()
  324. {
  325. /* @var $response Zend_Rest_Client_Result */
  326. $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1') );
  327. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  328. $httpClient = Zend_Service_Twitter::getHttpClient();
  329. $httpRequest = $httpClient->getLastRequest();
  330. $httpResponse = $httpClient->getLastResponse();
  331. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  332. $this->assertTrue(isset($response->status));
  333. }
  334. /**
  335. * @return void
  336. */
  337. public function testFriendsTimelineWithPageReturnsResults()
  338. {
  339. /* @var $response Zend_Rest_Client_Result */
  340. $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1', 'page' => '2') );
  341. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  342. $httpClient = Zend_Service_Twitter::getHttpClient();
  343. $httpRequest = $httpClient->getLastRequest();
  344. $httpResponse = $httpClient->getLastResponse();
  345. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  346. $this->assertTrue(isset($response->status));
  347. }
  348. /**
  349. * @return void
  350. */
  351. public function testFriendsTimelineWithCountReturnsResults()
  352. {
  353. /* @var $response Zend_Rest_Client_Result */
  354. $response = $this->twitter->status->friendsTimeline( 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. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  360. $this->assertTrue(isset($response->status));
  361. $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  362. }
  363. /**
  364. * @return void
  365. */
  366. public function testUserTimelineStatusWithPageAndTwoTweetsReturnsResults()
  367. {
  368. /* @var $response Zend_Rest_Client_Result */
  369. $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'count' => 2) );
  370. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  371. $httpClient = Zend_Service_Twitter::getHttpClient();
  372. $httpRequest = $httpClient->getLastRequest();
  373. $httpResponse = $httpClient->getLastResponse();
  374. $raw_response = $httpResponse->getHeadersAsString() . $httpResponse->getBody();
  375. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  376. $this->assertTrue(isset($response->status));
  377. $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  378. }
  379. public function testUserTimelineStatusShouldReturnFortyResults()
  380. {
  381. /* @var $response Zend_Rest_Client_Result */
  382. $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'count' => 40) );
  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. $this->assertEquals(40, count($response->status));
  390. }
  391. /**
  392. * @return void
  393. */
  394. public function testPostStatusUpdateReturnsResponse()
  395. {
  396. /* @var $response Zend_Rest_Client_Result */
  397. $response = $this->twitter->status->update( 'Test Message - ' . rand() );
  398. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  399. $httpClient = Zend_Service_Twitter::getHttpClient();
  400. $httpRequest = $httpClient->getLastRequest();
  401. $httpResponse = $httpClient->getLastResponse();
  402. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  403. $this->assertTrue(isset($response->status));
  404. }
  405. /**
  406. * $return void
  407. */
  408. public function testPostStatusUpdateToLongShouldThrowException()
  409. {
  410. try {
  411. $response = $this->twitter->status->update( 'Test Message - ' . str_repeat(' Hello ', 140) );
  412. $this->fail('Trying to post a status with > 140 character should throw exception');
  413. } catch (Exception $e) {
  414. }
  415. }
  416. public function testPostStatusUpdateUTF8ShouldNotThrowException()
  417. {
  418. try {
  419. $response = $this->twitter->status->update( str_repeat('M�r', 46) . 'M�' );
  420. } catch (Exception $e) {
  421. $this->fail('Trying to post a utf8 string of 140 chars should not throw exception');
  422. }
  423. }
  424. /**
  425. * $return void
  426. */
  427. public function testPostStatusUpdateEmptyShouldThrowException()
  428. {
  429. try {
  430. $response = $this->twitter->status->update('');
  431. $this->fail('Trying to post an empty status should throw exception');
  432. } catch (Exception $e) {
  433. }
  434. }
  435. /**
  436. * @return void
  437. */
  438. public function testShowStatusReturnsResponse()
  439. {
  440. $response = $this->twitter->status->publicTimeline();
  441. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  442. $status_id = $response->toValue($response->status->id);
  443. $this->assertType('numeric', $status_id);
  444. $response2 = $this->twitter->status->show($status_id);
  445. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  446. $httpClient = Zend_Service_Twitter::getHttpClient();
  447. $httpRequest = $httpClient->getLastRequest();
  448. $httpResponse = $httpClient->getLastResponse();
  449. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  450. $this->assertTrue(isset($response->status));
  451. }
  452. /**
  453. * @return void
  454. */
  455. public function testCreateFavoriteStatusReturnsResponse()
  456. {
  457. /* @var $response Zend_Rest_Client_Result */
  458. $response = $this->twitter->status->userTimeline();
  459. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  460. $update_id = $response->toValue($response->status->id);
  461. $this->assertType('numeric', $update_id);
  462. $response2 = $this->twitter->favorite->create($update_id);
  463. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  464. $httpClient = Zend_Service_Twitter::getHttpClient();
  465. $httpRequest = $httpClient->getLastRequest();
  466. $httpResponse = $httpClient->getLastResponse();
  467. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  468. $this->assertTrue(isset($response->status));
  469. }
  470. /**
  471. * @return void
  472. */
  473. public function testFavoriteFavoriesReturnsResponse()
  474. {
  475. $response = $this->twitter->favorite->favorites();
  476. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  477. $httpClient = Zend_Service_Twitter::getHttpClient();
  478. $httpRequest = $httpClient->getLastRequest();
  479. $httpResponse = $httpClient->getLastResponse();
  480. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  481. $this->assertTrue(isset($response->status));
  482. }
  483. public function testDestroyFavoriteReturnsResponse()
  484. {
  485. $response = $this->twitter->favorite->favorites();
  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->favorite->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 testStatusDestroyReturnsResult()
  498. {
  499. /* @var $response Zend_Rest_Client_Result */
  500. $response = $this->twitter->status->userTimeline();
  501. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  502. $update_id = $response->toValue($response->status->id);
  503. $this->assertType('numeric', $update_id);
  504. $response2 = $this->twitter->status->destroy($update_id);
  505. $this->assertTrue($response2 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 testUserFriendsReturnsResults()
  513. {
  514. $response = $this->twitter->user->friends();
  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 testUserFolloersReturnsResults()
  523. {
  524. $response = $this->twitter->user->followers(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));
  531. }
  532. public function testUserFriendsSpecificUserReturnsResults()
  533. {
  534. $response = $this->twitter->user->friends(array('id' =>'zftestuser1'));
  535. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  536. $httpClient = Zend_Service_Twitter::getHttpClient();
  537. $httpRequest = $httpClient->getLastRequest();
  538. $httpResponse = $httpClient->getLastResponse();
  539. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  540. $this->assertTrue(isset($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  541. return $response;
  542. }
  543. public function testUserShowReturnsResults()
  544. {
  545. $userInfo = $this->testUserFriendsSpecificUserReturnsResults();
  546. $userId = $userInfo->toValue($userInfo->user->id);
  547. $response = $this->twitter->user->show($userId);
  548. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  549. $this->assertEquals($userInfo->toValue($userInfo->user->name), $response->toValue($response->name));
  550. $this->assertEquals($userId, $response->toValue($response->id));
  551. }
  552. public function testStatusRepliesReturnsResults()
  553. {
  554. $response = $this->twitter->status->replies(array('page' => 1, 'since_id' => 10000, 'invalid_option' => 'doh'));
  555. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  556. $httpClient = Zend_Service_Twitter::getHttpClient();
  557. $httpRequest = $httpClient->getLastRequest();
  558. $httpResponse = $httpClient->getLastResponse();
  559. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  560. }
  561. /**
  562. * @return void
  563. */
  564. public function testFriendshipDestory()
  565. {
  566. $response = $this->twitter->friendship->destroy('zftestuser1');
  567. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  568. $httpClient = Zend_Service_Twitter::getHttpClient();
  569. $httpRequest = $httpClient->getLastRequest();
  570. $httpResponse = $httpClient->getLastResponse();
  571. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  572. }
  573. /**
  574. * Insert Test Data
  575. *
  576. */
  577. protected function insertTestTwitterData()
  578. {
  579. $twitter = new Zend_Service_Twitter('zftestuser1','zftestuser1');
  580. // create 10 new entries
  581. for($x=0; $x<10; $x++) {
  582. $twitter->status->update( 'Test Message - ' . $x);
  583. }
  584. $twitter->account->endSession();
  585. }
  586. }
  587. if (PHPUnit_MAIN_METHOD == 'Zend_Service_TwitterTest::main') {
  588. Zend_Service_TwitterTest::main();
  589. }