TwitterTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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 testFriendsTimelineWithPageReturnsResults()
  286. {
  287. /* @var $response Zend_Rest_Client_Result */
  288. $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1', 'page' => '2') );
  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 testFriendsTimelineWithCountReturnsResults()
  300. {
  301. /* @var $response Zend_Rest_Client_Result */
  302. $response = $this->twitter->status->friendsTimeline( array('id' => 'zftestuser1', 'count' => '2') );
  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. $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  310. }
  311. /**
  312. * @return void
  313. */
  314. public function testUserTimelineStatusWithPageAndTwoTweetsReturnsResults()
  315. {
  316. /* @var $response Zend_Rest_Client_Result */
  317. $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'count' => 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. $raw_response = $httpResponse->getHeadersAsString() . $httpResponse->getBody();
  323. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  324. $this->assertTrue(isset($response->status));
  325. $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  326. }
  327. public function testUserTimelineStatusShouldReturnFortyResults()
  328. {
  329. /* @var $response Zend_Rest_Client_Result */
  330. $response = $this->twitter->status->userTimeline( array('id' => 'zftestuser1', 'count' => 40) );
  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. $this->assertEquals(40, count($response->status));
  338. }
  339. /**
  340. * @return void
  341. */
  342. public function testPostStatusUpdateReturnsResponse()
  343. {
  344. /* @var $response Zend_Rest_Client_Result */
  345. $response = $this->twitter->status->update( 'Test Message - ' . rand() );
  346. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  347. $httpClient = Zend_Service_Twitter::getHttpClient();
  348. $httpRequest = $httpClient->getLastRequest();
  349. $httpResponse = $httpClient->getLastResponse();
  350. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  351. $this->assertTrue(isset($response->status));
  352. }
  353. /**
  354. * $return void
  355. */
  356. public function testPostStatusUpdateToLongShouldThrowException()
  357. {
  358. try {
  359. $response = $this->twitter->status->update( 'Test Message - ' . str_repeat(' Hello ', 140) );
  360. $this->fail('Trying to post a status with > 140 character should throw exception');
  361. } catch (Exception $e) {
  362. }
  363. }
  364. public function testPostStatusUpdateUTF8ShouldNotThrowException()
  365. {
  366. try {
  367. $response = $this->twitter->status->update( str_repeat('M�r', 46) . 'M�' );
  368. } catch (Exception $e) {
  369. $this->fail('Trying to post a utf8 string of 140 chars should not throw exception');
  370. }
  371. }
  372. /**
  373. * $return void
  374. */
  375. public function testPostStatusUpdateEmptyShouldThrowException()
  376. {
  377. try {
  378. $response = $this->twitter->status->update('');
  379. $this->fail('Trying to post an empty status should throw exception');
  380. } catch (Exception $e) {
  381. }
  382. }
  383. /**
  384. * @return void
  385. */
  386. public function testShowStatusReturnsResponse()
  387. {
  388. $response = $this->twitter->status->publicTimeline();
  389. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  390. $status_id = $response->toValue($response->status->id);
  391. $this->assertType('numeric', $status_id);
  392. $response2 = $this->twitter->status->show($status_id);
  393. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  394. $httpClient = Zend_Service_Twitter::getHttpClient();
  395. $httpRequest = $httpClient->getLastRequest();
  396. $httpResponse = $httpClient->getLastResponse();
  397. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  398. $this->assertTrue(isset($response->status));
  399. }
  400. /**
  401. * @return void
  402. */
  403. public function testCreateFavoriteStatusReturnsResponse()
  404. {
  405. /* @var $response Zend_Rest_Client_Result */
  406. $response = $this->twitter->status->userTimeline();
  407. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  408. $update_id = $response->toValue($response->status->id);
  409. $this->assertType('numeric', $update_id);
  410. $response2 = $this->twitter->favorite->create($update_id);
  411. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  412. $httpClient = Zend_Service_Twitter::getHttpClient();
  413. $httpRequest = $httpClient->getLastRequest();
  414. $httpResponse = $httpClient->getLastResponse();
  415. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  416. $this->assertTrue(isset($response->status));
  417. }
  418. /**
  419. * @return void
  420. */
  421. public function testFavoriteFavoriesReturnsResponse()
  422. {
  423. $response = $this->twitter->favorite->favorites();
  424. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  425. $httpClient = Zend_Service_Twitter::getHttpClient();
  426. $httpRequest = $httpClient->getLastRequest();
  427. $httpResponse = $httpClient->getLastResponse();
  428. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  429. $this->assertTrue(isset($response->status));
  430. }
  431. public function testDestroyFavoriteReturnsResponse()
  432. {
  433. $response = $this->twitter->favorite->favorites();
  434. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  435. $update_id = $response->toValue($response->status->id);
  436. $this->assertType('numeric', $update_id);
  437. $response2 = $this->twitter->favorite->destroy($update_id);
  438. $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
  439. $httpClient = Zend_Service_Twitter::getHttpClient();
  440. $httpRequest = $httpClient->getLastRequest();
  441. $httpResponse = $httpClient->getLastResponse();
  442. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  443. $this->assertTrue(isset($response->status));
  444. }
  445. public function testStatusDestroyReturnsResult()
  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->status->destroy($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. public function testUserFriendsReturnsResults()
  461. {
  462. $response = $this->twitter->user->friends();
  463. $this->assertTrue($response 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. public function testUserFolloersReturnsResults()
  471. {
  472. $response = $this->twitter->user->followers(array('id' =>'zftestuser1'));
  473. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  474. $httpClient = Zend_Service_Twitter::getHttpClient();
  475. $httpRequest = $httpClient->getLastRequest();
  476. $httpResponse = $httpClient->getLastResponse();
  477. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  478. $this->assertTrue(isset($response->status));
  479. }
  480. public function testUserFriendsSpecificUserReturnsResults()
  481. {
  482. $response = $this->twitter->user->friends(array('id' =>'zftestuser1'));
  483. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  484. $httpClient = Zend_Service_Twitter::getHttpClient();
  485. $httpRequest = $httpClient->getLastRequest();
  486. $httpResponse = $httpClient->getLastResponse();
  487. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  488. $this->assertTrue(isset($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  489. return $response;
  490. }
  491. public function testUserShowReturnsResults()
  492. {
  493. $userInfo = $this->testUserFriendsSpecificUserReturnsResults();
  494. $userId = $userInfo->toValue($userInfo->user->id);
  495. $response = $this->twitter->user->show($userId);
  496. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  497. $this->assertEquals($userInfo->toValue($userInfo->user->name), $response->toValue($response->name));
  498. $this->assertEquals($userId, $response->toValue($response->id));
  499. }
  500. public function testStatusRepliesReturnsResults()
  501. {
  502. $response = $this->twitter->status->replies(array('since' => '-800 days', 'page' => 1, 'since_id' => 10000, 'invalid_option' => 'doh'));
  503. $this->assertTrue($response instanceof Zend_Rest_Client_Result);
  504. $httpClient = Zend_Service_Twitter::getHttpClient();
  505. $httpRequest = $httpClient->getLastRequest();
  506. $httpResponse = $httpClient->getLastResponse();
  507. $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
  508. }
  509. /**
  510. * @return void
  511. */
  512. public function testFriendshipDestory()
  513. {
  514. $response = $this->twitter->friendship->destroy('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. }
  521. /**
  522. * Insert Test Data
  523. *
  524. */
  525. protected function insertTestTwitterData()
  526. {
  527. $twitter = new Zend_Service_Twitter('zftestuser1','zftestuser1');
  528. // create 10 new entries
  529. for($x=0; $x<10; $x++) {
  530. $twitter->status->update( 'Test Message - ' . $x);
  531. }
  532. $twitter->account->endSession();
  533. }
  534. }
  535. if (PHPUnit_MAIN_METHOD == 'Zend_Service_TwitterTest::main') {
  536. Zend_Service_TwitterTest::main();
  537. }