summaryrefslogtreecommitdiff
path: root/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TwitterTest.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-11-06 06:41:47 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-11-06 06:41:47 -0500
commitc80c15dcc33a70acc2b177691d33f088f8c2541e (patch)
treebc3e44e35b97b751c145cc5797a0faf356922244 /vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TwitterTest.php
parentc91ff61cdfa8b5eb76783927e5b8710f2a9f2601 (diff)
Include all vendor files in the repo to be easier for people
Diffstat (limited to 'vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TwitterTest.php')
-rw-r--r--vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TwitterTest.php307
1 files changed, 307 insertions, 0 deletions
diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TwitterTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TwitterTest.php
new file mode 100644
index 00000000..bb31fa29
--- /dev/null
+++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TwitterTest.php
@@ -0,0 +1,307 @@
+<?php
+
+namespace OAuthTest\Unit\OAuth1\Service;
+
+use OAuth\OAuth1\Service\Twitter;
+
+class TwitterTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ */
+ public function testConstructCorrectInterfaceWithoutCustomUri()
+ {
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\ServiceInterface', $service);
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ */
+ public function testConstructCorrectInstanceWithoutCustomUri()
+ {
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\AbstractService', $service);
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ */
+ public function testConstructCorrectInstanceWithCustomUri()
+ {
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),
+ $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface')
+ );
+
+ $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\AbstractService', $service);
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getRequestTokenEndpoint
+ */
+ public function testGetRequestTokenEndpoint()
+ {
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->assertSame(
+ 'https://api.twitter.com/oauth/request_token',
+ $service->getRequestTokenEndpoint()->getAbsoluteUri()
+ );
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getAuthorizationEndpoint
+ */
+ public function testGetAuthorizationEndpoint()
+ {
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->assertTrue(
+ in_array(
+ strtolower($service->getAuthorizationEndpoint()->getAbsoluteUri()),
+ array(\OAuth\OAuth1\Service\Twitter::ENDPOINT_AUTHENTICATE, \OAuth\OAuth1\Service\Twitter::ENDPOINT_AUTHORIZE)
+ )
+ );
+
+ $service->setAuthorizationEndpoint( \OAuth\OAuth1\Service\Twitter::ENDPOINT_AUTHORIZE );
+
+ $this->assertTrue(
+ in_array(
+ strtolower($service->getAuthorizationEndpoint()->getAbsoluteUri()),
+ array(\OAuth\OAuth1\Service\Twitter::ENDPOINT_AUTHENTICATE, \OAuth\OAuth1\Service\Twitter::ENDPOINT_AUTHORIZE)
+ )
+ );
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::setAuthorizationEndpoint
+ */
+ public function testSetAuthorizationEndpoint()
+ {
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->setExpectedException('\\OAuth\\Common\\Exception\\Exception');
+
+ $service->setAuthorizationEndpoint('foo');
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getAccessTokenEndpoint
+ */
+ public function testGetAccessTokenEndpoint()
+ {
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->assertSame(
+ 'https://api.twitter.com/oauth/access_token',
+ $service->getAccessTokenEndpoint()->getAbsoluteUri()
+ );
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getRequestTokenEndpoint
+ * @covers OAuth\OAuth1\Service\Twitter::parseRequestTokenResponse
+ */
+ public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse()
+ {
+ $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
+ $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null));
+
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $client,
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
+
+ $service->requestRequestToken();
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getRequestTokenEndpoint
+ * @covers OAuth\OAuth1\Service\Twitter::parseRequestTokenResponse
+ */
+ public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray()
+ {
+ $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
+ $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('notanarray'));
+
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $client,
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
+
+ $service->requestRequestToken();
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getRequestTokenEndpoint
+ * @covers OAuth\OAuth1\Service\Twitter::parseRequestTokenResponse
+ */
+ public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotSet()
+ {
+ $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
+ $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('foo=bar'));
+
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $client,
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
+
+ $service->requestRequestToken();
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getRequestTokenEndpoint
+ * @covers OAuth\OAuth1\Service\Twitter::parseRequestTokenResponse
+ */
+ public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotTrue()
+ {
+ $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
+ $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(
+ 'oauth_callback_confirmed=false'
+ ));
+
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $client,
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
+
+ $service->requestRequestToken();
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getRequestTokenEndpoint
+ * @covers OAuth\OAuth1\Service\Twitter::parseRequestTokenResponse
+ * @covers OAuth\OAuth1\Service\Twitter::parseAccessTokenResponse
+ */
+ public function testParseRequestTokenResponseValid()
+ {
+ $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
+ $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(
+ 'oauth_callback_confirmed=true&oauth_token=foo&oauth_token_secret=bar'
+ ));
+
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $client,
+ $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestRequestToken());
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getRequestTokenEndpoint
+ * @covers OAuth\OAuth1\Service\Twitter::parseAccessTokenResponse
+ */
+ public function testParseAccessTokenResponseThrowsExceptionOnError()
+ {
+ $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
+ $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=bar'));
+
+ $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface');
+
+ $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface');
+ $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token));
+
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $client,
+ $storage,
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
+
+ $service->requestAccessToken('foo', 'bar', $token);
+ }
+
+ /**
+ * @covers OAuth\OAuth1\Service\Twitter::__construct
+ * @covers OAuth\OAuth1\Service\Twitter::getRequestTokenEndpoint
+ * @covers OAuth\OAuth1\Service\Twitter::parseAccessTokenResponse
+ */
+ public function testParseAccessTokenResponseValid()
+ {
+ $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
+ $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(
+ 'oauth_token=foo&oauth_token_secret=bar'
+ ));
+
+ $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface');
+
+ $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface');
+ $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token));
+
+ $service = new Twitter(
+ $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
+ $client,
+ $storage,
+ $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')
+ );
+
+ $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestAccessToken('foo', 'bar', $token));
+ }
+}