| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Service_Twitter
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id: TwitterTest.php 22318 2010-05-29 18:24:27Z padraic $
- */
- if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Zend_Service_Twitter_TwitterTest2::main');
- }
- /** Zend_Service_Twitter */
- require_once 'Zend/Service/Twitter.php';
- /** Zend_Http_Client */
- require_once 'Zend/Http/Client.php';
- /** Zend_Http_Client_Adapter_Test */
- require_once 'Zend/Http/Client/Adapter/Test.php';
- /**
- * @category Zend
- * @package Zend_Service_Twitter
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Service
- * @group Zend_Service_Twitter
- */
- class Zend_Service_Twitter_TwitterTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Runs the test methods of this class.
- *
- * @return void
- */
- public static function main()
- {
- $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- public function teardown()
- {
- Zend_Service_Abstract::setHttpClient(new Zend_Http_Client);
- }
- /**
- * Quick reusable Twitter Service stub setup. Its purpose is to fake
- * interactions with Twitter so the component can focus on what matters:
- * 1. Makes correct requests (URI, parameters and HTTP method)
- * 2. Parses all responses and returns a Zend_Rest_Client_Result
- * 3. TODO: Correctly utilises all optional parameters
- *
- * If used correctly, tests will be fast, efficient, and focused on
- * Zend_Service_Twitter's behaviour only. No other dependencies need be
- * tested. The Twitter API Changelog should be regularly reviewed to
- * ensure the component is synchronised to the API.
- *
- * @param string $path Path appended to Twitter API endpoint
- * @param string $method Do we expect HTTP GET or POST?
- * @param string $responseFile File containing a valid XML response to the request
- * @param array $params Expected GET/POST parameters for the request
- * @return Zend_Http_Client
- */
- protected function _stubTwitter($path, $method, $responseFile = null, array $params = null)
- {
- $client = $this->getMock('Zend_Oauth_Client', array(), array(), '', false);
- $client->expects($this->any())->method('resetParameters')
- ->will($this->returnValue($client));
- $client->expects($this->once())->method('setUri')
- ->with('http://api.twitter.com/1/' . $path);
- $response = $this->getMock('Zend_Http_Response', array(), array(), '', false);
- if (!is_null($params)) {
- $setter = 'setParameter' . ucfirst(strtolower($method));
- $client->expects($this->once())->method($setter)->with($params);
- }
- $client->expects($this->once())->method('request')->with($method)
- ->will($this->returnValue($response));
- $response->expects($this->any())->method('getBody')
- ->will($this->returnValue(
- isset($responseFile) ? file_get_contents(dirname(__FILE__) . '/_files/' . $responseFile) : ''
- ));
- return $client;
- }
- /**
- * OAuth tests
- */
- public function testProvidingAccessTokenInOptionsSetsHttpClientFromAccessToken()
- {
- $token = $this->getMock('Zend_Oauth_Token_Access', array(), array(), '', false);
- $client = $this->getMock('Zend_Oauth_Client', array(), array(), '', false);
- $token->expects($this->once())->method('getHttpClient')
- ->with(array('accessToken'=>$token, 'opt1'=>'val1', 'siteUrl'=>'https://api.twitter.com/oauth'))
- ->will($this->returnValue($client));
- $twitter = new Zend_Service_Twitter(array('accessToken'=>$token, 'opt1'=>'val1'));
- $this->assertTrue($client === $twitter->getLocalHttpClient());
- }
- public function testNotAuthorisedWithoutToken()
- {
- $twitter = new Zend_Service_Twitter;
- $this->assertFalse($twitter->isAuthorised());
- }
- public function testChecksAuthenticatedStateBasedOnAvailabilityOfAccessTokenBasedClient()
- {
- $token = $this->getMock('Zend_Oauth_Token_Access', array(), array(), '', false);
- $client = $this->getMock('Zend_Oauth_Client', array(), array(), '', false);
- $token->expects($this->once())->method('getHttpClient')
- ->with(array('accessToken'=>$token, 'siteUrl'=>'https://api.twitter.com/oauth'))
- ->will($this->returnValue($client));
- $twitter = new Zend_Service_Twitter(array('accessToken'=>$token));
- $this->assertTrue($twitter->isAuthorised());
- }
- public function testRelaysMethodsToInternalOAuthInstance()
- {
- $oauth = $this->getMock('Zend_Oauth_Consumer', array(), array(), '', false);
- $oauth->expects($this->once())->method('getRequestToken')->will($this->returnValue('foo'));
- $oauth->expects($this->once())->method('getRedirectUrl')->will($this->returnValue('foo'));
- $oauth->expects($this->once())->method('redirect')->will($this->returnValue('foo'));
- $oauth->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo'));
- $oauth->expects($this->once())->method('getToken')->will($this->returnValue('foo'));
- $twitter = new Zend_Service_Twitter(array('opt1'=>'val1'), $oauth);
- $this->assertEquals('foo', $twitter->getRequestToken());
- $this->assertEquals('foo', $twitter->getRedirectUrl());
- $this->assertEquals('foo', $twitter->redirect());
- $this->assertEquals('foo', $twitter->getAccessToken(array(), $this->getMock('Zend_Oauth_Token_Request')));
- $this->assertEquals('foo', $twitter->getToken());
- }
- public function testResetsHttpClientOnReceiptOfAccessTokenToOauthClient()
- {
- $oauth = $this->getMock('Zend_Oauth_Consumer', array(), array(), '', false);
- $client = $this->getMock('Zend_Oauth_Client', array(), array(), '', false);
- $token = $this->getMock('Zend_Oauth_Token_Access', array(), array(), '', false);
- $token->expects($this->once())->method('getHttpClient')->will($this->returnValue($client));
- $oauth->expects($this->once())->method('getAccessToken')->will($this->returnValue($token));
- $client->expects($this->once())->method('setHeaders')->with('Accept-Charset', 'ISO-8859-1,utf-8');
- $twitter = new Zend_Service_Twitter(array(), $oauth);
- $twitter->getAccessToken(array(), $this->getMock('Zend_Oauth_Token_Request'));
- $this->assertTrue($client === $twitter->getLocalHttpClient());
- }
- /**
- * @expectedException Zend_Service_Twitter_Exception
- */
- public function testAuthorisationFailureWithUsernameAndNoAccessToken()
- {
- $twitter = new Zend_Service_Twitter(array('username'=>'me'));
- $twitter->statusPublicTimeline();
- }
- /**
- * @group ZF-8218
- */
- public function testUserNameNotRequired()
- {
- $twitter = new Zend_Service_Twitter();
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'users/show.xml', Zend_Http_Client::GET, 'users.show.twitter.xml',
- array('id'=>'twitter')
- ));
- $exists = $twitter->user->show('twitter')->id() !== null;
- $this->assertTrue($exists);
- }
- /**
- * @group ZF-7781
- */
- public function testRetrievingStatusesWithValidScreenNameThrowsNoInvalidScreenNameException()
- {
- $twitter = new Zend_Service_Twitter();
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/user_timeline.xml', Zend_Http_Client::GET, 'user_timeline.twitter.xml'
- ));
- $twitter->status->userTimeline(array('screen_name' => 'twitter'));
- }
- /**
- * @group ZF-7781
- * @expectedException Zend_Service_Twitter_Exception
- */
- public function testRetrievingStatusesWithInvalidScreenNameCharacterThrowsInvalidScreenNameException()
- {
- $twitter = new Zend_Service_Twitter();
- $twitter->status->userTimeline(array('screen_name' => 'abc.def'));
- }
- /**
- * @group ZF-7781
- */
- public function testRetrievingStatusesWithInvalidScreenNameLengthThrowsInvalidScreenNameException()
- {
- $this->setExpectedException('Zend_Service_Twitter_Exception');
- $twitter = new Zend_Service_Twitter();
- $twitter->status->userTimeline(array('screen_name' => 'abcdef_abc123_abc123x'));
- }
- /**
- * @group ZF-7781
- */
- public function testStatusUserTimelineConstructsExpectedGetUriAndOmitsInvalidParams()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/user_timeline/783214.xml', Zend_Http_Client::GET, 'user_timeline.twitter.xml', array(
- 'page' => '1',
- 'count' => '123',
- 'user_id' => '783214',
- 'since_id' => '10000',
- 'max_id' => '20000',
- 'screen_name' => 'twitter'
- )
- ));
- $twitter->status->userTimeline(array(
- 'id' => '783214',
- 'since' => '+2 days', /* invalid param since Apr 2009 */
- 'page' => '1',
- 'count' => '123',
- 'user_id' => '783214',
- 'since_id' => '10000',
- 'max_id' => '20000',
- 'screen_name' => 'twitter'
- ));
- }
- public function testOverloadingGetShouldReturnObjectInstanceWithValidMethodType()
- {
- $twitter = new Zend_Service_Twitter;
- $return = $twitter->status;
- $this->assertSame($twitter, $return);
- }
- /**
- * @expectedException Zend_Service_Twitter_Exception
- */
- public function testOverloadingGetShouldthrowExceptionWithInvalidMethodType()
- {
- $twitter = new Zend_Service_Twitter;
- $return = $twitter->foo;
- }
- /**
- * @expectedException Zend_Service_Twitter_Exception
- */
- public function testOverloadingGetShouldthrowExceptionWithInvalidFunction()
- {
- $twitter = new Zend_Service_Twitter;
- $return = $twitter->foo();
- }
- public function testMethodProxyingDoesNotThrowExceptionsWithValidMethods()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/public_timeline.xml', Zend_Http_Client::GET, 'public_timeline.xml'
- ));
- $twitter->status->publicTimeline();
- }
- /**
- * @expectedException Zend_Service_Twitter_Exception
- */
- public function testMethodProxyingThrowExceptionsWithInvalidMethods()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->status->foo();
- }
- public function testVerifiedCredentials()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'account/verify_credentials.xml', Zend_Http_Client::GET, 'account.verify_credentials.xml'
- ));
- $response = $twitter->account->verifyCredentials();
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testPublicTimelineStatusReturnsResults()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/public_timeline.xml', Zend_Http_Client::GET, 'public_timeline.xml'
- ));
- $response = $twitter->status->publicTimeline();
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testRateLimitStatusReturnsResults()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'account/rate_limit_status.xml', Zend_Http_Client::GET, 'rate_limit_status.xml'
- ));
- $response = $twitter->account->rateLimitStatus();
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testRateLimitStatusHasHitsLeft()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'account/rate_limit_status.xml', Zend_Http_Client::GET, 'rate_limit_status.xml'
- ));
- $response = $twitter->account->rateLimitStatus();
- $remaining_hits = $response->toValue($response->{'remaining-hits'});
- $this->assertEquals(150, $remaining_hits);
- }
- public function testAccountEndSession()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'account/end_session', Zend_Http_Client::GET
- ));
- $response = $twitter->account->endSession();
- $this->assertTrue($response);
- }
- /**
- * TODO: Check actual purpose. New friend returns XML response, existing
- * friend returns a 403 code.
- */
- public function testFriendshipCreate()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'friendships/create/twitter.xml', Zend_Http_Client::POST, 'friendships.create.twitter.xml'
- ));
- $response = $twitter->friendship->create('twitter');
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * TODO: Mismatched behaviour from API. Per the API this can assert the
- * existence of a friendship between any two users (not just the current
- * user). We should expand the method or add a better fit method for
- * general use.
- */
- public function testFriendshipExists()
- {
- $twitter = new Zend_Service_Twitter(array('username'=>'padraicb'));
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'friendships/exists.xml', Zend_Http_Client::GET, 'friendships.exists.twitter.xml',
- array('user_a'=>'padraicb', 'user_b'=>'twitter')
- ));
- $response = $twitter->friendship->exists('twitter');
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * TODO: Add verification for ALL optional parameters
- */
- public function testFriendsTimelineWithPageReturnsResults()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/friends_timeline.xml', Zend_Http_Client::GET, 'statuses.friends_timeline.page.xml',
- array('page'=>3)
- ));
- $response = $twitter->status->friendsTimeline(array('page' => 3));
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * TODO: Add verification for ALL optional parameters
- */
- public function testUserTimelineReturnsResults()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/user_timeline/twitter.xml', Zend_Http_Client::GET, 'user_timeline.twitter.xml'
- ));
- $response = $twitter->status->userTimeline(array('id' => 'twitter'));
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * TODO: Add verification for ALL optional parameters
- */
- public function testPostStatusUpdateReturnsResponse()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/update.xml', Zend_Http_Client::POST, 'statuses.update.xml',
- array('status'=>'Test Message 1')
- ));
- $response = $twitter->status->update('Test Message 1');
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * @expectedException Zend_Service_Twitter_Exception
- */
- public function testPostStatusUpdateToLongShouldThrowException()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->status->update('Test Message - ' . str_repeat(' Hello ', 140));
- }
- /**
- * @expectedException Zend_Service_Twitter_Exception
- */
- public function testPostStatusUpdateEmptyShouldThrowException()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->status->update('');
- }
- public function testShowStatusReturnsResponse()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/show/15042159587.xml', Zend_Http_Client::GET, 'statuses.show.xml'
- ));
- $response = $twitter->status->show(15042159587);
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testCreateFavoriteStatusReturnsResponse()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'favorites/create/15042159587.xml', Zend_Http_Client::POST, 'favorites.create.xml'
- ));
- $response = $twitter->favorite->create(15042159587);
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testFavoriteFavoriesReturnsResponse()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'favorites.xml', Zend_Http_Client::GET, 'favorites.xml'
- ));
- $response = $twitter->favorite->favorites();
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * TODO: Can we use a HTTP DELETE?
- */
- public function testDestroyFavoriteReturnsResponse()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'favorites/destroy/15042159587.xml', Zend_Http_Client::POST, 'favorites.destroy.xml'
- ));
- $response = $twitter->favorite->destroy(15042159587);
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testStatusDestroyReturnsResult()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/destroy/15042159587.xml', Zend_Http_Client::POST, 'statuses.destroy.xml'
- ));
- $response = $twitter->status->destroy(15042159587);
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * TODO: Add verification for ALL optional parameters
- */
- public function testUserFriendsReturnsResults()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/friends.xml', Zend_Http_Client::GET, 'statuses.friends.xml'
- ));
- $response = $twitter->user->friends();
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * TODO: Add verification for ALL optional parameters
- * Note: Implementation does not currently accept ANY optional parameters
- */
- public function testUserFollowersReturnsResults()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/followers.xml', Zend_Http_Client::GET, 'statuses.followers.xml'
- ));
- $response = $twitter->user->followers();
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testUserShowByIdReturnsResults()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'users/show.xml', Zend_Http_Client::GET, 'users.show.twitter.xml',
- array('id'=>'twitter')
- ));
- $response = $twitter->user->show('twitter');
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * TODO: Add verification for ALL optional parameters
- */
- public function testStatusRepliesReturnsResults()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/mentions.xml', Zend_Http_Client::GET, 'statuses.mentions.xml'
- ));
- $response = $twitter->status->replies();
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * TODO: Add verification for ALL optional parameters
- */
- public function testFriendshipDestroy()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'friendships/destroy/twitter.xml', Zend_Http_Client::POST, 'friendships.destroy.twitter.xml'
- ));
- $response = $twitter->friendship->destroy('twitter');
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testBlockingCreate()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'blocks/create/twitter.xml', Zend_Http_Client::POST, 'blocks.create.twitter.xml'
- ));
- $response = $twitter->block->create('twitter');
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testBlockingExistsReturnsTrueWhenBlockExists()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'blocks/exists/twitter.xml', Zend_Http_Client::GET, 'blocks.exists.twitter.xml'
- ));
- $this->assertTrue($twitter->block->exists('twitter'));
- }
- public function testBlockingBlocked()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'blocks/blocking.xml', Zend_Http_Client::GET, 'blocks.blocking.xml'
- ));
- $response = $twitter->block->blocking();
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testBlockingBlockedReturnsIds()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'blocks/blocking/ids.xml', Zend_Http_Client::GET, 'blocks.blocking.ids.xml',
- array('page'=>1)
- ));
- $response = $twitter->block->blocking(1, true);
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- $this->assertEquals('23836616', (string) $response->id);
- }
- public function testBlockingDestroy()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'blocks/destroy/twitter.xml', Zend_Http_Client::POST, 'blocks.destroy.twitter.xml'
- ));
- $response = $twitter->block->destroy('twitter');
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- public function testBlockingExistsReturnsFalseWhenBlockDoesNotExists()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'blocks/exists/padraicb.xml', Zend_Http_Client::GET, 'blocks.exists.padraicb.xml'
- ));
- $this->assertFalse($twitter->block->exists('padraicb'));
- }
- public function testBlockingExistsReturnsObjectWhenFlagPassed()
- {
- $twitter = new Zend_Service_Twitter;
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'blocks/exists/padraicb.xml', Zend_Http_Client::GET, 'blocks.exists.padraicb.xml'
- ));
- $response = $twitter->block->exists('padraicb', true);
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
- }
- /**
- * @group ZF-6284
- */
- public function testTwitterObjectsSoNotShareSameHttpClientToPreventConflictingAuthentication()
- {
- $twitter1 = new Zend_Service_Twitter(array('username'=>'zftestuser1'));
- $twitter2 = new Zend_Service_Twitter(array('username'=>'zftestuser2'));
- $this->assertFalse($twitter1->getLocalHttpClient() === $twitter2->getLocalHttpClient());
- }
- /**
- * @group ZF-10644
- */
- public function testStatusUserTimelineShouldHonorAllFlags()
- {
- $params = array(
- 'screen_name' => 'allzend',
- 'page' => 1,
- 'include_rts' => '1',
- 'trim_user' => '1',
- 'include_entities' => '1',
- );
- $twitter = new Zend_Service_Twitter();
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/user_timeline.xml', Zend_Http_Client::GET, 'user_timeline.twitter.xml',
- $params
- ));
- // Assertions are part of mocking
- $timeline = $twitter->statusUserTimeline($params);
- }
- /**
- * @group ZF-11014
- */
- public function testStatusFriendsTimelineShouldHonorAllFlags()
- {
- $params = array(
- 'page' => 3,
- 'include_rts' => '1',
- 'trim_user' => '1',
- 'include_entities' => '1',
- );
- $twitter = new Zend_Service_Twitter();
- $twitter->setLocalHttpClient($this->_stubTwitter(
- 'statuses/friends_timeline.xml', Zend_Http_Client::GET, 'statuses.friends_timeline.page.xml',
- $params
- ));
- // Assertions are part of mocking
- $timeline = $twitter->statusFriendsTimeline($params);
- }
- /**
- * @group ZF-11023
- */
- public function testConstructorPassedObjectZendConfig()
- {
- require_once 'Zend/Config.php';
- $config = new Zend_Config(array('username' => 'zf'));
- $twitter = new Zend_Service_Twitter($config);
- $this->assertEquals('zf', $twitter->getUsername());
- }
-
- }
- if (PHPUnit_MAIN_METHOD == 'Zend_Service_TwitterTest2::main') {
- Zend_Service_TwitterTest2::main();
- }
|