TwitterTest.php 26 KB

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