|
|
@@ -17,11 +17,11 @@
|
|
|
* @subpackage UnitTests
|
|
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
|
|
- * @version $Id$
|
|
|
+ * @version $Id: TwitterTest.php 22318 2010-05-29 18:24:27Z padraic $
|
|
|
*/
|
|
|
|
|
|
if (!defined('PHPUnit_MAIN_METHOD')) {
|
|
|
- define('PHPUnit_MAIN_METHOD', 'Zend_Service_Twitter_TwitterTest::main');
|
|
|
+ define('PHPUnit_MAIN_METHOD', 'Zend_Service_Twitter_TwitterTest2::main');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -47,7 +47,7 @@ require_once 'Zend/Http/Client/Adapter/Test.php';
|
|
|
* @group Zend_Service
|
|
|
* @group Zend_Service_Twitter
|
|
|
*/
|
|
|
-class Zend_Service_Twitter_TwitterTest extends PHPUnit_Framework_TestCase
|
|
|
+class Zend_Service_Twitter_TwitterTest2 extends PHPUnit_Framework_TestCase
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
@@ -60,62 +60,95 @@ class Zend_Service_Twitter_TwitterTest extends PHPUnit_Framework_TestCase
|
|
|
$suite = new PHPUnit_Framework_TestSuite(__CLASS__);
|
|
|
$result = PHPUnit_TextUI_TestRunner::run($suite);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public function teardown()
|
|
|
+ {
|
|
|
+ Zend_Service_Abstract::setHttpClient(new Zend_Http_Client);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * Sets up the fixture, for example, open a network connection.
|
|
|
- * This method is called before a test is executed.
|
|
|
+ * 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
|
|
|
*
|
|
|
- * @return void
|
|
|
- */
|
|
|
- protected function setUp()
|
|
|
- {
|
|
|
- if (!defined('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED') || !constant('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED')) {
|
|
|
- $this->markTestSkipped('Twitter tests are not enabled');
|
|
|
- return;
|
|
|
+ * 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_Http_Client');
|
|
|
+ $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);
|
|
|
}
|
|
|
-
|
|
|
- Zend_Service_Abstract::getHttpClient()->setAdapter('Zend_Http_Client_Adapter_Socket');
|
|
|
- $this->twitter = new Zend_Service_Twitter(TESTS_ZEND_SERVICE_TWITTER_USER, TESTS_ZEND_SERVICE_TWITTER_PASS);
|
|
|
+ $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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group ZF-8218
|
|
|
*/
|
|
|
public function testUserNameNotRequired()
|
|
|
- {
|
|
|
- Zend_Service_Abstract::getHttpClient()->setAdapter('Zend_Http_Client_Adapter_Socket');
|
|
|
+ {
|
|
|
$twitter = new Zend_Service_Twitter();
|
|
|
- $exists = $twitter->user->show('zftestuser1')->id() !== null;
|
|
|
-
|
|
|
+ $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);
|
|
|
-
|
|
|
- unset($twitter);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group ZF-7781
|
|
|
*/
|
|
|
- public function testValidationOfScreenNames_NoError()
|
|
|
+ public function testRetrievingStatusesWithValidScreenNameThrowsNoInvalidScreenNameException()
|
|
|
{
|
|
|
- $response = $this->twitter->status->userTimeline(array('screen_name' => 'Abc123_Abc123_Abc123'));
|
|
|
+ $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 testValidationOfScreenNames_InvalidChar()
|
|
|
+ public function testRetrievingStatusesWithInvalidScreenNameCharacterThrowsInvalidScreenNameException()
|
|
|
{
|
|
|
- $this->setExpectedException('Zend_Service_Twitter_Exception');
|
|
|
- $response = $this->twitter->status->userTimeline(array('screen_name' => 'abc.def'));
|
|
|
+ $twitter = new Zend_Service_Twitter();
|
|
|
+ $twitter->status->userTimeline(array('screen_name' => 'abc.def'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group ZF-7781
|
|
|
*/
|
|
|
- public function testValidationOfScreenNames_InvalidLength()
|
|
|
+ public function testRetrievingStatusesWithInvalidScreenNameLengthThrowsInvalidScreenNameException()
|
|
|
{
|
|
|
$this->setExpectedException('Zend_Service_Twitter_Exception');
|
|
|
- $response = $this->twitter->status->userTimeline(array('screen_name' => 'abcdef_abc123_abc123x'));
|
|
|
+ $twitter = new Zend_Service_Twitter();
|
|
|
+ $twitter->status->userTimeline(array('screen_name' => 'abcdef_abc123_abc123x'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -123,632 +156,412 @@ class Zend_Service_Twitter_TwitterTest extends PHPUnit_Framework_TestCase
|
|
|
*/
|
|
|
public function testStatusUserTimelineConstructsExpectedGetUriAndOmitsInvalidParams()
|
|
|
{
|
|
|
- $client = new Zend_Http_Client();
|
|
|
- $client->setAdapter(new Zend_Http_Client_Adapter_Test());
|
|
|
- Zend_Service_Twitter::setHttpClient($client);
|
|
|
- $twitter = new Zend_Service_Twitter(TESTS_ZEND_SERVICE_TWITTER_USER, TESTS_ZEND_SERVICE_TWITTER_PASS);
|
|
|
- try {
|
|
|
- $twitter->status->userTimeline(array('id' => '123', 'since' => '+2 days', /* invalid param since Apr 2009 */
|
|
|
- 'page' => '1', 'count' => '123', 'user_id' => '123', 'since_id' => '123', 'max_id' => '123', 'screen_name' => 'abcdef'));
|
|
|
- } catch (Zend_Rest_Client_Result_Exception $e) {
|
|
|
- // ignores empty response complaint from Zend_Rest
|
|
|
- }
|
|
|
- $this->assertContains('GET /statuses/user_timeline/123.xml?page=1&count=123&user_id=123&since_id=123&max_id=123&screen_name=abcdef', $twitter->getLocalHttpClient()->getLastRequest());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testConstructorShouldSetUsernameAndPassword()
|
|
|
- {
|
|
|
- $this->assertEquals(TESTS_ZEND_SERVICE_TWITTER_USER, $this->twitter->getUsername());
|
|
|
- $this->assertEquals(TESTS_ZEND_SERVICE_TWITTER_PASS, $this->twitter->getPassword());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testConstructorShouldAllowUsernamePasswordAsArray()
|
|
|
- {
|
|
|
- $userInfo = array('username' => 'foo', 'password' => 'bar');
|
|
|
-
|
|
|
- $twit = new Zend_Service_Twitter($userInfo);
|
|
|
- $this->assertEquals('foo', $twit->getUsername());
|
|
|
- $this->assertEquals('bar', $twit->getPassword());
|
|
|
+ $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'
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testUsernameAccessorsShouldAllowSettingAndRetrievingUsername()
|
|
|
- {
|
|
|
- $this->twitter->setUsername('foo');
|
|
|
- $this->assertEquals('foo', $this->twitter->getUsername());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testPasswordAccessorsShouldAllowSettingAndRetrievingPassword()
|
|
|
- {
|
|
|
- $this->twitter->setPassword('foo');
|
|
|
- $this->assertEquals('foo', $this->twitter->getPassword());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testOverloadingGetShouldReturnObjectInstanceWithValidMethodType()
|
|
|
{
|
|
|
- try {
|
|
|
- $return = $this->twitter->status;
|
|
|
- $this->assertSame($this->twitter, $return);
|
|
|
- } catch (Exception $e) {
|
|
|
- $this->fail('Property overloading with a valid method type should not throw an exception');
|
|
|
- }
|
|
|
+ $twitter = new Zend_Service_Twitter;
|
|
|
+ $return = $twitter->status;
|
|
|
+ $this->assertSame($twitter, $return);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
+ * @expectedException Zend_Service_Twitter_Exception
|
|
|
*/
|
|
|
public function testOverloadingGetShouldthrowExceptionWithInvalidMethodType()
|
|
|
{
|
|
|
- try {
|
|
|
- $return = $this->twitter->foo;
|
|
|
- $this->fail('Property overloading with an invalid method type should throw an exception');
|
|
|
- } catch (Exception $e) {
|
|
|
- }
|
|
|
+ $twitter = new Zend_Service_Twitter;
|
|
|
+ $return = $twitter->foo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
+ * @expectedException Zend_Service_Twitter_Exception
|
|
|
*/
|
|
|
public function testOverloadingGetShouldthrowExceptionWithInvalidFunction()
|
|
|
{
|
|
|
- try {
|
|
|
- $return = $this->twitter->foo();
|
|
|
- $this->fail('Property overloading with an invalid function should throw an exception');
|
|
|
- } catch (Exception $e) {
|
|
|
- }
|
|
|
+ $twitter = new Zend_Service_Twitter;
|
|
|
+ $return = $twitter->foo();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testMethodProxyingDoesNotThrowExceptionsWithValidMethods()
|
|
|
{
|
|
|
- try {
|
|
|
- $this->twitter->status->publicTimeline();
|
|
|
- } catch (Exception $e) {
|
|
|
- $this->fail('Method proxying should not throw an exception with valid methods; exception: ' . $e->getMessage());
|
|
|
- }
|
|
|
+ $twitter = new Zend_Service_Twitter;
|
|
|
+ $twitter->setLocalHttpClient($this->_stubTwitter(
|
|
|
+ 'statuses/public_timeline.xml', Zend_Http_Client::GET, 'public_timeline.xml'
|
|
|
+ ));
|
|
|
+ $twitter->status->publicTimeline();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
+ * @expectedException Zend_Service_Twitter_Exception
|
|
|
*/
|
|
|
public function testMethodProxyingThrowExceptionsWithInvalidMethods()
|
|
|
{
|
|
|
- try {
|
|
|
- $this->twitter->status->foo();
|
|
|
- $this->fail('Method proxying should throw an exception with invalid methods');
|
|
|
- } catch (Exception $e) {
|
|
|
- }
|
|
|
+ $twitter = new Zend_Service_Twitter;
|
|
|
+ $twitter->status->foo();
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
+
|
|
|
public function testVerifiedCredentials()
|
|
|
{
|
|
|
- $response = $this->twitter->account->verifyCredentials();
|
|
|
+ $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);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testPublicTimelineStatusReturnsResults()
|
|
|
{
|
|
|
- $response = $this->twitter->status->publicTimeline();
|
|
|
+ $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);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testUsersFeaturedStatusReturnsResults()
|
|
|
- {
|
|
|
- $response = $this->twitter->user->featured();
|
|
|
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
}
|
|
|
|
|
|
public function testRateLimitStatusReturnsResults()
|
|
|
{
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->account->rateLimitStatus();
|
|
|
+ $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);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
}
|
|
|
|
|
|
public function testRateLimitStatusHasHitsLeft()
|
|
|
{
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->account->rateLimitStatus();
|
|
|
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
|
|
|
-
|
|
|
+ $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->assertType('numeric', $remaining_hits);
|
|
|
- $this->assertGreaterThan(0, $remaining_hits);
|
|
|
+ $this->assertEquals(150, $remaining_hits);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
+
|
|
|
public function testAccountEndSession()
|
|
|
{
|
|
|
- $response = $this->twitter->account->endSession();
|
|
|
+ $twitter = new Zend_Service_Twitter;
|
|
|
+ $twitter->setLocalHttpClient($this->_stubTwitter(
|
|
|
+ 'account/end_session', Zend_Http_Client::GET
|
|
|
+ ));
|
|
|
+ $response = $twitter->account->endSession();
|
|
|
$this->assertTrue($response);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
+ * TODO: Check actual purpose. New friend returns XML response, existing
|
|
|
+ * friend returns a 403 code.
|
|
|
*/
|
|
|
public function testFriendshipCreate()
|
|
|
{
|
|
|
- $response = $this->twitter->friendship->create('zftestuser1');
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
+ $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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
+ * 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()
|
|
|
{
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->friendship->exists('zftestuser1');
|
|
|
+ $twitter = new Zend_Service_Twitter('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);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testFriendsTimelineWithInvalidParamReturnsResults()
|
|
|
- {
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->status->friendsTimeline(array('foo' => 'bar'));
|
|
|
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testFriendsTimelineStatusWithFriendSpecifiedReturnsResults()
|
|
|
- {
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $this->insertTestTwitterData();
|
|
|
- $response = $this->twitter->status->friendsTimeline(array('id' => 'zftestuser1'));
|
|
|
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
+ * TODO: Add verification for ALL optional parameters
|
|
|
*/
|
|
|
public function testFriendsTimelineWithPageReturnsResults()
|
|
|
- {
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->status->friendsTimeline(array('id' => 'zftestuser1', 'page' => '2'));
|
|
|
+ {
|
|
|
+ $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);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
-
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
+ * TODO: Add verification for ALL optional parameters
|
|
|
*/
|
|
|
- public function testFriendsTimelineWithCountReturnsResults()
|
|
|
+ public function testUserTimelineReturnsResults()
|
|
|
{
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->status->friendsTimeline(array('id' => 'zftestuser1', 'count' => '2'));
|
|
|
+ $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);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
-
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
- $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testUserTimelineStatusWithPageAndTwoTweetsReturnsResults()
|
|
|
- {
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->status->userTimeline(array('id' => 'zftestuser1', 'count' => 2));
|
|
|
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $raw_response = $httpResponse->getHeadersAsString() . $httpResponse->getBody();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
-
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
- $this->assertEquals(2, count($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- }
|
|
|
-
|
|
|
- public function testUserTimelineStatusShouldReturnFortyResults()
|
|
|
- {
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->status->userTimeline(array('id' => 'zftestuser1', 'count' => 40));
|
|
|
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
-
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
- $this->assertEquals(40, count($response->status));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return void
|
|
|
+ * TODO: Add verification for ALL optional parameters
|
|
|
*/
|
|
|
public function testPostStatusUpdateReturnsResponse()
|
|
|
{
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->status->update('Test Message - ' . rand());
|
|
|
+ $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);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * $return void
|
|
|
+ * @expectedException Zend_Service_Twitter_Exception
|
|
|
*/
|
|
|
public function testPostStatusUpdateToLongShouldThrowException()
|
|
|
{
|
|
|
- try {
|
|
|
- $response = $this->twitter->status->update('Test Message - ' . str_repeat(' Hello ', 140));
|
|
|
- $this->fail('Trying to post a status with > 140 character should throw exception');
|
|
|
- } catch (Exception $e) {
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function testPostStatusUpdateUTF8ShouldNotThrowException()
|
|
|
- {
|
|
|
- try {
|
|
|
- $response = $this->twitter->status->update(str_repeat('M�r', 46) . 'M�');
|
|
|
- } catch (Exception $e) {
|
|
|
- $this->fail('Trying to post a utf8 string of 140 chars should not throw exception');
|
|
|
- }
|
|
|
+ $twitter = new Zend_Service_Twitter;
|
|
|
+ $twitter->status->update('Test Message - ' . str_repeat(' Hello ', 140));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * $return void
|
|
|
+ * @expectedException Zend_Service_Twitter_Exception
|
|
|
*/
|
|
|
public function testPostStatusUpdateEmptyShouldThrowException()
|
|
|
{
|
|
|
- try {
|
|
|
- $response = $this->twitter->status->update('');
|
|
|
- $this->fail('Trying to post an empty status should throw exception');
|
|
|
- } catch (Exception $e) {
|
|
|
- }
|
|
|
+ $twitter = new Zend_Service_Twitter;
|
|
|
+ $twitter->status->update('');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testShowStatusReturnsResponse()
|
|
|
{
|
|
|
- $response = $this->twitter->status->publicTimeline();
|
|
|
+ $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);
|
|
|
-
|
|
|
- $status_id = $response->toValue($response->status->id);
|
|
|
- $this->assertType('numeric', $status_id);
|
|
|
-
|
|
|
- $response2 = $this->twitter->status->show($status_id);
|
|
|
- $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testCreateFavoriteStatusReturnsResponse()
|
|
|
{
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->status->userTimeline();
|
|
|
+ $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);
|
|
|
-
|
|
|
- $update_id = $response->toValue($response->status->id);
|
|
|
- $this->assertType('numeric', $update_id);
|
|
|
-
|
|
|
- $response2 = $this->twitter->favorite->create($update_id);
|
|
|
- $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testFavoriteFavoriesReturnsResponse()
|
|
|
{
|
|
|
- $response = $this->twitter->favorite->favorites();
|
|
|
+ $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);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * TODO: Can we use a HTTP DELETE?
|
|
|
+ */
|
|
|
public function testDestroyFavoriteReturnsResponse()
|
|
|
{
|
|
|
- $response = $this->twitter->favorite->favorites();
|
|
|
+ $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);
|
|
|
-
|
|
|
- $update_id = $response->toValue($response->status->id);
|
|
|
- $this->assertType('numeric', $update_id);
|
|
|
-
|
|
|
- $response2 = $this->twitter->favorite->destroy($update_id);
|
|
|
- $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
}
|
|
|
|
|
|
public function testStatusDestroyReturnsResult()
|
|
|
{
|
|
|
- /* @var $response Zend_Rest_Client_Result */
|
|
|
- $response = $this->twitter->status->userTimeline();
|
|
|
+ $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);
|
|
|
-
|
|
|
- $update_id = $response->toValue($response->status->id);
|
|
|
- $this->assertType('numeric', $update_id);
|
|
|
-
|
|
|
- $response2 = $this->twitter->status->destroy($update_id);
|
|
|
- $this->assertTrue($response2 instanceof Zend_Rest_Client_Result);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * TODO: Add verification for ALL optional parameters
|
|
|
+ */
|
|
|
public function testUserFriendsReturnsResults()
|
|
|
{
|
|
|
- $response = $this->twitter->user->friends();
|
|
|
+ $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);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
}
|
|
|
|
|
|
- public function testUserFolloersReturnsResults()
|
|
|
+ /**
|
|
|
+ * TODO: Add verification for ALL optional parameters
|
|
|
+ * Note: Implementation does not currently accept ANY optional parameters
|
|
|
+ */
|
|
|
+ public function testUserFollowersReturnsResults()
|
|
|
{
|
|
|
- $response = $this->twitter->user->followers(array('id' => 'zftestuser1'));
|
|
|
+ $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);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status));
|
|
|
- }
|
|
|
-
|
|
|
- public function testUserFriendsSpecificUserReturnsResults()
|
|
|
- {
|
|
|
- $response = $this->twitter->user->friends(array('id' => 'ZendRssFeed'));
|
|
|
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
-
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
- $this->assertTrue(isset($response->status), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
-
|
|
|
- return $response;
|
|
|
}
|
|
|
|
|
|
public function testUserShowByIdReturnsResults()
|
|
|
{
|
|
|
- $userInfo = $this->testUserFriendsSpecificUserReturnsResults();
|
|
|
- $userId = $userInfo->toValue($userInfo->user->id);
|
|
|
-
|
|
|
- $response = $this->twitter->user->show($userId);
|
|
|
+ $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);
|
|
|
-
|
|
|
- $this->assertEquals($userInfo->toValue($userInfo->user->name), $response->toValue($response->name));
|
|
|
- $this->assertEquals($userId, $response->toValue($response->id));
|
|
|
- }
|
|
|
-
|
|
|
- public function testUserShowByNameReturnsResults()
|
|
|
- {
|
|
|
- $response = $this->twitter->user->show('zftestuser1');
|
|
|
- $this->assertTrue($response instanceof Zend_Rest_Client_Result);
|
|
|
-
|
|
|
- $this->assertEquals('zftestuser1', $response->toValue($response->screen_name));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * TODO: Add verification for ALL optional parameters
|
|
|
+ */
|
|
|
public function testStatusRepliesReturnsResults()
|
|
|
{
|
|
|
- $response = $this->twitter->status->replies(array('page' => 1, 'since_id' => 10000, 'invalid_option' => 'doh'));
|
|
|
+ $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);
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
+ * TODO: Add verification for ALL optional parameters
|
|
|
*/
|
|
|
- public function testFriendshipDestory()
|
|
|
+ public function testFriendshipDestroy()
|
|
|
{
|
|
|
- $response = $this->twitter->friendship->destroy('zftestuser1');
|
|
|
+ $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);
|
|
|
-
|
|
|
- $httpClient = $this->twitter->getLocalHttpClient();
|
|
|
- $httpRequest = $httpClient->getLastRequest();
|
|
|
- $httpResponse = $httpClient->getLastResponse();
|
|
|
- $this->assertTrue($httpResponse->isSuccessful(), $httpResponse->getStatus() . ': ' . var_export($httpRequest, 1) . '\n' . $httpResponse->getHeadersAsString());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testBlockingCreate()
|
|
|
{
|
|
|
- $response = $this->twitter->block->create('zftestuser1');
|
|
|
+ $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);
|
|
|
- $this->assertEquals('zftestuser1', (string) $response->screen_name);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testBlockingExistsReturnsTrueWhenBlockExists()
|
|
|
{
|
|
|
- $this->assertTrue($this->twitter->block->exists('zftestuser1'));
|
|
|
+ $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'));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testBlockingBlocked()
|
|
|
{
|
|
|
- $response = $this->twitter->block->blocking();
|
|
|
+ $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);
|
|
|
- $this->assertEquals('zftestuser1', (string) $response->user->screen_name);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testBlockingBlockedReturnsIds()
|
|
|
{
|
|
|
- $response = $this->twitter->block->blocking(1, true);
|
|
|
+ $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('16935247', (string) $response->id);
|
|
|
+ $this->assertEquals('23836616', (string) $response->id);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testBlockingDestroy()
|
|
|
{
|
|
|
- $response = $this->twitter->block->destroy('zftestuser1');
|
|
|
+ $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);
|
|
|
- $this->assertEquals('zftestuser1', (string) $response->screen_name);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function testBlockingExistsReturnsFalseWhenBlockDoesNotExists()
|
|
|
{
|
|
|
- $this->assertFalse($this->twitter->block->exists('zftestuser1'));
|
|
|
+ $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'));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testBlockingExistsReturnsOjectWhenFlagPassed()
|
|
|
+ public function testBlockingExistsReturnsObjectWhenFlagPassed()
|
|
|
{
|
|
|
- $response = $this->twitter->block->exists('zftestuser1', true);
|
|
|
+ $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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Insert Test Data
|
|
|
- *
|
|
|
- */
|
|
|
- protected function insertTestTwitterData()
|
|
|
- {
|
|
|
- $twitter = new Zend_Service_Twitter('zftestuser1', 'zftestuser1');
|
|
|
- // create 10 new entries
|
|
|
- for ($x = 0; $x < 10; $x++) {
|
|
|
- $twitter->status->update('Test Message - ' . $x);
|
|
|
- }
|
|
|
- $twitter->account->endSession();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* @group ZF-6284
|
|
|
*/
|
|
|
public function testTwitterObjectsSoNotShareSameHttpClientToPreventConflictingAuthentication()
|
|
|
{
|
|
|
- $twitter1 = new Zend_Service_Twitter('zftestuser1', 'zftestuser1');
|
|
|
- $twitter2 = new Zend_Service_Twitter('zftestuser2', 'zftestuser2');
|
|
|
+ $twitter1 = new Zend_Service_Twitter('zftestuser1');
|
|
|
+ $twitter2 = new Zend_Service_Twitter('zftestuser2');
|
|
|
$this->assertFalse($twitter1->getLocalHttpClient() === $twitter2->getLocalHttpClient());
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-if (PHPUnit_MAIN_METHOD == 'Zend_Service_TwitterTest::main') {
|
|
|
- Zend_Service_TwitterTest::main();
|
|
|
+if (PHPUnit_MAIN_METHOD == 'Zend_Service_TwitterTest2::main') {
|
|
|
+ Zend_Service_TwitterTest2::main();
|
|
|
}
|