diff options
Diffstat (limited to 'vendor/lusitanian/oauth/tests/Unit')
51 files changed, 11617 insertions, 0 deletions
diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/AutoloaderTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/AutoloaderTest.php new file mode 100644 index 00000000..eebc3408 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/AutoloaderTest.php @@ -0,0 +1,126 @@ +<?php + +namespace OAuthTest\Unit\Commen\Core; + +use OAuth\Common\AutoLoader; + +class AutoLoaderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\Common\AutoLoader::__construct + * @covers OAuth\Common\AutoLoader::register + */ + public function testRegister() + { + $autoloader = new AutoLoader('Test', '/'); + + $this->assertTrue($autoloader->register()); + } + + /** + * @covers OAuth\Common\AutoLoader::__construct + * @covers OAuth\Common\AutoLoader::register + * @covers OAuth\Common\AutoLoader::unregister + */ + public function testUnregister() + { + $autoloader = new AutoLoader('Test', '/'); + + $this->assertTrue($autoloader->register()); + $this->assertTrue($autoloader->unregister()); + } + + /** + * @covers OAuth\Common\AutoLoader::__construct + * @covers OAuth\Common\AutoLoader::register + * @covers OAuth\Common\AutoLoader::load + */ + public function testLoadSuccess() + { + $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common'); + + $this->assertTrue($autoloader->register()); + + $someClass = new \FakeProject\NS\SomeClass(); + + $this->assertTrue($someClass->isLoaded()); + } + + /** + * @covers OAuth\Common\AutoLoader::__construct + * @covers OAuth\Common\AutoLoader::register + * @covers OAuth\Common\AutoLoader::load + */ + public function testLoadSuccessExtraSlashedNamespace() + { + $autoloader = new AutoLoader('\\\\FakeProject', dirname(__DIR__) . '/../Mocks/Common'); + + $this->assertTrue($autoloader->register()); + + $someClass = new \FakeProject\NS\SomeClass(); + + $this->assertTrue($someClass->isLoaded()); + } + + /** + * @covers OAuth\Common\AutoLoader::__construct + * @covers OAuth\Common\AutoLoader::register + * @covers OAuth\Common\AutoLoader::load + */ + public function testLoadSuccessExtraForwardSlashedPath() + { + $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common//'); + + $this->assertTrue($autoloader->register()); + + $someClass = new \FakeProject\NS\SomeClass(); + + $this->assertTrue($someClass->isLoaded()); + } + + /** + * @covers OAuth\Common\AutoLoader::__construct + * @covers OAuth\Common\AutoLoader::register + * @covers OAuth\Common\AutoLoader::load + */ + public function testLoadSuccessExtraBackwardSlashedPath() + { + $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common\\'); + + $this->assertTrue($autoloader->register()); + + $someClass = new \FakeProject\NS\SomeClass(); + + $this->assertTrue($someClass->isLoaded()); + } + + /** + * @covers OAuth\Common\AutoLoader::__construct + * @covers OAuth\Common\AutoLoader::register + * @covers OAuth\Common\AutoLoader::load + */ + public function testLoadSuccessExtraMixedSlashedPath() + { + $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common\\\\/\\//'); + + $this->assertTrue($autoloader->register()); + + $someClass = new \FakeProject\NS\SomeClass(); + + $this->assertTrue($someClass->isLoaded()); + } + + /** + * @covers OAuth\Common\AutoLoader::__construct + * @covers OAuth\Common\AutoLoader::register + * @covers OAuth\Common\AutoLoader::load + */ + public function testLoadUnknownClass() + { + $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common\\\\/\\//'); + + $this->assertTrue($autoloader->register()); + + $this->assertFalse($autoloader->load('IDontExistClass')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Consumer/CredentialsTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Consumer/CredentialsTest.php new file mode 100644 index 00000000..1a895fbc --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Consumer/CredentialsTest.php @@ -0,0 +1,51 @@ +<?php + +namespace OAuth\Unit\Common\Consumer; + +use OAuth\Common\Consumer\Credentials; + +class CredentialsTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\Common\Consumer\Credentials::__construct + */ + public function testConstructCorrectInterface() + { + $credentials = new Credentials('foo', 'bar', 'baz'); + + $this->assertInstanceOf('\\OAuth\\Common\\Consumer\\CredentialsInterface', $credentials); + } + + /** + * @covers OAuth\Common\Consumer\Credentials::__construct + * @covers OAuth\Common\Consumer\Credentials::getConsumerId + */ + public function testGetConsumerId() + { + $credentials = new Credentials('foo', 'bar', 'baz'); + + $this->assertSame('foo', $credentials->getConsumerId()); + } + + /** + * @covers OAuth\Common\Consumer\Credentials::__construct + * @covers OAuth\Common\Consumer\Credentials::getConsumerSecret + */ + public function testGetConsumerSecret() + { + $credentials = new Credentials('foo', 'bar', 'baz'); + + $this->assertSame('bar', $credentials->getConsumerSecret()); + } + + /** + * @covers OAuth\Common\Consumer\Credentials::__construct + * @covers OAuth\Common\Consumer\Credentials::getCallbackUrl + */ + public function testGetCallbackUrl() + { + $credentials = new Credentials('foo', 'bar', 'baz'); + + $this->assertSame('baz', $credentials->getCallbackUrl()); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/AbstractClientTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/AbstractClientTest.php new file mode 100644 index 00000000..b3531527 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/AbstractClientTest.php @@ -0,0 +1,67 @@ +<?php + +namespace OAuthTest\Unit\Common\Http; + +class AbstractClientTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\Common\Http\Client\AbstractClient::__construct + */ + public function testConstructCorrectInterface() + { + $client = $this->getMockForAbstractClass('\\OAuth\\Common\\Http\\Client\\AbstractClient'); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\ClientInterface', $client); + } + + /** + * @covers OAuth\Common\Http\Client\AbstractClient::__construct + * @covers OAuth\Common\Http\Client\AbstractClient::setMaxRedirects + */ + public function testSetMaxRedirects() + { + $client = $this->getMockForAbstractClass('\\OAuth\\Common\\Http\\Client\\AbstractClient'); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\AbstractClient', $client->setMaxRedirects(10)); + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\ClientInterface', $client->setMaxRedirects(10)); + } + + /** + * @covers OAuth\Common\Http\Client\AbstractClient::__construct + * @covers OAuth\Common\Http\Client\AbstractClient::setTimeout + */ + public function testSetTimeout() + { + $client = $this->getMockForAbstractClass('\\OAuth\\Common\\Http\\Client\\AbstractClient'); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\AbstractClient', $client->setTimeout(25)); + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\ClientInterface', $client->setTimeout(25)); + } + + /** + * @covers OAuth\Common\Http\Client\AbstractClient::__construct + * @covers OAuth\Common\Http\Client\AbstractClient::normalizeHeaders + */ + public function testNormalizeHeaders() + { + $client = $this->getMockForAbstractClass('\\OAuth\\Common\\Http\\Client\\AbstractClient'); + + $original = array( + 'lowercasekey' => 'lowercasevalue', + 'UPPERCASEKEY' => 'UPPERCASEVALUE', + 'mIxEdCaSeKey' => 'MiXeDcAsEvAlUe', + '31i71casekey' => '31i71casevalue', + ); + + $goal = array( + 'lowercasekey' => 'Lowercasekey: lowercasevalue', + 'UPPERCASEKEY' => 'Uppercasekey: UPPERCASEVALUE', + 'mIxEdCaSeKey' => 'Mixedcasekey: MiXeDcAsEvAlUe', + '31i71casekey' => '31i71casekey: 31i71casevalue', + ); + + $client->normalizeHeaders($original); + + $this->assertSame($goal, $original); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/CurlClientTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/CurlClientTest.php new file mode 100644 index 00000000..f635ce89 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/CurlClientTest.php @@ -0,0 +1,378 @@ +<?php + +namespace OAuthTest\Unit\Common\Http\Client; + +use OAuth\Common\Http\Client\CurlClient; + +class CurlClientTest extends \PHPUnit_Framework_TestCase +{ + /** + * + */ + public function testConstructCorrectInstance() + { + $client = new CurlClient(); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\AbstractClient', $client); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::setForceSSL3 + */ + public function testSetForceSSL3() + { + $client = new CurlClient(); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\CurlClient', $client->setForceSSL3(true)); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponseThrowsExceptionOnGetRequestWithBody() + { + $this->setExpectedException('\\InvalidArgumentException'); + + $client = new CurlClient(); + + $client->retrieveResponse( + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'), + 'foo', + array(), + 'GET' + ); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponseThrowsExceptionOnGetRequestWithBodyMethodConvertedToUpper() + { + $this->setExpectedException('\\InvalidArgumentException'); + + $client = new CurlClient(); + + $client->retrieveResponse( + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'), + 'foo', + array(), + 'get' + ); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponseDefaultUserAgent() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/get')); + + $client = new CurlClient(); + + $response = $client->retrieveResponse( + $endPoint, + '', + array(), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertSame('PHPoAuthLib', $response['headers']['User-Agent']); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponseCustomUserAgent() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/get')); + + $client = new CurlClient('My Super Awesome Http Client'); + + $response = $client->retrieveResponse( + $endPoint, + '', + array(), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertSame('My Super Awesome Http Client', $response['headers']['User-Agent']); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponseWithCustomContentType() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/get')); + + $client = new CurlClient(); + + $response = $client->retrieveResponse( + $endPoint, + '', + array('Content-Type' => 'foo/bar'), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertSame('foo/bar', $response['headers']['Content-Type']); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponseWithFormUrlEncodedContentType() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/post')); + + $client = new CurlClient(); + + $response = $client->retrieveResponse( + $endPoint, + array('foo' => 'bar', 'baz' => 'fab'), + array(), + 'POST' + ); + + $response = json_decode($response, true); + + $this->assertSame('application/x-www-form-urlencoded', $response['headers']['Content-Type']); + $this->assertEquals(array('foo' => 'bar', 'baz' => 'fab'), $response['form']); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponseHost() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/post')); + + $client = new CurlClient(); + + $response = $client->retrieveResponse( + $endPoint, + array('foo' => 'bar', 'baz' => 'fab'), + array(), + 'POST' + ); + + $response = json_decode($response, true); + + $this->assertSame('httpbin.org', $response['headers']['Host']); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponsePostRequestWithRequestBodyAsString() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/post')); + + $formData = array('baz' => 'fab', 'foo' => 'bar'); + + $client = new CurlClient(); + + $response = $client->retrieveResponse( + $endPoint, + $formData, + array(), + 'POST' + ); + + $response = json_decode($response, true); + + $this->assertSame($formData, $response['form']); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponsePutRequestWithRequestBodyAsString() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/put')); + + $formData = array('baz' => 'fab', 'foo' => 'bar'); + + $client = new CurlClient(); + + $response = $client->retrieveResponse( + $endPoint, + $formData, + array(), + 'PUT' + ); + + $response = json_decode($response, true); + + $this->assertSame($formData, $response['form']); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponsePutRequestWithRequestBodyAsStringNoRedirects() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/put')); + + $formData = array('baz' => 'fab', 'foo' => 'bar'); + + $client = new CurlClient(); + + $client->setMaxRedirects(0); + + $response = $client->retrieveResponse( + $endPoint, + $formData, + array(), + 'PUT' + ); + + $response = json_decode($response, true); + + $this->assertSame($formData, $response['form']); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponseWithForcedSsl3() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('https://httpbin.org/get')); + + $client = new CurlClient(); + + $client->setForceSSL3(true); + + $response = $client->retrieveResponse( + $endPoint, + '', + array('Content-Type' => 'foo/bar'), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertSame('foo/bar', $response['headers']['Content-Type']); + } + + /** + * @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse + */ + public function testRetrieveResponseThrowsExceptionOnInvalidUrl() + { + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('jkehfkefcmekjhcnkerjh')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('jkehfkefcmekjhcnkerjh')); + + $client = new CurlClient(); + + $client->setForceSSL3(true); + + $response = $client->retrieveResponse( + $endPoint, + '', + array('Content-Type' => 'foo/bar'), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertSame('foo/bar', $response['headers']['Content-Type']); + } + + public function testAdditionalParameters() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/gzip')); + + $client = new CurlClient(); + $client->setCurlParameters(array( + CURLOPT_ENCODING => 'gzip', + )); + + $response = $client->retrieveResponse( + $endPoint, + '', + array(), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertNotNull($response); + $this->assertSame('gzip', $response['headers']['Accept-Encoding']); + $this->assertTrue($response['gzipped']); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/StreamClientTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/StreamClientTest.php new file mode 100644 index 00000000..f634f406 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/StreamClientTest.php @@ -0,0 +1,283 @@ +<?php + +namespace OAuthTest\Unit\Common\Http\Client; + +use OAuth\Common\Http\Client\StreamClient; + +class StreamClientTest extends \PHPUnit_Framework_TestCase +{ + /** + * + */ + public function testConstructCorrectInstance() + { + $client = new StreamClient(); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\AbstractClient', $client); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + */ + public function testRetrieveResponseThrowsExceptionOnGetRequestWithBody() + { + $this->setExpectedException('\\InvalidArgumentException'); + + $client = new StreamClient(); + + $client->retrieveResponse( + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'), + 'foo', + array(), + 'GET' + ); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + */ + public function testRetrieveResponseThrowsExceptionOnGetRequestWithBodyMethodConvertedToUpper() + { + $this->setExpectedException('\\InvalidArgumentException'); + + $client = new StreamClient(); + + $client->retrieveResponse( + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'), + 'foo', + array(), + 'get' + ); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponseDefaultUserAgent() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/get')); + + $client = new StreamClient(); + + $response = $client->retrieveResponse( + $endPoint, + '', + array(), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertSame('PHPoAuthLib', $response['headers']['User-Agent']); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponseCustomUserAgent() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/get')); + + $client = new StreamClient('My Super Awesome Http Client'); + + $response = $client->retrieveResponse( + $endPoint, + '', + array(), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertSame('My Super Awesome Http Client', $response['headers']['User-Agent']); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponseWithCustomContentType() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/get')); + + $client = new StreamClient(); + + $response = $client->retrieveResponse( + $endPoint, + '', + array('Content-Type' => 'foo/bar'), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertSame('foo/bar', $response['headers']['Content-Type']); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponseWithFormUrlEncodedContentType() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/post')); + + $client = new StreamClient(); + + $response = $client->retrieveResponse( + $endPoint, + array('foo' => 'bar', 'baz' => 'fab'), + array(), + 'POST' + ); + + $response = json_decode($response, true); + + $this->assertSame('application/x-www-form-urlencoded', $response['headers']['Content-Type']); + $this->assertEquals(array('foo' => 'bar', 'baz' => 'fab'), $response['form']); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponseHost() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/post')); + + $client = new StreamClient(); + + $response = $client->retrieveResponse( + $endPoint, + array('foo' => 'bar', 'baz' => 'fab'), + array(), + 'POST' + ); + + $response = json_decode($response, true); + + $this->assertSame('httpbin.org', $response['headers']['Host']); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponsePostRequestWithRequestBodyAsString() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/post')); + + $formData = array('baz' => 'fab', 'foo' => 'bar'); + + $client = new StreamClient(); + + $response = $client->retrieveResponse( + $endPoint, + $formData, + array(), + 'POST' + ); + + $response = json_decode($response, true); + + $this->assertSame($formData, $response['form']); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponsePutRequestWithRequestBodyAsString() + { + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('httpbin.org')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('http://httpbin.org/put')); + + $formData = array('baz' => 'fab', 'foo' => 'bar'); + + $client = new StreamClient(); + + $response = $client->retrieveResponse( + $endPoint, + $formData, + array(), + 'PUT' + ); + + $response = json_decode($response, true); + + $this->assertSame($formData, $response['form']); + } + + /** + * @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse + * @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext + */ + public function testRetrieveResponseThrowsExceptionOnInvalidRequest() + { + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $endPoint->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('dskjhfckjhekrsfhkehfkreljfrekljfkre')); + $endPoint->expects($this->any()) + ->method('getAbsoluteUri') + ->will($this->returnValue('dskjhfckjhekrsfhkehfkreljfrekljfkre')); + + $client = new StreamClient(); + + $response = $client->retrieveResponse( + $endPoint, + '', + array('Content-Type' => 'foo/bar'), + 'get' + ); + + $response = json_decode($response, true); + + $this->assertSame('foo/bar', $response['headers']['Content-Type']); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Http/HttpClientsTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Http/HttpClientsTest.php new file mode 100644 index 00000000..6fa9eace --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Http/HttpClientsTest.php @@ -0,0 +1,171 @@ +<?php + +/** + * @category OAuth + * @package Tests + * @author David Desberg <david@daviddesberg.com> + * @copyright Copyright (c) 2012 The authors + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +namespace OAuth\Unit\Common\Http; + +use OAuth\Common\Http\Uri\Uri; +use OAuth\Common\Http\Uri\UriInterface; +use OAuth\Common\Http\Client; + +class HttpClientsTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var object|\OAuth\Common\Http\Client\ClientInterface[] + */ + protected $clients; + + public function setUp() + { + $streamClient = new Client\StreamClient(); + $streamClient->setTimeout(3); + + $curlClient = new Client\CurlClient(); + $curlClient->setTimeout(3); + + $this->clients[] = $streamClient; + $this->clients[] = $curlClient; + } + + public function tearDown() + { + foreach ($this->clients as $client) { + unset($client); + } + } + + /** + * Test that extra headers are passed properly + */ + public function testHeaders() + { + $testUri = new Uri('http://httpbin.org/get'); + + $me = $this; + $headerCb = function ($response) use ($me) { + $data = json_decode($response, true); + $me->assertEquals('extraheadertest', $data['headers']['Testingheader']); + }; + + $this->__doTestRetrieveResponse($testUri, array(), array('Testingheader' => 'extraheadertest'), 'GET', $headerCb); + } + + /** + * Tests that we get an exception for a >= 400 status code + */ + public function testException() + { + // sending a post here should get us a 405 which should trigger an exception + $testUri = new Uri('http://httpbin.org/delete'); + foreach ($this->clients as $client) { + $this->setExpectedException('OAuth\Common\Http\Exception\TokenResponseException'); + $client->retrieveResponse($testUri, array('blah' => 'blih')); + } + } + + /** + * Tests the DELETE method + */ + public function testDelete() + { + $testUri = new Uri('http://httpbin.org/delete'); + + $me = $this; + $deleteTestCb = function ($response) use ($me) { + $data = json_decode($response, true); + $me->assertEquals('', $data['data']); + }; + + $this->__doTestRetrieveResponse($testUri, array(), array(), 'DELETE', $deleteTestCb); + } + + /** + * Tests the PUT method + */ + public function testPut() + { + $testUri = new Uri('http://httpbin.org/put'); + + $me = $this; + $putTestCb = function ($response) use ($me) { + // verify the put response + $data = json_decode($response, true); + $me->assertEquals(json_encode(array('testKey' => 'testValue')), $data['data']); + }; + + $this->__doTestRetrieveResponse($testUri, json_encode(array('testKey' => 'testValue')), array('Content-Type' => 'application/json'), 'PUT', $putTestCb); + } + + /** + * Tests the POST method + */ + public function testPost() + { + // http test server + $testUri = new Uri('http://httpbin.org/post'); + + $me = $this; + $postTestCb = function ($response) use ($me) { + // verify the post response + $data = json_decode($response, true); + // note that we check this because the retrieveResponse wrapper function automatically adds a content-type + // if there isn't one and it + $me->assertEquals('testValue', $data['form']['testKey']); + }; + + $this->__doTestRetrieveResponse($testUri, array('testKey' => 'testValue'), array(), 'POST', $postTestCb); + } + + /** + * Expect exception when we try to send a GET request with a body + */ + public function testInvalidGet() + { + $testUri = new Uri('http://site.net'); + + foreach ($this->clients as $client) { + $this->setExpectedException('InvalidArgumentException'); + $client->retrieveResponse($testUri, array('blah' => 'blih'), array(), 'GET'); + } + } + + /** + * Tests the GET method + */ + public function testGet() + { + // test uri + $testUri = new Uri('http://httpbin.org/get?testKey=testValue'); + + $me = $this; + $getTestCb = function ($response) use ($me) { + $data = json_decode($response, true); + $me->assertEquals('testValue', $data['args']['testKey']); + }; + + $this->__doTestRetrieveResponse($testUri, array(), array(), 'GET', $getTestCb); + } + + /** + * Test on all HTTP clients. + * + * @param UriInterface $uri + * @param array $param + * @param array $header + * @param string $method + * @param \Closure $responseCallback + */ + protected function __doTestRetrieveResponse(UriInterface $uri, $param, array $header, $method, $responseCallback) + { + foreach ($this->clients as $client) { + $response = $client->retrieveResponse($uri, $param, $header, $method); + $responseCallback($response, $client); + } + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Http/Uri/UriFactoryTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Uri/UriFactoryTest.php new file mode 100644 index 00000000..ea743509 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Uri/UriFactoryTest.php @@ -0,0 +1,331 @@ +<?php + +namespace OAuthTest\Unit\Common\Http\Uri; + +use OAuth\Common\Http\Uri\UriFactory; +use OAuth\Common\Http\Uri\Uri; + +class UriFactoryTest extends \PHPUnit_Framework_TestCase +{ + /** + * + */ + public function testConstructCorrectInterface() + { + $factory = new UriFactory(); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriFactoryInterface', $factory); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + */ + public function testCreateFromSuperGlobalArrayUsingProxyStyle() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array('REQUEST_URI' => 'http://example.com')); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayHttp() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTPS' => 'off', + 'HTTP_HOST' => 'example.com', + 'REQUEST_URI' => '/foo', + 'QUERY_STRING' => 'param1=value1', + )); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * This looks wonky David. Should the port really fallback to 80 even when supplying https as scheme? + * + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayHttps() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTPS' => 'on', + 'HTTP_HOST' => 'example.com', + 'REQUEST_URI' => '/foo', + 'QUERY_STRING' => 'param1=value1', + )); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('https://example.com:80/foo?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayPortSupplied() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTP_HOST' => 'example.com', + 'SERVER_PORT' => 21, + 'REQUEST_URI' => '/foo', + 'QUERY_STRING' => 'param1=value1', + )); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com:21/foo?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayPortNotSet() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTP_HOST' => 'example.com', + 'REQUEST_URI' => '/foo', + 'QUERY_STRING' => 'param1=value1', + )); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayRequestUriSet() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTP_HOST' => 'example.com', + 'REQUEST_URI' => '/foo', + 'QUERY_STRING' => 'param1=value1', + )); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayRedirectUrlSet() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTP_HOST' => 'example.com', + 'REDIRECT_URL' => '/foo', + 'QUERY_STRING' => 'param1=value1', + )); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayThrowsExceptionOnDetectingPathMissingIndices() + { + $factory = new UriFactory(); + + $this->setExpectedException('\\RuntimeException'); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTP_HOST' => 'example.com', + 'QUERY_STRING' => 'param1=value1', + )); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayWithQueryString() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTP_HOST' => 'example.com', + 'REQUEST_URI' => '/foo?param1=value1', + 'QUERY_STRING' => 'param1=value1', + )); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayWithoutQueryString() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTP_HOST' => 'example.com', + 'REQUEST_URI' => '/foo', + )); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com/foo', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray + * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse + * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme + * @covers OAuth\Common\Http\Uri\UriFactory::detectHost + * @covers OAuth\Common\Http\Uri\UriFactory::detectPort + * @covers OAuth\Common\Http\Uri\UriFactory::detectPath + * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery + * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts + */ + public function testCreateFromSuperGlobalArrayHostWithColon() + { + $factory = new UriFactory(); + + $uri = $factory->createFromSuperGlobalArray(array( + 'HTTP_HOST' => 'example.com:80', + 'REQUEST_URI' => '/foo', + )); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com/foo', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\UriFactory::createFromAbsolute + */ + public function testCreateFromAbsolute() + { + $factory = new UriFactory(); + + $uri = $factory->createFromAbsolute('http://example.com'); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $uri + ); + + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Http/Uri/UriTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Uri/UriTest.php new file mode 100644 index 00000000..bc158ffa --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Http/Uri/UriTest.php @@ -0,0 +1,898 @@ +<?php + +namespace OAuthTest\Unit\Common\Http\Uri; + +use OAuth\Common\Http\Uri\Uri; + +class UriTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + */ + public function testConstructCorrectInterfaceWithoutUri() + { + $uri = new Uri(); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + */ + public function testConstructThrowsExceptionOnInvalidUri() + { + $this->setExpectedException('\\InvalidArgumentException'); + + // http://lxr.php.net/xref/PHP_5_4/ext/standard/tests/url/urls.inc#92 + $uri = new Uri('http://@:/'); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + */ + public function testConstructThrowsExceptionOnUriWithoutScheme() + { + $this->setExpectedException('\\InvalidArgumentException'); + + $uri = new Uri('www.pieterhordijk.com'); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getScheme + */ + public function testGetScheme() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('http', $uri->getScheme()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getUserInfo + */ + public function testGetUserInfo() + { + $uri = new Uri('http://peehaa@example.com'); + + $this->assertSame('peehaa', $uri->getUserInfo()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getUserInfo + */ + public function testGetUserInfoWithPass() + { + $uri = new Uri('http://peehaa:pass@example.com'); + + $this->assertSame('peehaa:********', $uri->getUserInfo()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getRawUserInfo + */ + public function testGetRawUserInfo() + { + $uri = new Uri('http://peehaa@example.com'); + + $this->assertSame('peehaa', $uri->getRawUserInfo()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getRawUserInfo + */ + public function testGetRawUserInfoWithPass() + { + $uri = new Uri('http://peehaa:pass@example.com'); + + $this->assertSame('peehaa:pass', $uri->getRawUserInfo()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getHost + */ + public function testGetHost() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('example.com', $uri->getHost()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getPort + */ + public function testGetPortImplicitHttp() + { + $uri = new Uri('http://example.com'); + + $this->assertSame(80, $uri->getPort()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getPort + */ + public function testGetPortImplicitHttps() + { + $uri = new Uri('https://example.com'); + + $this->assertSame(443, $uri->getPort()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getPort + */ + public function testGetPortExplicit() + { + $uri = new Uri('http://example.com:21'); + + $this->assertSame(21, $uri->getPort()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getPath + */ + public function testGetPathNotSupplied() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('/', $uri->getPath()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getPath + */ + public function testGetPathSlash() + { + $uri = new Uri('http://example.com/'); + + $this->assertSame('/', $uri->getPath()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getPath + */ + public function testGetPath() + { + $uri = new Uri('http://example.com/foo'); + + $this->assertSame('/foo', $uri->getPath()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getQuery + */ + public function testGetQueryWithParams() + { + $uri = new Uri('http://example.com?param1=first¶m2=second'); + + $this->assertSame('param1=first¶m2=second', $uri->getQuery()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getQuery + */ + public function testGetQueryWithoutParams() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('', $uri->getQuery()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getFragment + */ + public function testGetFragmentExists() + { + $uri = new Uri('http://example.com#foo'); + + $this->assertSame('foo', $uri->getFragment()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getFragment + */ + public function testGetFragmentNotExists() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('', $uri->getFragment()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getAuthority + */ + public function testGetAuthorityWithoutUserInfo() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('example.com', $uri->getAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getAuthority + */ + public function testGetAuthorityWithoutUserInfoWithExplicitPort() + { + $uri = new Uri('http://example.com:21'); + + $this->assertSame('example.com:21', $uri->getAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getAuthority + */ + public function testGetAuthorityWithUsernameWithExplicitPort() + { + $uri = new Uri('http://peehaa@example.com:21'); + + $this->assertSame('peehaa@example.com:21', $uri->getAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getAuthority + */ + public function testGetAuthorityWithUsernameAndPassWithExplicitPort() + { + $uri = new Uri('http://peehaa:pass@example.com:21'); + + $this->assertSame('peehaa:********@example.com:21', $uri->getAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getAuthority + */ + public function testGetAuthorityWithUsernameAndPassWithoutExplicitPort() + { + $uri = new Uri('http://peehaa:pass@example.com'); + + $this->assertSame('peehaa:********@example.com', $uri->getAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority + */ + public function testGetRawAuthorityWithoutUserInfo() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('example.com', $uri->getRawAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority + */ + public function testGetRawAuthorityWithoutUserInfoWithExplicitPort() + { + $uri = new Uri('http://example.com:21'); + + $this->assertSame('example.com:21', $uri->getRawAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority + */ + public function testGetRawAuthorityWithUsernameWithExplicitPort() + { + $uri = new Uri('http://peehaa@example.com:21'); + + $this->assertSame('peehaa@example.com:21', $uri->getRawAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority + */ + public function testGetRawAuthorityWithUsernameAndPassWithExplicitPort() + { + $uri = new Uri('http://peehaa:pass@example.com:21'); + + $this->assertSame('peehaa:pass@example.com:21', $uri->getRawAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority + */ + public function testGetRawAuthorityWithUsernameAndPassWithoutExplicitPort() + { + $uri = new Uri('http://peehaa:pass@example.com'); + + $this->assertSame('peehaa:pass@example.com', $uri->getRawAuthority()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testGetAbsoluteUriBare() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testGetAbsoluteUriWithAuthority() + { + $uri = new Uri('http://peehaa:pass@example.com'); + + $this->assertSame('http://peehaa:pass@example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testGetAbsoluteUriWithPath() + { + $uri = new Uri('http://example.com/foo'); + + $this->assertSame('http://example.com/foo', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testGetAbsoluteUriWithoutPath() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testGetAbsoluteUriWithoutPathExplicitTrailingSlash() + { + $uri = new Uri('http://example.com/'); + + $this->assertSame('http://example.com/', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testGetAbsoluteUriWithQuery() + { + $uri = new Uri('http://example.com?param1=value1'); + + $this->assertSame('http://example.com?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testGetAbsoluteUriWithFragment() + { + $uri = new Uri('http://example.com#foo'); + + $this->assertSame('http://example.com#foo', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getRelativeUri + */ + public function testGetRelativeUriWithoutPath() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('', $uri->getRelativeUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getRelativeUri + */ + public function testGetRelativeUriWithPath() + { + $uri = new Uri('http://example.com/foo'); + + $this->assertSame('/foo', $uri->getRelativeUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::getRelativeUri + */ + public function testGetRelativeUriWithExplicitTrailingSlash() + { + $uri = new Uri('http://example.com/'); + + $this->assertSame('/', $uri->getRelativeUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::__toString + */ + public function testToStringBare() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('http://example.com', (string) $uri); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getRawAuthority + * @covers OAuth\Common\Http\Uri\Uri::__toString + */ + public function testToStringWithAuthority() + { + $uri = new Uri('http://peehaa:pass@example.com'); + + $this->assertSame('http://peehaa:********@example.com', (string) $uri); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::__toString + */ + public function testToStringWithPath() + { + $uri = new Uri('http://example.com/foo'); + + $this->assertSame('http://example.com/foo', (string) $uri); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::__toString + */ + public function testToStringWithoutPath() + { + $uri = new Uri('http://example.com'); + + $this->assertSame('http://example.com', (string) $uri); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::__toString + */ + public function testToStringWithoutPathExplicitTrailingSlash() + { + $uri = new Uri('http://example.com/'); + + $this->assertSame('http://example.com/', (string) $uri); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::__toString + */ + public function testToStringWithQuery() + { + $uri = new Uri('http://example.com?param1=value1'); + + $this->assertSame('http://example.com?param1=value1', (string) $uri); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::__toString + */ + public function testToStringWithFragment() + { + $uri = new Uri('http://example.com#foo'); + + $this->assertSame('http://example.com#foo', (string) $uri); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setPath + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetPathEmpty() + { + $uri = new Uri('http://example.com'); + $uri->setPath(''); + + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setPath + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetPathWithPath() + { + $uri = new Uri('http://example.com'); + $uri->setPath('/foo'); + + $this->assertSame('http://example.com/foo', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setPath + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetPathWithOnlySlash() + { + $uri = new Uri('http://example.com'); + $uri->setPath('/'); + + $this->assertSame('http://example.com/', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setQuery + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetQueryEmpty() + { + $uri = new Uri('http://example.com'); + $uri->setQuery(''); + + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setQuery + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetQueryFilled() + { + $uri = new Uri('http://example.com'); + $uri->setQuery('param1=value1¶m2=value2'); + + $this->assertSame('http://example.com?param1=value1¶m2=value2', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::addToQuery + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testAddToQueryAppend() + { + $uri = new Uri('http://example.com?param1=value1'); + $uri->addToQuery('param2', 'value2'); + + $this->assertSame('http://example.com?param1=value1¶m2=value2', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::addToQuery + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testAddToQueryCreate() + { + $uri = new Uri('http://example.com'); + $uri->addToQuery('param1', 'value1'); + + $this->assertSame('http://example.com?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setFragment + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetFragmentEmpty() + { + $uri = new Uri('http://example.com'); + $uri->setFragment(''); + + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setFragment + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetFragmentWithData() + { + $uri = new Uri('http://example.com'); + $uri->setFragment('foo'); + + $this->assertSame('http://example.com#foo', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setScheme + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetSchemeWithEmpty() + { + $uri = new Uri('http://example.com'); + $uri->setScheme(''); + + $this->assertSame('://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setScheme + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetSchemeWithData() + { + $uri = new Uri('http://example.com'); + $uri->setScheme('foo'); + + $this->assertSame('foo://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetUserInfoEmpty() + { + $uri = new Uri('http://example.com'); + $uri->setUserInfo(''); + + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setUserInfo + * @covers OAuth\Common\Http\Uri\Uri::protectUserInfo + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetUserInfoWithData() + { + $uri = new Uri('http://example.com'); + $uri->setUserInfo('foo:bar'); + + $this->assertSame('http://foo:bar@example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setPort + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetPortCustom() + { + $uri = new Uri('http://example.com'); + $uri->setPort('21'); + + $this->assertSame('http://example.com:21', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setPort + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetPortHttpImplicit() + { + $uri = new Uri('http://example.com'); + $uri->setPort(80); + + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setPort + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetPortHttpsImplicit() + { + $uri = new Uri('https://example.com'); + $uri->setPort(443); + + $this->assertSame('https://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setPort + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetPortHttpExplicit() + { + $uri = new Uri('http://example.com'); + $uri->setPort(443); + + $this->assertSame('http://example.com:443', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setPort + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetPortHttpsExplicit() + { + $uri = new Uri('https://example.com'); + $uri->setPort(80); + + $this->assertSame('https://example.com:80', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::setHost + * @covers OAuth\Common\Http\Uri\Uri::getAbsoluteUri + */ + public function testSetHost() + { + $uri = new Uri('http://example.com'); + $uri->setHost('pieterhordijk.com'); + + $this->assertSame('http://pieterhordijk.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::hasExplicitTrailingHostSlash + */ + public function testHasExplicitTrailingHostSlashTrue() + { + $uri = new Uri('http://example.com/'); + + $this->assertTrue($uri->hasExplicitTrailingHostSlash()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::hasExplicitTrailingHostSlash + */ + public function testHasExplicitTrailingHostSlashFalse() + { + $uri = new Uri('http://example.com/foo'); + + $this->assertFalse($uri->hasExplicitTrailingHostSlash()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::hasExplicitPortSpecified + */ + public function testHasExplicitPortSpecifiedTrue() + { + $uri = new Uri('http://example.com:8080'); + + $this->assertTrue($uri->hasExplicitPortSpecified()); + } + + /** + * @covers OAuth\Common\Http\Uri\Uri::__construct + * @covers OAuth\Common\Http\Uri\Uri::parseUri + * @covers OAuth\Common\Http\Uri\Uri::hasExplicitPortSpecified + */ + public function testHasExplicitPortSpecifiedFalse() + { + $uri = new Uri('http://example.com'); + + $this->assertFalse($uri->hasExplicitPortSpecified()); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Service/AbstractServiceTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Service/AbstractServiceTest.php new file mode 100644 index 00000000..2d8bff46 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Service/AbstractServiceTest.php @@ -0,0 +1,171 @@ +<?php + +namespace OAuthTest\Unit\Common\Service; + +use OAuthTest\Mocks\Common\Service\Mock; + +class AbstractServiceTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\Common\Service\AbstractService::__construct + */ + public function testConstructCorrectInterface() + { + $service = $this->getMockForAbstractClass( + '\\OAuth\\Common\\Service\\AbstractService', + array( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ) + ); + + $this->assertInstanceOf('\\OAuth\\Common\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\Common\Service\AbstractService::__construct + * @covers OAuth\Common\Service\AbstractService::getStorage + */ + public function testGetStorage() + { + $service = $this->getMockForAbstractClass( + '\\OAuth\\Common\\Service\\AbstractService', + array( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ) + ); + + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $service->getStorage()); + } + + /** + * @covers OAuth\Common\Service\AbstractService::__construct + * @covers OAuth\Common\Service\AbstractService::service + */ + public function testService() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('Mock', $service->service()); + } + + /** + * @covers OAuth\Common\Service\AbstractService::__construct + * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath + */ + public function testDetermineRequestUriFromPathUsingUriObject() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Http\\Uri\\UriInterface', + $service->testDetermineRequestUriFromPath($this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface')) + ); + } + + /** + * @covers OAuth\Common\Service\AbstractService::__construct + * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath + */ + public function testDetermineRequestUriFromPathUsingHttpPath() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $uri = $service->testDetermineRequestUriFromPath('http://example.com'); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri); + $this->assertSame('http://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Service\AbstractService::__construct + * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath + */ + public function testDetermineRequestUriFromPathUsingHttpsPath() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $uri = $service->testDetermineRequestUriFromPath('https://example.com'); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri); + $this->assertSame('https://example.com', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Service\AbstractService::__construct + * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath + */ + public function testDetermineRequestUriFromPathThrowsExceptionOnInvalidUri() + { + $this->setExpectedException('\\OAuth\\Common\\Exception\\Exception'); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $uri = $service->testDetermineRequestUriFromPath('example.com'); + } + + /** + * @covers OAuth\Common\Service\AbstractService::__construct + * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath + */ + public function testDetermineRequestUriFromPathWithQueryString() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $uri = $service->testDetermineRequestUriFromPath( + 'path?param1=value1', + new \OAuth\Common\Http\Uri\Uri('https://example.com') + ); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri); + $this->assertSame('https://example.com/path?param1=value1', $uri->getAbsoluteUri()); + } + + /** + * @covers OAuth\Common\Service\AbstractService::__construct + * @covers OAuth\Common\Service\AbstractService::determineRequestUriFromPath + */ + public function testDetermineRequestUriFromPathWithLeadingSlashInPath() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $uri = $service->testDetermineRequestUriFromPath( + '/path', + new \OAuth\Common\Http\Uri\Uri('https://example.com') + ); + + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri); + $this->assertSame('https://example.com/path', $uri->getAbsoluteUri()); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Storage/MemoryTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/MemoryTest.php new file mode 100644 index 00000000..93a01a79 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/MemoryTest.php @@ -0,0 +1,132 @@ +<?php + +namespace OAuthTest\Unit\Common\Storage; + +use OAuth\Common\Storage\Memory; + +class MemoryTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\Common\Storage\Memory::__construct + */ + public function testConstructCorrectInterface() + { + $storage = new Memory(); + + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); + } + + /** + * @covers OAuth\Common\Storage\Memory::__construct + * @covers OAuth\Common\Storage\Memory::storeAccessToken + */ + public function testStoreAccessToken() + { + $storage = new Memory(); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Storage\\Memory', + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')) + ); + } + + /** + * @covers OAuth\Common\Storage\Memory::__construct + * @covers OAuth\Common\Storage\Memory::storeAccessToken + * @covers OAuth\Common\Storage\Memory::retrieveAccessToken + * @covers OAuth\Common\Storage\Memory::hasAccessToken + */ + public function testRetrieveAccessTokenValid() + { + $storage = new Memory(); + + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + + $this->assertInstanceOf('\\OAuth\\Common\\Token\\TokenInterface', $storage->retrieveAccessToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Memory::__construct + * @covers OAuth\Common\Storage\Memory::retrieveAccessToken + * @covers OAuth\Common\Storage\Memory::hasAccessToken + */ + public function testRetrieveAccessTokenThrowsExceptionWhenTokenIsNotFound() + { + $this->setExpectedException('\\OAuth\\Common\\Storage\\Exception\\TokenNotFoundException'); + + $storage = new Memory(); + + $storage->retrieveAccessToken('foo'); + } + + /** + * @covers OAuth\Common\Storage\Memory::__construct + * @covers OAuth\Common\Storage\Memory::storeAccessToken + * @covers OAuth\Common\Storage\Memory::hasAccessToken + */ + public function testHasAccessTokenTrue() + { + $storage = new Memory(); + + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + + $this->assertTrue($storage->hasAccessToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Memory::__construct + * @covers OAuth\Common\Storage\Memory::hasAccessToken + */ + public function testHasAccessTokenFalse() + { + $storage = new Memory(); + + $this->assertFalse($storage->hasAccessToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Memory::__construct + * @covers OAuth\Common\Storage\Memory::clearToken + */ + public function testClearTokenIsNotSet() + { + $storage = new Memory(); + + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Memory::__construct + * @covers OAuth\Common\Storage\Memory::storeAccessToken + * @covers OAuth\Common\Storage\Memory::clearToken + */ + public function testClearTokenSet() + { + $storage = new Memory(); + + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + + $this->assertTrue($storage->hasAccessToken('foo')); + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearToken('foo')); + $this->assertFalse($storage->hasAccessToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Memory::__construct + * @covers OAuth\Common\Storage\Memory::storeAccessToken + * @covers OAuth\Common\Storage\Memory::clearAllTokens + */ + public function testClearAllTokens() + { + $storage = new Memory(); + + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + $storage->storeAccessToken('bar', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + + $this->assertTrue($storage->hasAccessToken('foo')); + $this->assertTrue($storage->hasAccessToken('bar')); + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearAllTokens()); + $this->assertFalse($storage->hasAccessToken('foo')); + $this->assertFalse($storage->hasAccessToken('bar')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Storage/RedisTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/RedisTest.php new file mode 100644 index 00000000..83e7a284 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/RedisTest.php @@ -0,0 +1,102 @@ +<?php + +/** + * @category OAuth + * @package Tests + * @author David Desberg <david@daviddesberg.com> + * @copyright Copyright (c) 2012 The authors + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +namespace OAuth\Unit\Common\Storage; + +use OAuth\Common\Storage\Redis; +use Predis\Client as Predis; +use OAuth\OAuth2\Token\StdOAuth2Token; + +class RedisTest extends \PHPUnit_Framework_TestCase +{ + protected $storage; + + public function setUp() + { + // connect to a redis daemon + $predis = new Predis(array( + 'host' => $_ENV['redis_host'], + 'port' => $_ENV['redis_port'], + )); + + // set it + $this->storage = new Redis($predis, 'test_user_token', 'test_user_state'); + + try { + $predis->connect(); + } catch (\Predis\Connection\ConnectionException $e) { + $this->markTestSkipped('No redis instance available: ' . $e->getMessage()); + } + } + + public function tearDown() + { + // delete + $this->storage->clearAllTokens(); + + // close connection + $this->storage->getRedis()->quit(); + } + + /** + * Check that the token gets properly stored. + */ + public function testStorage() + { + // arrange + $service_1 = 'Facebook'; + $service_2 = 'Foursquare'; + + $token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + $token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + + // act + $this->storage->storeAccessToken($service_1, $token_1); + $this->storage->storeAccessToken($service_2, $token_2); + + // assert + $extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams(); + $this->assertEquals('param', $extraParams['extra']); + $this->assertEquals($token_1, $this->storage->retrieveAccessToken($service_1)); + $this->assertEquals($token_2, $this->storage->retrieveAccessToken($service_2)); + } + + /** + * Test hasAccessToken. + */ + public function testHasAccessToken() + { + // arrange + $service = 'Facebook'; + $this->storage->clearToken($service); + + // act + // assert + $this->assertFalse($this->storage->hasAccessToken($service)); + } + + /** + * Check that the token gets properly deleted. + */ + public function testStorageClears() + { + // arrange + $service = 'Facebook'; + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + + // act + $this->storage->storeAccessToken($service, $token); + $this->storage->clearToken($service); + + // assert + $this->setExpectedException('OAuth\Common\Storage\Exception\TokenNotFoundException'); + $this->storage->retrieveAccessToken($service); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Storage/SessionTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/SessionTest.php new file mode 100644 index 00000000..72f38b1a --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/SessionTest.php @@ -0,0 +1,245 @@ +<?php + +namespace OAuthTest\Unit\Common\Storage; + +use OAuth\Common\Storage\Session; + +class SessionTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\Common\Storage\Session::__construct + * + * @runInSeparateProcess + */ + public function testConstructCorrectInterface() + { + $storage = new Session(); + + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * + * @runInSeparateProcess + */ + public function testConstructWithoutStartingSession() + { + session_start(); + + $storage = new Session(false); + + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * + * @runInSeparateProcess + */ + public function testConstructTryingToStartWhileSessionAlreadyExists() + { + session_start(); + + $storage = new Session(); + + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * + * @runInSeparateProcess + */ + public function testConstructWithExistingSessionKey() + { + session_start(); + + $_SESSION['lusitanian_oauth_token'] = array(); + + $storage = new Session(); + + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::storeAccessToken + * + * @runInSeparateProcess + */ + public function testStoreAccessTokenIsAlreadyArray() + { + $storage = new Session(); + + $this->assertInstanceOf( + '\\OAuth\\Common\\Storage\\Session', + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')) + ); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::storeAccessToken + * + * @runInSeparateProcess + */ + public function testStoreAccessTokenIsNotArray() + { + $storage = new Session(); + + $_SESSION['lusitanian_oauth_token'] = 'foo'; + + $this->assertInstanceOf( + '\\OAuth\\Common\\Storage\\Session', + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')) + ); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::storeAccessToken + * @covers OAuth\Common\Storage\Session::retrieveAccessToken + * @covers OAuth\Common\Storage\Session::hasAccessToken + * + * @runInSeparateProcess + */ + public function testRetrieveAccessTokenValid() + { + $storage = new Session(); + + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + + $this->assertInstanceOf('\\OAuth\\Common\\Token\\TokenInterface', $storage->retrieveAccessToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::retrieveAccessToken + * @covers OAuth\Common\Storage\Session::hasAccessToken + * + * @runInSeparateProcess + */ + public function testRetrieveAccessTokenThrowsExceptionWhenTokenIsNotFound() + { + $this->setExpectedException('\\OAuth\\Common\\Storage\\Exception\\TokenNotFoundException'); + + $storage = new Session(); + + $storage->retrieveAccessToken('foo'); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::storeAccessToken + * @covers OAuth\Common\Storage\Session::hasAccessToken + * + * @runInSeparateProcess + */ + public function testHasAccessTokenTrue() + { + $storage = new Session(); + + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + + $this->assertTrue($storage->hasAccessToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::hasAccessToken + * + * @runInSeparateProcess + */ + public function testHasAccessTokenFalse() + { + $storage = new Session(); + + $this->assertFalse($storage->hasAccessToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::clearToken + * + * @runInSeparateProcess + */ + public function testClearTokenIsNotSet() + { + $storage = new Session(); + + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\Session', $storage->clearToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::storeAccessToken + * @covers OAuth\Common\Storage\Session::clearToken + * + * @runInSeparateProcess + */ + public function testClearTokenSet() + { + $storage = new Session(); + + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + + $this->assertTrue($storage->hasAccessToken('foo')); + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\Session', $storage->clearToken('foo')); + $this->assertFalse($storage->hasAccessToken('foo')); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::storeAccessToken + * @covers OAuth\Common\Storage\Session::clearAllTokens + * + * @runInSeparateProcess + */ + public function testClearAllTokens() + { + $storage = new Session(); + + $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + $storage->storeAccessToken('bar', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); + + $this->assertTrue($storage->hasAccessToken('foo')); + $this->assertTrue($storage->hasAccessToken('bar')); + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\Session', $storage->clearAllTokens()); + $this->assertFalse($storage->hasAccessToken('foo')); + $this->assertFalse($storage->hasAccessToken('bar')); + } + + /** + * @covers OAuth\Common\Storage\Session::__construct + * @covers OAuth\Common\Storage\Session::__destruct + * + * @runInSeparateProcess + */ + public function testDestruct() + { + $storage = new Session(); + + unset($storage); + } + + /** + * @covers OAuth\Common\Storage\Session::storeAccessToken + * @covers OAuth\Common\Storage\Session::retrieveAccessToken + * + * @runInSeparateProcess + */ + public function testSerializeUnserialize() + { + $mock = $this->getMock('\\OAuth\\Common\\Token\\AbstractToken', array('__sleep')); + $mock->expects($this->once()) + ->method('__sleep') + ->will($this->returnValue(array('accessToken'))); + + $storage = new Session(); + $storage->storeAccessToken('foo', $mock); + $retrievedToken = $storage->retrieveAccessToken('foo'); + + $this->assertInstanceOf('\\OAuth\\Common\\Token\\AbstractToken', $retrievedToken); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Storage/StorageTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/StorageTest.php new file mode 100644 index 00000000..3fe19906 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/StorageTest.php @@ -0,0 +1,74 @@ +<?php + +/** + * @category OAuth + * @package Tests + * @author David Desberg <david@daviddesberg.com> + * @author Hannes Van De Vreken <vandevreken.hannes@gmail.com> + * @copyright Copyright (c) 2012 The authors + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +namespace OAuth\Unit\Common\Storage; + +use \OAuth\OAuth2\Token\StdOAuth2Token; + +abstract class StorageTest extends \PHPUnit_Framework_TestCase +{ + protected $storage; + + /** + * Check that the token gets properly stored. + */ + public function testStorage() + { + // arrange + $service_1 = 'Facebook'; + $service_2 = 'Foursquare'; + + $token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + $token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + + // act + $this->storage->storeAccessToken($service_1, $token_1); + $this->storage->storeAccessToken($service_2, $token_2); + + // assert + $extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams(); + $this->assertEquals('param', $extraParams['extra']); + $this->assertEquals($token_1, $this->storage->retrieveAccessToken($service_1)); + $this->assertEquals($token_2, $this->storage->retrieveAccessToken($service_2)); + } + + /** + * Test hasAccessToken. + */ + public function testHasAccessToken() + { + // arrange + $service = 'Facebook'; + $this->storage->clearToken($service); + + // act + // assert + $this->assertFalse($this->storage->hasAccessToken($service)); + } + + /** + * Check that the token gets properly deleted. + */ + public function testStorageClears() + { + // arrange + $service = 'Facebook'; + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + + // act + $this->storage->storeAccessToken($service, $token); + $this->storage->clearToken($service); + + // assert + $this->setExpectedException('OAuth\Common\Storage\Exception\TokenNotFoundException'); + $this->storage->retrieveAccessToken($service); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Storage/SymfonySessionTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/SymfonySessionTest.php new file mode 100644 index 00000000..c6434612 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Storage/SymfonySessionTest.php @@ -0,0 +1,111 @@ +<?php + +/** + * @category OAuth + * @package Tests + * @author David Desberg <david@daviddesberg.com> + * @copyright Copyright (c) 2012 The authors + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +namespace OAuth\Unit\Common\Storage; + +use OAuth\Common\Storage\SymfonySession; +use OAuth\OAuth2\Token\StdOAuth2Token; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; + +class SymfonySessionTest extends \PHPUnit_Framework_TestCase +{ + protected $session; + + protected $storage; + + public function setUp() + { + // set it + $this->session = new Session(new MockArraySessionStorage()); + $this->storage = new SymfonySession($this->session); + } + + public function tearDown() + { + // delete + $this->storage->getSession()->clear(); + unset($this->storage); + } + + /** + * Check that the token survives the constructor + */ + public function testStorageSurvivesConstructor() + { + $service = 'Facebook'; + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + + // act + $this->storage->storeAccessToken($service, $token); + $this->storage = null; + $this->storage = new SymfonySession($this->session); + + // assert + $extraParams = $this->storage->retrieveAccessToken($service)->getExtraParams(); + $this->assertEquals('param', $extraParams['extra']); + $this->assertEquals($token, $this->storage->retrieveAccessToken($service)); + } + + /** + * Check that the token gets properly stored. + */ + public function testStorage() + { + // arrange + $service_1 = 'Facebook'; + $service_2 = 'Foursquare'; + + $token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + $token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + + // act + $this->storage->storeAccessToken($service_1, $token_1); + $this->storage->storeAccessToken($service_2, $token_2); + + // assert + $extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams(); + $this->assertEquals('param', $extraParams['extra']); + $this->assertEquals($token_1, $this->storage->retrieveAccessToken($service_1)); + $this->assertEquals($token_2, $this->storage->retrieveAccessToken($service_2)); + } + + /** + * Test hasAccessToken. + */ + public function testHasAccessToken() + { + // arrange + $service = 'Facebook'; + $this->storage->clearToken($service); + + // act + // assert + $this->assertFalse($this->storage->hasAccessToken($service)); + } + + /** + * Check that the token gets properly deleted. + */ + public function testStorageClears() + { + // arrange + $service = 'Facebook'; + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); + + // act + $this->storage->storeAccessToken($service, $token); + $this->storage->clearToken($service); + + // assert + $this->setExpectedException('OAuth\Common\Storage\Exception\TokenNotFoundException'); + $this->storage->retrieveAccessToken($service); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/Common/Token/AbstractTokenTest.php b/vendor/lusitanian/oauth/tests/Unit/Common/Token/AbstractTokenTest.php new file mode 100644 index 00000000..54b3bb63 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/Common/Token/AbstractTokenTest.php @@ -0,0 +1,189 @@ +<?php + +namespace OAuthTest\Unit\Common\Token; + +use \OAuth\Common\Token\AbstractToken; + +class AbstractTokenTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + */ + public function testConstructCorrectInterface() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken'); + + $this->assertInstanceOf('\\OAuth\\Common\\Token\\TokenInterface', $token); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::getAccessToken + */ + public function testGetAccessTokenNotSet() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken'); + + $this->assertNull($token->getAccessToken()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::getAccessToken + */ + public function testGetAccessTokenSet() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken', array('foo')); + + $this->assertSame('foo', $token->getAccessToken()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::getAccessToken + * @covers OAuth\Common\Token\AbstractToken::setAccessToken + */ + public function testSetAccessToken() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken'); + + $token->setAccessToken('foo'); + + $this->assertSame('foo', $token->getAccessToken()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::getRefreshToken + */ + public function testGetRefreshToken() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken'); + + $this->assertNull($token->getRefreshToken()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::getRefreshToken + */ + public function testGetRefreshTokenSet() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken', array('foo', 'bar')); + + $this->assertSame('bar', $token->getRefreshToken()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::getRefreshToken + * @covers OAuth\Common\Token\AbstractToken::setRefreshToken + */ + public function testSetRefreshToken() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken'); + + $token->setRefreshToken('foo'); + + $this->assertSame('foo', $token->getRefreshToken()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::getExtraParams + */ + public function testGetExtraParamsNotSet() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken'); + + $this->assertSame(array(), $token->getExtraParams()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::getExtraParams + */ + public function testGetExtraParamsSet() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken', array('foo', 'bar', null, array('foo', 'bar'))); + + $this->assertEquals(array('foo', 'bar'), $token->getExtraParams()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::setExtraParams + * @covers OAuth\Common\Token\AbstractToken::getExtraParams + */ + public function testSetExtraParams() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken'); + + $token->setExtraParams(array('foo', 'bar')); + + $this->assertSame(array('foo', 'bar'), $token->getExtraParams()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::setLifetime + * @covers OAuth\Common\Token\AbstractToken::getEndOfLife + */ + public function testGetEndOfLifeNotSet() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken'); + + $this->assertSame(AbstractToken::EOL_UNKNOWN, $token->getEndOfLife()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::setLifetime + * @covers OAuth\Common\Token\AbstractToken::getEndOfLife + */ + public function testGetEndOfLifeZero() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken', array('foo', 'bar', 0)); + + $this->assertSame(AbstractToken::EOL_NEVER_EXPIRES, $token->getEndOfLife()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::setLifetime + * @covers OAuth\Common\Token\AbstractToken::getEndOfLife + */ + public function testGetEndOfLifeNeverExpires() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken', array('foo', 'bar', AbstractToken::EOL_NEVER_EXPIRES)); + + $this->assertSame(AbstractToken::EOL_NEVER_EXPIRES, $token->getEndOfLife()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::setLifetime + * @covers OAuth\Common\Token\AbstractToken::getEndOfLife + */ + public function testGetEndOfLifeNeverExpiresFiveMinutes() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken', array('foo', 'bar', 5 * 60)); + + $this->assertSame(time() + (5*60), $token->getEndOfLife()); + } + + /** + * @covers OAuth\Common\Token\AbstractToken::__construct + * @covers OAuth\Common\Token\AbstractToken::setLifetime + * @covers OAuth\Common\Token\AbstractToken::getEndOfLife + * @covers OAuth\Common\Token\AbstractToken::setEndOfLife + */ + public function testSetEndOfLife() + { + $token = $this->getMockForAbstractClass('\\OAuth\\Common\\Token\\AbstractToken'); + + $token->setEndOfLife(10); + + $this->assertSame(10, $token->getEndOfLife()); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/AbstractServiceTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/AbstractServiceTest.php new file mode 100644 index 00000000..ab5417b2 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/AbstractServiceTest.php @@ -0,0 +1,215 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Service; + +use OAuthTest\Mocks\OAuth1\Service\Mock; + +class AbstractServiceTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth1\Service\AbstractService::__construct + */ + public function testConstructCorrectInterface() + { + $service = $this->getMockForAbstractClass( + '\\OAuth\\OAuth1\\Service\\AbstractService', + array( + $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\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth1\Service\AbstractService::__construct + */ + public function testConstructCorrectParent() + { + $service = $this->getMockForAbstractClass( + '\\OAuth\\OAuth1\\Service\\AbstractService', + array( + $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\\Common\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth1\Service\AbstractService::requestRequestToken + * @covers OAuth\OAuth1\Service\AbstractService::buildAuthorizationHeaderForTokenRequest + * @covers OAuth\OAuth1\Service\AbstractService::getBasicAuthorizationHeaderInfo + * @covers OAuth\OAuth1\Service\AbstractService::generateNonce + * @covers OAuth\OAuth1\Service\AbstractService::getSignatureMethod + * @covers OAuth\OAuth1\Service\AbstractService::getVersion + * @covers OAuth\OAuth1\Service\AbstractService::getExtraOAuthHeaders + * @covers OAuth\OAuth1\Service\AbstractService::parseRequestTokenResponse + */ + public function testRequestRequestTokenBuildAuthHeaderTokenRequestWithoutParams() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnCallback(function($endpoint, $array, $headers) { + \PHPUnit_Framework_Assert::assertSame('http://pieterhordijk.com/token', $endpoint->getAbsoluteUri()); + })); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestRequestToken()); + } + + /** + * @covers OAuth\OAuth1\Service\AbstractService::getAuthorizationUri + * @covers OAuth\OAuth1\Service\AbstractService::getAuthorizationEndpoint + */ + public function testGetAuthorizationUriWithoutParameters() + { + $service = new Mock( + $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->assertSame('http://pieterhordijk.com/auth', $service->getAuthorizationUri()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth1\Service\AbstractService::getAuthorizationUri + * @covers OAuth\OAuth1\Service\AbstractService::getAuthorizationEndpoint + */ + public function testGetAuthorizationUriWithParameters() + { + $service = new Mock( + $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->assertSame('http://pieterhordijk.com/auth?foo=bar&baz=beer', $service->getAuthorizationUri(array( + 'foo' => 'bar', + 'baz' => 'beer', + ))->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth1\Service\AbstractService::requestAccessToken + * @covers OAuth\OAuth1\Service\AbstractService::service + * @covers OAuth\OAuth1\Service\AbstractService::buildAuthorizationHeaderForAPIRequest + * @covers OAuth\OAuth1\Service\AbstractService::getBasicAuthorizationHeaderInfo + * @covers OAuth\OAuth1\Service\AbstractService::generateNonce + * @covers OAuth\OAuth1\Service\AbstractService::getSignatureMethod + * @covers OAuth\OAuth1\Service\AbstractService::getVersion + * @covers OAuth\OAuth1\Service\AbstractService::getAccessTokenEndpoint + * @covers OAuth\OAuth1\Service\AbstractService::getExtraOAuthHeaders + * @covers OAuth\OAuth1\Service\AbstractService::parseAccessTokenResponse + */ + public function testRequestAccessTokenWithoutSecret() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnCallback(function($endpoint, $array, $headers) { + \PHPUnit_Framework_Assert::assertSame('http://pieterhordijk.com/access', $endpoint->getAbsoluteUri()); + })); + + $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); + $token->expects($this->once())->method('getRequestTokenSecret')->will($this->returnValue('baz')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage, + $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestAccessToken('foo', 'bar')); + } + + /** + * @covers OAuth\OAuth1\Service\AbstractService::requestAccessToken + * @covers OAuth\OAuth1\Service\AbstractService::service + * @covers OAuth\OAuth1\Service\AbstractService::buildAuthorizationHeaderForAPIRequest + * @covers OAuth\OAuth1\Service\AbstractService::getBasicAuthorizationHeaderInfo + * @covers OAuth\OAuth1\Service\AbstractService::generateNonce + * @covers OAuth\OAuth1\Service\AbstractService::getSignatureMethod + * @covers OAuth\OAuth1\Service\AbstractService::getVersion + * @covers OAuth\OAuth1\Service\AbstractService::getAccessTokenEndpoint + * @covers OAuth\OAuth1\Service\AbstractService::getExtraOAuthHeaders + * @covers OAuth\OAuth1\Service\AbstractService::parseAccessTokenResponse + */ + public function testRequestAccessTokenWithSecret() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnCallback(function($endpoint, $array, $headers) { + \PHPUnit_Framework_Assert::assertSame('http://pieterhordijk.com/access', $endpoint->getAbsoluteUri()); + })); + + $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 Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage, + $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestAccessToken('foo', 'bar', $token)); + } + + /** + * @covers OAuth\OAuth1\Service\AbstractService::request + * @covers OAuth\OAuth1\Service\AbstractService::determineRequestUriFromPath + * @covers OAuth\OAuth1\Service\AbstractService::service + * @covers OAuth\OAuth1\Service\AbstractService::getExtraApiHeaders + * @covers OAuth\OAuth1\Service\AbstractService::buildAuthorizationHeaderForAPIRequest + * @covers OAuth\OAuth1\Service\AbstractService::getBasicAuthorizationHeaderInfo + * @covers OAuth\OAuth1\Service\AbstractService::generateNonce + * @covers OAuth\OAuth1\Service\AbstractService::getSignatureMethod + * @covers OAuth\OAuth1\Service\AbstractService::getVersion + */ + public function testRequest() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('response!')); + + $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); + //$token->expects($this->once())->method('getRequestTokenSecret')->will($this->returnValue('baz')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage, + $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertSame('response!', $service->request('/my/awesome/path')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/BitBucketTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/BitBucketTest.php new file mode 100644 index 00000000..87be98b1 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/BitBucketTest.php @@ -0,0 +1,278 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Service; + +use OAuth\OAuth1\Service\BitBucket; + +class BitBucketTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth1\Service\BitBucket::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new BitBucket( + $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\BitBucket::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new BitBucket( + $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\BitBucket::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new BitBucket( + $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\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getRequestTokenEndpoint + */ + public function testGetRequestTokenEndpoint() + { + $service = new BitBucket( + $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://bitbucket.org/!api/1.0/oauth/request_token', + $service->getRequestTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new BitBucket( + $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://bitbucket.org/!api/1.0/oauth/authenticate', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new BitBucket( + $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://bitbucket.org/!api/1.0/oauth/access_token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\BitBucket::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new BitBucket( + $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\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\BitBucket::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('notanarray')); + + $service = new BitBucket( + $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\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\BitBucket::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 BitBucket( + $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\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\BitBucket::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 BitBucket( + $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\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\BitBucket::parseRequestTokenResponse + * @covers OAuth\OAuth1\Service\BitBucket::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 BitBucket( + $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\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\BitBucket::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 BitBucket( + $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\BitBucket::__construct + * @covers OAuth\OAuth1\Service\BitBucket::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\BitBucket::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 BitBucket( + $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)); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/EtsyTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/EtsyTest.php new file mode 100644 index 00000000..97ad3cdd --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/EtsyTest.php @@ -0,0 +1,286 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Service; + +use OAuth\OAuth1\Service\Etsy; + +class EtsyTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth1\Service\Etsy::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Etsy( + $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\Etsy::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Etsy( + $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\Etsy::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Etsy( + $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\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getRequestTokenEndpoint + */ + public function testGetRequestTokenEndpoint() + { + $service = new Etsy( + $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://openapi.etsy.com/v2/oauth/request_token', + $service->getRequestTokenEndpoint()->getAbsoluteUri() + ); + + $service->setScopes(array('email_r', 'cart_rw')); + + $this->assertSame( + 'https://openapi.etsy.com/v2/oauth/request_token?scope=email_r%20cart_rw', + $service->getRequestTokenEndpoint()->getAbsoluteUri() + ); + + } + + /** + * @covers OAuth\OAuth1\Service\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Etsy( + $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://openapi.etsy.com/v2/', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Etsy( + $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://openapi.etsy.com/v2/oauth/access_token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Etsy::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Etsy( + $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\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Etsy::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('notanarray')); + + $service = new Etsy( + $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\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Etsy::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 Etsy( + $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\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Etsy::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 Etsy( + $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\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Etsy::parseRequestTokenResponse + * @covers OAuth\OAuth1\Service\Etsy::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 Etsy( + $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\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Etsy::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 Etsy( + $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\Etsy::__construct + * @covers OAuth\OAuth1\Service\Etsy::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Etsy::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 Etsy( + $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)); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/FitBitTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/FitBitTest.php new file mode 100644 index 00000000..a8b7ae2d --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/FitBitTest.php @@ -0,0 +1,278 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Service; + +use OAuth\OAuth1\Service\FitBit; + +class FitBitTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth1\Service\FitBit::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new FitBit( + $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\FitBit::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new FitBit( + $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\FitBit::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new FitBit( + $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\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getRequestTokenEndpoint + */ + public function testGetRequestTokenEndpoint() + { + $service = new FitBit( + $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.fitbit.com/oauth/request_token', + $service->getRequestTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new FitBit( + $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://www.fitbit.com/oauth/authorize', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new FitBit( + $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.fitbit.com/oauth/access_token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\FitBit::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new FitBit( + $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\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\FitBit::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('notanarray')); + + $service = new FitBit( + $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\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\FitBit::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 FitBit( + $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\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\FitBit::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 FitBit( + $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\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\FitBit::parseRequestTokenResponse + * @covers OAuth\OAuth1\Service\FitBit::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 FitBit( + $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\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\FitBit::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 FitBit( + $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\FitBit::__construct + * @covers OAuth\OAuth1\Service\FitBit::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\FitBit::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 FitBit( + $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)); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/FlickrTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/FlickrTest.php new file mode 100644 index 00000000..ee88f714 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/FlickrTest.php @@ -0,0 +1,302 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Service; + +use OAuth\OAuth1\Service\Flickr; + +class FlickrTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth1\Service\Flickr::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Flickr( + $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\Flickr::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Flickr( + $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\Flickr::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Flickr( + $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\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getRequestTokenEndpoint + */ + public function testGetRequestTokenEndpoint() + { + $service = new Flickr( + $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://www.flickr.com/services/oauth/request_token', + $service->getRequestTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Flickr( + $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://www.flickr.com/services/oauth/authorize', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Flickr( + $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://www.flickr.com/services/oauth/access_token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Flickr::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Flickr( + $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\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Flickr::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('notanarray')); + + $service = new Flickr( + $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\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Flickr::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 Flickr( + $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\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Flickr::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 Flickr( + $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\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Flickr::parseRequestTokenResponse + * @covers OAuth\OAuth1\Service\Flickr::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 Flickr( + $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\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Flickr::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 Flickr( + $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\Flickr::__construct + * @covers OAuth\OAuth1\Service\Flickr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Flickr::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 Flickr( + $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)); + } + + /** + * @covers OAuth\OAuth1\Service\Flickr::request + */ + public function testRequest() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('response!')); + + $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 Flickr( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage, + $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertSame('response!', $service->request('/my/awesome/path')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/ScoopItTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/ScoopItTest.php new file mode 100644 index 00000000..4ba83fa6 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/ScoopItTest.php @@ -0,0 +1,302 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Service; + +use OAuth\OAuth1\Service\ScoopIt; + +class ScoopItTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth1\Service\ScoopIt::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new ScoopIt( + $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\ScoopIt::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new ScoopIt( + $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\ScoopIt::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new ScoopIt( + $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\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getRequestTokenEndpoint + */ + public function testGetRequestTokenEndpoint() + { + $service = new ScoopIt( + $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://www.scoop.it/oauth/request', + $service->getRequestTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new ScoopIt( + $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://www.scoop.it/oauth/authorize', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new ScoopIt( + $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://www.scoop.it/oauth/access', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\ScoopIt::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new ScoopIt( + $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\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\ScoopIt::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('notanarray')); + + $service = new ScoopIt( + $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\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\ScoopIt::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 ScoopIt( + $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\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\ScoopIt::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 ScoopIt( + $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\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\ScoopIt::parseRequestTokenResponse + * @covers OAuth\OAuth1\Service\ScoopIt::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 ScoopIt( + $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\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\ScoopIt::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 ScoopIt( + $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\ScoopIt::__construct + * @covers OAuth\OAuth1\Service\ScoopIt::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\ScoopIt::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 ScoopIt( + $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)); + } + + /** + * @covers OAuth\OAuth1\Service\ScoopIt::request + */ + public function testRequest() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('response!')); + + $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 ScoopIt( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage, + $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertSame('response!', $service->request('/my/awesome/path')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TumblrTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TumblrTest.php new file mode 100644 index 00000000..f1467ad6 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/TumblrTest.php @@ -0,0 +1,278 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Service; + +use OAuth\OAuth1\Service\Tumblr; + +class TumblrTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth1\Service\Tumblr::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Tumblr( + $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\Tumblr::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Tumblr( + $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\Tumblr::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Tumblr( + $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\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getRequestTokenEndpoint + */ + public function testGetRequestTokenEndpoint() + { + $service = new Tumblr( + $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://www.tumblr.com/oauth/request_token', + $service->getRequestTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Tumblr( + $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://www.tumblr.com/oauth/authorize', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Tumblr( + $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://www.tumblr.com/oauth/access_token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Tumblr::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Tumblr( + $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\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Tumblr::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('notanarray')); + + $service = new Tumblr( + $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\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Tumblr::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 Tumblr( + $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\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Tumblr::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 Tumblr( + $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\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Tumblr::parseRequestTokenResponse + * @covers OAuth\OAuth1\Service\Tumblr::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 Tumblr( + $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\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Tumblr::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 Tumblr( + $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\Tumblr::__construct + * @covers OAuth\OAuth1\Service\Tumblr::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Tumblr::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 Tumblr( + $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)); + } +} 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)); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/XingTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/XingTest.php new file mode 100644 index 00000000..d3a5f4ae --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/XingTest.php @@ -0,0 +1,239 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Service; + +use OAuth\OAuth1\Service\Xing; + +class XingTest extends \PHPUnit_Framework_TestCase +{ + private $client; + private $storage; + private $xing; + + + protected function setUp() + { + parent::setUp(); + + $this->client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $this->storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + + $this->xing = new Xing( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->client, + $this->storage, + $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') + ); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $this->assertInstanceOf( + '\\OAuth\\OAuth1\\Service\\ServiceInterface', $this->xing + ); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $this->assertInstanceOf( + '\\OAuth\\OAuth1\\Service\\AbstractService', $this->xing + ); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Xing( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->client, + $this->storage, + $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint + */ + public function testGetRequestTokenEndpoint() + { + $this->assertSame( + 'https://api.xing.com/v1/request_token', + $this->xing->getRequestTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $this->assertSame( + 'https://api.xing.com/v1/authorize', + $this->xing->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $this->assertSame( + 'https://api.xing.com/v1/access_token', + $this->xing->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() + { + $this->client + ->expects($this->once()) + ->method('retrieveResponse') + ->will($this->returnValue(null)); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $this->xing->requestRequestToken(); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() + { + $this->client + ->expects($this->once()) + ->method('retrieveResponse') + ->will($this->returnValue('notanarray')); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $this->xing->requestRequestToken(); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotSet() + { + $this->client + ->expects($this->once()) + ->method('retrieveResponse') + ->will($this->returnValue('foo=bar')); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $this->xing->requestRequestToken(); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotTrue() + { + $this->client + ->expects($this->once()) + ->method('retrieveResponse') + ->will($this->returnValue('oauth_callback_confirmed=false')); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $this->xing->requestRequestToken(); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse + * @covers OAuth\OAuth1\Service\Xing::parseAccessTokenResponse + */ + public function testParseRequestTokenResponseValid() + { + $this->client + ->expects($this->once()) + ->method('retrieveResponse') + ->will($this->returnValue( + 'oauth_callback_confirmed=true&oauth_token=foo&oauth_token_secret=bar' + )); + + $this->assertInstanceOf( + '\\OAuth\\OAuth1\\Token\\StdOAuth1Token', + $this->xing->requestRequestToken() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Xing::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $this->client + ->expects($this->once()) + ->method('retrieveResponse') + ->will($this->returnValue('error=bar')); + + $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); + + $this->storage + ->expects($this->any()) + ->method('retrieveAccessToken') + ->will($this->returnValue($token)); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $this->xing->requestAccessToken('foo', 'bar', $token); + } + + /** + * @covers OAuth\OAuth1\Service\Xing::__construct + * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Xing::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValid() + { + $this->client + ->expects($this->once()) + ->method('retrieveResponse') + ->will($this->returnValue('oauth_token=foo&oauth_token_secret=bar')); + + $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); + + $this->storage + ->expects($this->any()) + ->method('retrieveAccessToken') + ->will($this->returnValue($token)); + + + $this->assertInstanceOf( + '\\OAuth\\OAuth1\\Token\\StdOAuth1Token', + $this->xing->requestAccessToken('foo', 'bar', $token) + ); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/YahooTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/YahooTest.php new file mode 100644 index 00000000..e8feb5dc --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Service/YahooTest.php @@ -0,0 +1,302 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Service; + +use OAuth\OAuth1\Service\Yahoo; + +class YahooTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth1\Service\Yahoo::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Yahoo( + $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\Yahoo::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Yahoo( + $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\Yahoo::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Yahoo( + $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\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint + */ + public function testGetRequestTokenEndpoint() + { + $service = new Yahoo( + $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.login.yahoo.com/oauth/v2/get_request_token', + $service->getRequestTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Yahoo( + $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.login.yahoo.com/oauth/v2/request_auth', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Yahoo( + $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.login.yahoo.com/oauth/v2/get_token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth1\Service\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Yahoo::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Yahoo( + $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\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Yahoo::parseRequestTokenResponse + */ + public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('notanarray')); + + $service = new Yahoo( + $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\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Yahoo::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 Yahoo( + $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\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Yahoo::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 Yahoo( + $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\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Yahoo::parseRequestTokenResponse + * @covers OAuth\OAuth1\Service\Yahoo::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 Yahoo( + $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\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Yahoo::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 Yahoo( + $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\Yahoo::__construct + * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint + * @covers OAuth\OAuth1\Service\Yahoo::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 Yahoo( + $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)); + } + + /** + * @covers OAuth\OAuth1\Service\Yahoo::request + */ + public function testRequest() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('response!')); + + $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 Yahoo( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage, + $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertSame('response!', $service->request('/my/awesome/path')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Signature/SignatureTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Signature/SignatureTest.php new file mode 100644 index 00000000..44c731f5 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Signature/SignatureTest.php @@ -0,0 +1,325 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Signature; + +use OAuth\OAuth1\Signature\Signature; + +class SignatureTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + */ + public function testConstructCorrectInterface() + { + $signature = new Signature($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface')); + + $this->assertInstanceOf('\\OAuth\\OAuth1\\Signature\\SignatureInterface', $signature); + } + + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm + */ + public function testSetHashingAlgorithm() + { + $signature = new Signature($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface')); + + $this->assertNull($signature->setHashingAlgorithm('foo')); + } + + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret + */ + public function testSetTokenSecret() + { + $signature = new Signature($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface')); + + $this->assertNull($signature->setTokenSecret('foo')); + } + + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm + * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret + * @covers OAuth\OAuth1\Signature\Signature::getSignature + * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString + * @covers OAuth\OAuth1\Signature\Signature::hash + * @covers OAuth\OAuth1\Signature\Signature::getSigningKey + */ + public function testGetSignatureBareUri() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->any()) + ->method('getConsumerSecret') + ->will($this->returnValue('foo')); + + + $signature = new Signature($credentials); + + $signature->setHashingAlgorithm('HMAC-SHA1'); + $signature->setTokenSecret('foo'); + + $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $uri->expects($this->any()) + ->method('getQuery') + ->will($this->returnValue('')); + $uri->expects($this->any()) + ->method('getScheme') + ->will($this->returnValue('http')); + $uri->expects($this->any()) + ->method('getRawAuthority') + ->will($this->returnValue('')); + $uri->expects($this->any()) + ->method('getPath') + ->will($this->returnValue('/foo')); + + $this->assertSame('uoCpiII/Lg/cPiF0XrU2pj4eGFQ=', $signature->getSignature($uri, array('pee' => 'haa'))); + } + + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm + * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret + * @covers OAuth\OAuth1\Signature\Signature::getSignature + * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString + * @covers OAuth\OAuth1\Signature\Signature::hash + * @covers OAuth\OAuth1\Signature\Signature::getSigningKey + */ + public function testGetSignatureWithQueryString() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->any()) + ->method('getConsumerSecret') + ->will($this->returnValue('foo')); + + + $signature = new Signature($credentials); + + $signature->setHashingAlgorithm('HMAC-SHA1'); + $signature->setTokenSecret('foo'); + + $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $uri->expects($this->any()) + ->method('getQuery') + ->will($this->returnValue('param1=value1')); + $uri->expects($this->any()) + ->method('getScheme') + ->will($this->returnValue('http')); + $uri->expects($this->any()) + ->method('getRawAuthority') + ->will($this->returnValue('')); + $uri->expects($this->any()) + ->method('getPath') + ->will($this->returnValue('/foo')); + + $this->assertSame('LxtD+WjJBRppIUvEI79iQ7I0hSo=', $signature->getSignature($uri, array('pee' => 'haa'))); + } + + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm + * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret + * @covers OAuth\OAuth1\Signature\Signature::getSignature + * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString + * @covers OAuth\OAuth1\Signature\Signature::hash + * @covers OAuth\OAuth1\Signature\Signature::getSigningKey + */ + public function testGetSignatureWithAuthority() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->any()) + ->method('getConsumerSecret') + ->will($this->returnValue('foo')); + + + $signature = new Signature($credentials); + + $signature->setHashingAlgorithm('HMAC-SHA1'); + $signature->setTokenSecret('foo'); + + $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $uri->expects($this->any()) + ->method('getQuery') + ->will($this->returnValue('param1=value1')); + $uri->expects($this->any()) + ->method('getScheme') + ->will($this->returnValue('http')); + $uri->expects($this->any()) + ->method('getRawAuthority') + ->will($this->returnValue('peehaa:pass')); + $uri->expects($this->any()) + ->method('getPath') + ->will($this->returnValue('/foo')); + + $this->assertSame('MHvkRndIntLrxiPkjkiCNsMEqv4=', $signature->getSignature($uri, array('pee' => 'haa'))); + } + + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm + * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret + * @covers OAuth\OAuth1\Signature\Signature::getSignature + * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString + * @covers OAuth\OAuth1\Signature\Signature::hash + * @covers OAuth\OAuth1\Signature\Signature::getSigningKey + */ + public function testGetSignatureWithBarePathNonExplicitTrailingHostSlash() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->any()) + ->method('getConsumerSecret') + ->will($this->returnValue('foo')); + + + $signature = new Signature($credentials); + + $signature->setHashingAlgorithm('HMAC-SHA1'); + $signature->setTokenSecret('foo'); + + $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $uri->expects($this->any()) + ->method('getQuery') + ->will($this->returnValue('param1=value1')); + $uri->expects($this->any()) + ->method('getScheme') + ->will($this->returnValue('http')); + $uri->expects($this->any()) + ->method('getRawAuthority') + ->will($this->returnValue('peehaa:pass')); + $uri->expects($this->any()) + ->method('getPath') + ->will($this->returnValue('/')); + $uri->expects($this->any()) + ->method('hasExplicitTrailingHostSlash') + ->will($this->returnValue(false)); + + $this->assertSame('iFELDoiI5Oj9ixB3kHzoPvBpq0w=', $signature->getSignature($uri, array('pee' => 'haa'))); + } + + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm + * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret + * @covers OAuth\OAuth1\Signature\Signature::getSignature + * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString + * @covers OAuth\OAuth1\Signature\Signature::hash + * @covers OAuth\OAuth1\Signature\Signature::getSigningKey + */ + public function testGetSignatureWithBarePathWithExplicitTrailingHostSlash() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->any()) + ->method('getConsumerSecret') + ->will($this->returnValue('foo')); + + + $signature = new Signature($credentials); + + $signature->setHashingAlgorithm('HMAC-SHA1'); + $signature->setTokenSecret('foo'); + + $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $uri->expects($this->any()) + ->method('getQuery') + ->will($this->returnValue('param1=value1')); + $uri->expects($this->any()) + ->method('getScheme') + ->will($this->returnValue('http')); + $uri->expects($this->any()) + ->method('getRawAuthority') + ->will($this->returnValue('peehaa:pass')); + $uri->expects($this->any()) + ->method('getPath') + ->will($this->returnValue('/')); + $uri->expects($this->any()) + ->method('hasExplicitTrailingHostSlash') + ->will($this->returnValue(true)); + + $this->assertSame('IEhUsArSTLvbQ3QYr0zzn+Rxpjg=', $signature->getSignature($uri, array('pee' => 'haa'))); + } + + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm + * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret + * @covers OAuth\OAuth1\Signature\Signature::getSignature + * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString + * @covers OAuth\OAuth1\Signature\Signature::hash + * @covers OAuth\OAuth1\Signature\Signature::getSigningKey + */ + public function testGetSignatureNoTokenSecretSet() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->any()) + ->method('getConsumerSecret') + ->will($this->returnValue('foo')); + + + $signature = new Signature($credentials); + + $signature->setHashingAlgorithm('HMAC-SHA1'); + + $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $uri->expects($this->any()) + ->method('getQuery') + ->will($this->returnValue('param1=value1')); + $uri->expects($this->any()) + ->method('getScheme') + ->will($this->returnValue('http')); + $uri->expects($this->any()) + ->method('getRawAuthority') + ->will($this->returnValue('peehaa:pass')); + $uri->expects($this->any()) + ->method('getPath') + ->will($this->returnValue('/')); + $uri->expects($this->any()) + ->method('hasExplicitTrailingHostSlash') + ->will($this->returnValue(true)); + + $this->assertSame('YMHF7FYmLq7wzGnnHWYtd1VoBBE=', $signature->getSignature($uri, array('pee' => 'haa'))); + } + + /** + * @covers OAuth\OAuth1\Signature\Signature::__construct + * @covers OAuth\OAuth1\Signature\Signature::setHashingAlgorithm + * @covers OAuth\OAuth1\Signature\Signature::setTokenSecret + * @covers OAuth\OAuth1\Signature\Signature::getSignature + * @covers OAuth\OAuth1\Signature\Signature::buildSignatureDataString + * @covers OAuth\OAuth1\Signature\Signature::hash + * @covers OAuth\OAuth1\Signature\Signature::getSigningKey + */ + public function testGetSignatureThrowsExceptionOnUnsupportedAlgo() + { + $this->setExpectedException('\\OAuth\\OAuth1\\Signature\\Exception\\UnsupportedHashAlgorithmException'); + + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->any()) + ->method('getConsumerSecret') + ->will($this->returnValue('foo')); + + + $signature = new Signature($credentials); + + $signature->setHashingAlgorithm('UnsupportedAlgo'); + + $uri = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'); + $uri->expects($this->any()) + ->method('getQuery') + ->will($this->returnValue('param1=value1')); + $uri->expects($this->any()) + ->method('getScheme') + ->will($this->returnValue('http')); + $uri->expects($this->any()) + ->method('getRawAuthority') + ->will($this->returnValue('peehaa:pass')); + $uri->expects($this->any()) + ->method('getPath') + ->will($this->returnValue('/')); + $uri->expects($this->any()) + ->method('hasExplicitTrailingHostSlash') + ->will($this->returnValue(true)); + + $signature->getSignature($uri, array('pee' => 'haa')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth1/Token/StdOAuth1TokenTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Token/StdOAuth1TokenTest.php new file mode 100644 index 00000000..9b065b1e --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth1/Token/StdOAuth1TokenTest.php @@ -0,0 +1,85 @@ +<?php + +namespace OAuthTest\Unit\OAuth1\Token; + +use OAuth\OAuth1\Token\StdOAuth1Token; + +class StdOAuth1TokenTest extends \PHPUnit_Framework_TestCase +{ + /** + * + */ + public function testConstructCorrectInterfaces() + { + $token = new StdOAuth1Token(); + + $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\TokenInterface', $token); + $this->assertInstanceOf('\\OAuth\\Common\\Token\\AbstractToken', $token); + } + + /** + * @covers OAuth\OAuth1\Token\StdOAuth1Token::setRequestToken + */ + public function testSetRequestToken() + { + $token = new StdOAuth1Token(); + + $this->assertNull($token->setRequestToken('foo')); + } + + /** + * @covers OAuth\OAuth1\Token\StdOAuth1Token::setRequestToken + * @covers OAuth\OAuth1\Token\StdOAuth1Token::getRequestToken + */ + public function testGetRequestToken() + { + $token = new StdOAuth1Token(); + + $this->assertNull($token->setRequestToken('foo')); + $this->assertSame('foo', $token->getRequestToken()); + } + + /** + * @covers OAuth\OAuth1\Token\StdOAuth1Token::setRequestTokenSecret + */ + public function testSetRequestTokenSecret() + { + $token = new StdOAuth1Token(); + + $this->assertNull($token->setRequestTokenSecret('foo')); + } + + /** + * @covers OAuth\OAuth1\Token\StdOAuth1Token::setRequestTokenSecret + * @covers OAuth\OAuth1\Token\StdOAuth1Token::getRequestTokenSecret + */ + public function testGetRequestTokenSecret() + { + $token = new StdOAuth1Token(); + + $this->assertNull($token->setRequestTokenSecret('foo')); + $this->assertSame('foo', $token->getRequestTokenSecret()); + } + + /** + * @covers OAuth\OAuth1\Token\StdOAuth1Token::setAccessTokenSecret + */ + public function testSetAccessTokenSecret() + { + $token = new StdOAuth1Token(); + + $this->assertNull($token->setAccessTokenSecret('foo')); + } + + /** + * @covers OAuth\OAuth1\Token\StdOAuth1Token::setAccessTokenSecret + * @covers OAuth\OAuth1\Token\StdOAuth1Token::getAccessTokenSecret + */ + public function testGetAccessTokenSecret() + { + $token = new StdOAuth1Token(); + + $this->assertNull($token->setAccessTokenSecret('foo')); + $this->assertSame('foo', $token->getAccessTokenSecret()); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/AbstractServiceTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/AbstractServiceTest.php new file mode 100644 index 00000000..595db2a3 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/AbstractServiceTest.php @@ -0,0 +1,401 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuthTest\Mocks\OAuth2\Service\Mock; +use OAuth\Common\Http\Uri\Uri; +use OAuth\Common\Token\TokenInterface; + +class AbstractServiceTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + */ + public function testConstructCorrectInterface() + { + $service = $this->getMockForAbstractClass( + '\\OAuth\\OAuth2\\Service\\AbstractService', + array( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + ) + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + */ + public function testConstructCorrectParent() + { + $service = $this->getMockForAbstractClass( + '\\OAuth\\OAuth2\\Service\\AbstractService', + array( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + ) + ); + + $this->assertInstanceOf('\\OAuth\\Common\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + */ + public function testConstructCorrectParentCustomUri() + { + $service = $this->getMockForAbstractClass( + '\\OAuth\\OAuth2\\Service\\AbstractService', + array( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'), + ) + ); + + $this->assertInstanceOf('\\OAuth\\Common\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::isValidScope + */ + public function testConstructThrowsExceptionOnInvalidScope() + { + $this->setExpectedException('\\OAuth\\OAuth2\\Service\\Exception\\InvalidScopeException'); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array('invalidscope') + ); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationUri + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationEndpoint + */ + public function testGetAuthorizationUriWithoutParametersOrScopes() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->once())->method('getConsumerId')->will($this->returnValue('foo')); + $credentials->expects($this->once())->method('getCallbackUrl')->will($this->returnValue('bar')); + + $service = new Mock( + $credentials, + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'http://pieterhordijk.com/auth?type=web_server&client_id=foo&redirect_uri=bar&response_type=code&scope=', + $service->getAuthorizationUri()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationUri + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationEndpoint + */ + public function testGetAuthorizationUriWithParametersWithoutScopes() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->once())->method('getConsumerId')->will($this->returnValue('foo')); + $credentials->expects($this->once())->method('getCallbackUrl')->will($this->returnValue('bar')); + + $service = new Mock( + $credentials, + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'http://pieterhordijk.com/auth?foo=bar&baz=beer&type=web_server&client_id=foo&redirect_uri=bar&response_type=code&scope=', + $service->getAuthorizationUri(array('foo' => 'bar', 'baz' => 'beer'))->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::isValidScope + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationUri + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationEndpoint + */ + public function testGetAuthorizationUriWithParametersAndScopes() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->once())->method('getConsumerId')->will($this->returnValue('foo')); + $credentials->expects($this->once())->method('getCallbackUrl')->will($this->returnValue('bar')); + + $service = new Mock( + $credentials, + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array('mock', 'mock2') + ); + + $this->assertSame( + 'http://pieterhordijk.com/auth?foo=bar&baz=beer&type=web_server&client_id=foo&redirect_uri=bar&response_type=code&scope=mock+mock2', + $service->getAuthorizationUri(array('foo' => 'bar', 'baz' => 'beer'))->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::requestAccessToken + * @covers OAuth\OAuth2\Service\AbstractService::getAccessTokenEndpoint + * @covers OAuth\OAuth2\Service\AbstractService::getExtraOAuthHeaders + * @covers OAuth\OAuth2\Service\AbstractService::parseAccessTokenResponse + * @covers OAuth\OAuth2\Service\AbstractService::service + */ + public function testRequestAccessToken() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceof('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('code')); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::request + * @covers OAuth\OAuth2\Service\AbstractService::determineRequestUriFromPath + */ + public function testRequestThrowsExceptionWhenTokenIsExpired() + { + $tokenExpiration = new \DateTime('26-03-1984 00:00:00'); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->any())->method('getEndOfLife')->will($this->returnValue($tokenExpiration->format('U'))); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $storage + ); + + $this->setExpectedException('\\OAuth\\Common\\Token\\Exception\\ExpiredTokenException', 'Token expired on 03/26/1984 at 12:00:00 AM'); + + $service->request('https://pieterhordijk.com/my/awesome/path'); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::request + * @covers OAuth\OAuth2\Service\AbstractService::determineRequestUriFromPath + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationMethod + * @covers OAuth\OAuth2\Service\AbstractService::parseAccessTokenResponse + * @covers OAuth\OAuth2\Service\AbstractService::service + * @covers OAuth\OAuth2\Service\AbstractService::getExtraApiHeaders + */ + public function testRequestOauthAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('OAuth foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::request + * @covers OAuth\OAuth2\Service\AbstractService::determineRequestUriFromPath + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationMethod + * @covers OAuth\OAuth2\Service\AbstractService::parseAccessTokenResponse + * @covers OAuth\OAuth2\Service\AbstractService::service + * @covers OAuth\OAuth2\Service\AbstractService::getExtraApiHeaders + */ + public function testRequestQueryStringMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $service->setAuthorizationMethod('querystring'); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('access_token=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::request + * @covers OAuth\OAuth2\Service\AbstractService::determineRequestUriFromPath + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationMethod + * @covers OAuth\OAuth2\Service\AbstractService::parseAccessTokenResponse + * @covers OAuth\OAuth2\Service\AbstractService::service + * @covers OAuth\OAuth2\Service\AbstractService::getExtraApiHeaders + */ + public function testRequestQueryStringTwoMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $service->setAuthorizationMethod('querystring2'); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('oauth2_access_token=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::request + * @covers OAuth\OAuth2\Service\AbstractService::determineRequestUriFromPath + * @covers OAuth\OAuth2\Service\AbstractService::getAuthorizationMethod + * @covers OAuth\OAuth2\Service\AbstractService::parseAccessTokenResponse + * @covers OAuth\OAuth2\Service\AbstractService::service + * @covers OAuth\OAuth2\Service\AbstractService::getExtraApiHeaders + */ + public function testRequestBearerMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $service->setAuthorizationMethod('bearer'); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('Bearer foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::getStorage + */ + public function testGetStorage() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $service->getStorage()); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::refreshAccessToken + * @covers OAuth\OAuth2\Service\AbstractService::getAccessTokenEndpoint + * @covers OAuth\OAuth2\Service\AbstractService::getExtraOAuthHeaders + * @covers OAuth\OAuth2\Service\AbstractService::parseAccessTokenResponse + */ + public function testRefreshAccessTokenSuccess() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\StdOAuth2Token'); + $token->expects($this->once())->method('getRefreshToken')->will($this->returnValue('foo')); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->refreshAccessToken($token)); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::isValidScope + */ + public function testIsValidScopeTrue() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertTrue($service->isValidScope('mock')); + } + + /** + * @covers OAuth\OAuth2\Service\AbstractService::__construct + * @covers OAuth\OAuth2\Service\AbstractService::isValidScope + */ + public function testIsValidScopeFalse() + { + $service = new Mock( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertFalse($service->isValidScope('invalid')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/AmazonTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/AmazonTest.php new file mode 100644 index 00000000..f70fe401 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/AmazonTest.php @@ -0,0 +1,207 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Amazon; +use OAuth\Common\Token\TokenInterface; + +class AmazonTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + * @covers OAuth\OAuth2\Service\Amazon::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://www.amazon.com/ap/oa', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + * @covers OAuth\OAuth2\Service\Amazon::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://www.amazon.com/ap/oatoken', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + * @covers OAuth\OAuth2\Service\Amazon::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('Bearer foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + * @covers OAuth\OAuth2\Service\Amazon::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + * @covers OAuth\OAuth2\Service\Amazon::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnErrorDescription() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error_description=some_error')); + + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + * @covers OAuth\OAuth2\Service\Amazon::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + * @covers OAuth\OAuth2\Service\Amazon::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Amazon::__construct + * @covers OAuth\OAuth2\Service\Amazon::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Amazon( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/BitlyTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/BitlyTest.php new file mode 100644 index 00000000..9944b260 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/BitlyTest.php @@ -0,0 +1,150 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Bitly; +use OAuth\Common\Token\TokenInterface; + +class BitlyTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Bitly::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Bitly( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Bitly::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Bitly( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Bitly::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Bitly( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Bitly::__construct + * @covers OAuth\OAuth2\Service\Bitly::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Bitly( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://bitly.com/oauth/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Bitly::__construct + * @covers OAuth\OAuth2\Service\Bitly::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Bitly( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://api-ssl.bitly.com/oauth/access_token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Bitly::__construct + * @covers OAuth\OAuth2\Service\Bitly::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Bitly( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('access_token=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\Bitly::__construct + * @covers OAuth\OAuth2\Service\Bitly::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Bitly( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Bitly::__construct + * @covers OAuth\OAuth2\Service\Bitly::parseAccessTokenResponse + * @covers OAuth\OAuth2\Service\Bitly::requestAccessToken + */ + public function testParseAccessTokenResponseValid() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('access_token=foo')); + + $service = new Bitly( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/BoxTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/BoxTest.php new file mode 100644 index 00000000..b5b2a789 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/BoxTest.php @@ -0,0 +1,207 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Box; +use OAuth\Common\Token\TokenInterface; + +class BoxTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Box::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + * @covers OAuth\OAuth2\Service\Box::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://www.box.com/api/oauth2/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + * @covers OAuth\OAuth2\Service\Box::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://www.box.com/api/oauth2/token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + * @covers OAuth\OAuth2\Service\Box::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('Bearer foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + * @covers OAuth\OAuth2\Service\Box::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + * @covers OAuth\OAuth2\Service\Box::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnErrorDescription() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error_description=some_error')); + + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + * @covers OAuth\OAuth2\Service\Box::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + * @covers OAuth\OAuth2\Service\Box::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Box::__construct + * @covers OAuth\OAuth2\Service\Box::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Box( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/BufferTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/BufferTest.php new file mode 100644 index 00000000..29726d0a --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/BufferTest.php @@ -0,0 +1,150 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Buffer; +use OAuth\Common\Token\TokenInterface; + +class BufferTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Buffer::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Buffer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Buffer::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Buffer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Buffer::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Buffer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Buffer::__construct + * @covers OAuth\OAuth2\Service\Buffer::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Buffer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://bufferapp.com/oauth2/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Buffer::__construct + * @covers OAuth\OAuth2\Service\Buffer::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Buffer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://api.bufferapp.com/1/oauth2/token.json', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Buffer::__construct + * @covers OAuth\OAuth2\Service\Buffer::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Buffer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('access_token=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\Buffer::__construct + * @covers OAuth\OAuth2\Service\Buffer::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Buffer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Buffer::__construct + * @covers OAuth\OAuth2\Service\Buffer::parseAccessTokenResponse + * @covers OAuth\OAuth2\Service\Buffer::requestAccessToken + */ + public function testParseAccessTokenResponseValid() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo"}')); + + $service = new Buffer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +}
\ No newline at end of file diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/DailymotionTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/DailymotionTest.php new file mode 100644 index 00000000..f3fbaa8e --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/DailymotionTest.php @@ -0,0 +1,230 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Dailymotion; +use OAuth\Common\Token\TokenInterface; + +class DailymotionTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + * @covers OAuth\OAuth2\Service\Dailymotion::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://api.dailymotion.com/oauth/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + * @covers OAuth\OAuth2\Service\Dailymotion::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://api.dailymotion.com/oauth/token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + * @covers OAuth\OAuth2\Service\Dailymotion::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('OAuth foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + * @covers OAuth\OAuth2\Service\Dailymotion::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + * @covers OAuth\OAuth2\Service\Dailymotion::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnErrorDescription() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error_description=some_error')); + + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + * @covers OAuth\OAuth2\Service\Dailymotion::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + * @covers OAuth\OAuth2\Service\Dailymotion::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + * @covers OAuth\OAuth2\Service\Dailymotion::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Dailymotion::__construct + * @covers OAuth\OAuth2\Service\Dailymotion::getExtraOAuthHeaders + */ + public function testGetExtraOAuthHeaders() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnCallback(function($uri, $params, $extraHeaders) { + \PHPUnit_Framework_Assert::assertTrue(array_key_exists('Accept', $extraHeaders)); + \PHPUnit_Framework_Assert::assertTrue(in_array('application/json', $extraHeaders, true)); + + return '{"access_token":"foo","expires_in":"bar"}'; + })); + + $service = new Dailymotion( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/DropboxTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/DropboxTest.php new file mode 100644 index 00000000..8f052c6b --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/DropboxTest.php @@ -0,0 +1,231 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Dropbox; +use OAuth\Common\Token\TokenInterface; + +class DropboxTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + * @covers OAuth\OAuth2\Service\Dropbox::getAuthorizationUri + */ + public function testGetAuthorizationUriWithoutAdditionalParams() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->once())->method('getConsumerId')->will($this->returnValue('foo')); + $credentials->expects($this->once())->method('getCallbackUrl')->will($this->returnValue('bar')); + + $service = new Dropbox( + $credentials, + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://www.dropbox.com/1/oauth2/authorize?client_id=foo&redirect_uri=bar&response_type=code&scope=', + $service->getAuthorizationUri()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + * @covers OAuth\OAuth2\Service\Dropbox::getAuthorizationUri + */ + public function testGetAuthorizationUriWithAdditionalParams() + { + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->once())->method('getConsumerId')->will($this->returnValue('foo')); + $credentials->expects($this->once())->method('getCallbackUrl')->will($this->returnValue('bar')); + + $service = new Dropbox( + $credentials, + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://www.dropbox.com/1/oauth2/authorize?client_id=foo&redirect_uri=bar&response_type=code&scope=', + $service->getAuthorizationUri()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + * @covers OAuth\OAuth2\Service\Dropbox::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://www.dropbox.com/1/oauth2/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + * @covers OAuth\OAuth2\Service\Dropbox::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://api.dropbox.com/1/oauth2/token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + * @covers OAuth\OAuth2\Service\Dropbox::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('access_token=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + * @covers OAuth\OAuth2\Service\Dropbox::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + * @covers OAuth\OAuth2\Service\Dropbox::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + * @covers OAuth\OAuth2\Service\Dropbox::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Dropbox::__construct + * @covers OAuth\OAuth2\Service\Dropbox::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Dropbox( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/FacebookTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/FacebookTest.php new file mode 100644 index 00000000..f2fed463 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/FacebookTest.php @@ -0,0 +1,242 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Facebook; +use OAuth\Common\Token\TokenInterface; + +class FacebookTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + * @covers OAuth\OAuth2\Service\Facebook::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://www.facebook.com/dialog/oauth', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + * @covers OAuth\OAuth2\Service\Facebook::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://graph.facebook.com/oauth/access_token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('OAuth foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + * @covers OAuth\OAuth2\Service\Facebook::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + * @covers OAuth\OAuth2\Service\Facebook::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('access_token=foo&expires=bar')); + + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + * @covers OAuth\OAuth2\Service\Facebook::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('access_token=foo&expires=bar&refresh_token=baz')); + + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + * @covers OAuth\OAuth2\Service\Facebook::getDialogUri + */ + public function testGetDialogUriRedirectUriMissing() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Exception\\Exception'); + + $service->getDialogUri('feed', array()); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + * @covers OAuth\OAuth2\Service\Facebook::getDialogUri + */ + public function testGetDialogUriInstanceofUri() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + + $service = new Facebook( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $dialogUri = $service->getDialogUri( + 'feed', + array( + 'redirect_uri' => 'http://www.facebook.com', + 'state' => 'Random state' + ) + ); + $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\Uri',$dialogUri); + } + + /** + * @covers OAuth\OAuth2\Service\Facebook::__construct + * @covers OAuth\OAuth2\Service\Facebook::getDialogUri + */ + public function testGetDialogUriContainsAppIdAndOtherParameters() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); + $credentials->expects($this->any())->method('getConsumerId')->will($this->returnValue('application_id')); + + + $service = new Facebook( + $credentials, + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $dialogUri = $service->getDialogUri( + 'feed', + array( + 'redirect_uri' => 'http://www.facebook.com', + 'state' => 'Random state' + ) + ); + + $queryString = $dialogUri->getQuery(); + parse_str($queryString, $queryArray); + + $this->assertArrayHasKey('app_id', $queryArray); + $this->assertArrayHasKey('redirect_uri', $queryArray); + $this->assertArrayHasKey('state', $queryArray); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/FoursquareTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/FoursquareTest.php new file mode 100644 index 00000000..96356ec5 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/FoursquareTest.php @@ -0,0 +1,197 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Foursquare; +use OAuth\Common\Token\TokenInterface; + +class FoursquareTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + * @covers OAuth\OAuth2\Service\Foursquare::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://foursquare.com/oauth2/authenticate', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + * @covers OAuth\OAuth2\Service\Foursquare::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://foursquare.com/oauth2/access_token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + * @covers OAuth\OAuth2\Service\Foursquare::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('OAuth foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + * @covers OAuth\OAuth2\Service\Foursquare::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + * @covers OAuth\OAuth2\Service\Foursquare::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"error":"some_error"}')); + + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + * @covers OAuth\OAuth2\Service\Foursquare::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Foursquare::__construct + * @covers OAuth\OAuth2\Service\Foursquare::request + */ + public function testRequest() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Foursquare( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $this->assertSame( + 'https://api.foursquare.com/v2/https://pieterhordijk.com/my/awesome/path?v=20130829', + $service->request('https://pieterhordijk.com/my/awesome/path')->getAbsoluteUri() + ); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/GitHubTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/GitHubTest.php new file mode 100644 index 00000000..edb0fee3 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/GitHubTest.php @@ -0,0 +1,220 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\GitHub; +use OAuth\Common\Token\TokenInterface; + +class GitHubTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + * @covers OAuth\OAuth2\Service\GitHub::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://github.com/login/oauth/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + * @covers OAuth\OAuth2\Service\GitHub::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://github.com/login/oauth/access_token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + * @covers OAuth\OAuth2\Service\GitHub::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('access_token=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + * @covers OAuth\OAuth2\Service\GitHub::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + * @covers OAuth\OAuth2\Service\GitHub::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"error":"some_error"}')); + + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + * @covers OAuth\OAuth2\Service\GitHub::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + * @covers OAuth\OAuth2\Service\GitHub::getExtraOAuthHeaders + */ + public function testGetExtraOAuthHeaders() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnCallback(function($uri, $params, $extraHeaders) { + \PHPUnit_Framework_Assert::assertTrue(array_key_exists('Accept', $extraHeaders)); + \PHPUnit_Framework_Assert::assertTrue(in_array('application/json', $extraHeaders, true)); + + return '{"access_token":"foo","expires_in":"bar"}'; + })); + + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\GitHub::__construct + * @covers OAuth\OAuth2\Service\GitHub::getExtraApiHeaders + */ + public function testGetExtraApiHeaders() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new GitHub( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Accept', $headers)); + $this->assertSame('application/vnd.github.beta+json', $headers['Accept']); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/GoogleTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/GoogleTest.php new file mode 100644 index 00000000..b55808d2 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/GoogleTest.php @@ -0,0 +1,195 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Google; +use OAuth\Common\Token\TokenInterface; + +class GoogleTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Google::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Google::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Google::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Google::__construct + * @covers OAuth\OAuth2\Service\Google::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://accounts.google.com/o/oauth2/auth?access_type=online', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + + // Verify that 'offine' works + $service->setAccessType('offline'); + $this->assertSame( + 'https://accounts.google.com/o/oauth2/auth?access_type=offline', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + + } + + /** + * @covers OAuth\OAuth2\Service\Google::__construct + * @covers OAuth\OAuth2\Service\Google::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpointException() + { + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('OAuth\OAuth2\Service\Exception\InvalidAccessTypeException'); + + try { + $service->setAccessType('invalid'); + } catch (InvalidAccessTypeException $e) { + return; + } + $this->fail('Expected InvalidAccessTypeException not thrown'); + } + + /** + * @covers OAuth\OAuth2\Service\Google::__construct + * @covers OAuth\OAuth2\Service\Google::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://accounts.google.com/o/oauth2/token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Google::__construct + * @covers OAuth\OAuth2\Service\Google::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Google::__construct + * @covers OAuth\OAuth2\Service\Google::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Google::__construct + * @covers OAuth\OAuth2\Service\Google::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Google::__construct + * @covers OAuth\OAuth2\Service\Google::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Google( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/HerokuTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/HerokuTest.php new file mode 100644 index 00000000..cc2c0f69 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/HerokuTest.php @@ -0,0 +1,261 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Heroku; +use OAuth\Common\Token\TokenInterface; + +class HerokuTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://id.heroku.com/oauth/authorize', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://id.heroku.com/oauth/token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('Bearer foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnErrorDescription() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error_description=some_error')); + + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::getExtraOAuthHeaders + */ + public function testGetExtraOAuthHeaders() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnCallback(function($uri, $params, $extraHeaders) { + \PHPUnit_Framework_Assert::assertTrue(array_key_exists('Accept', $extraHeaders)); + \PHPUnit_Framework_Assert::assertTrue(in_array('application/vnd.heroku+json; version=3', $extraHeaders, true)); + + return '{"access_token":"foo","expires_in":"bar"}'; + })); + + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Heroku::__construct + * @covers OAuth\OAuth2\Service\Heroku::getExtraApiHeaders + */ + public function testGetExtraApiHeaders() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Heroku( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Accept', $headers)); + $this->assertSame('application/vnd.heroku+json; version=3', $headers['Accept']); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/InstagramTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/InstagramTest.php new file mode 100644 index 00000000..bf9d764c --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/InstagramTest.php @@ -0,0 +1,193 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Instagram; +use OAuth\Common\Token\TokenInterface; + +class InstagramTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + * @covers OAuth\OAuth2\Service\Instagram::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://api.instagram.com/oauth/authorize/', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + * @covers OAuth\OAuth2\Service\Instagram::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://api.instagram.com/oauth/access_token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + * @covers OAuth\OAuth2\Service\Instagram::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('access_token=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + * @covers OAuth\OAuth2\Service\Instagram::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + * @covers OAuth\OAuth2\Service\Instagram::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + * @covers OAuth\OAuth2\Service\Instagram::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Instagram::__construct + * @covers OAuth\OAuth2\Service\Instagram::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Instagram( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/LinkedinTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/LinkedinTest.php new file mode 100644 index 00000000..c7f5c76e --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/LinkedinTest.php @@ -0,0 +1,213 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Linkedin; +use OAuth\Common\Token\TokenInterface; + +class LinkedinTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + * @covers OAuth\OAuth2\Service\Linkedin::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://www.linkedin.com/uas/oauth2/authorization', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + * @covers OAuth\OAuth2\Service\Linkedin::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://www.linkedin.com/uas/oauth2/accessToken', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + * @covers OAuth\OAuth2\Service\Linkedin::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('oauth2_access_token=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnErrorDescription() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error_description=some_error')); + + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Linkedin::__construct + * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Linkedin( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/MailchimpTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/MailchimpTest.php new file mode 100644 index 00000000..e7f955e1 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/MailchimpTest.php @@ -0,0 +1,179 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Mailchimp; +use OAuth\Common\Token\TokenInterface; +use OAuth\Common\Http\Uri\Uri; + +class MailchimpTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Mailchimp::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Mailchimp( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Mailchimp::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Mailchimp( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Mailchimp::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Mailchimp( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Mailchimp::__construct + * @covers OAuth\OAuth2\Service\Mailchimp::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Mailchimp( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://login.mailchimp.com/oauth2/authorize', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Mailchimp::__construct + * @covers OAuth\OAuth2\Service\Mailchimp::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Mailchimp( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://login.mailchimp.com/oauth2/token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Mailchimp::__construct + * @covers OAuth\OAuth2\Service\Mailchimp::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\StdOAuth2Token'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Mailchimp( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage, + array(), + new Uri('https://us1.api.mailchimp.com/2.0/') + ); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('apikey=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\Mailchimp::__construct + * @covers OAuth\OAuth2\Service\Mailchimp::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Mailchimp( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Mailchimp::__construct + * @covers OAuth\OAuth2\Service\Mailchimp::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Mailchimp( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Mailchimp::__construct + * @covers OAuth\OAuth2\Service\Mailchimp::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValid() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->at(0))->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + $client->expects($this->at(1))->method('retrieveResponse')->will($this->returnValue('{"dc": "us7"}')); + + $service = new Mailchimp( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/MicrosoftTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/MicrosoftTest.php new file mode 100644 index 00000000..4001e1e4 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/MicrosoftTest.php @@ -0,0 +1,193 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Microsoft; +use OAuth\Common\Token\TokenInterface; + +class MicrosoftTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + * @covers OAuth\OAuth2\Service\Microsoft::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://login.live.com/oauth20_authorize.srf', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + * @covers OAuth\OAuth2\Service\Microsoft::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://login.live.com/oauth20_token.srf', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + * @covers OAuth\OAuth2\Service\Microsoft::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); + $absoluteUri = parse_url($uri->getAbsoluteUri()); + + $this->assertSame('access_token=foo', $absoluteUri['query']); + } + + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + * @covers OAuth\OAuth2\Service\Microsoft::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + * @covers OAuth\OAuth2\Service\Microsoft::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + * @covers OAuth\OAuth2\Service\Microsoft::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Microsoft::__construct + * @covers OAuth\OAuth2\Service\Microsoft::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Microsoft( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/PaypalTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/PaypalTest.php new file mode 100644 index 00000000..5396326f --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/PaypalTest.php @@ -0,0 +1,213 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Paypal; +use OAuth\Common\Token\TokenInterface; + +class PaypalTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + * @covers OAuth\OAuth2\Service\Paypal::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + * @covers OAuth\OAuth2\Service\Paypal::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://api.paypal.com/v1/identity/openidconnect/tokenservice', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + * @covers OAuth\OAuth2\Service\Paypal::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('Bearer foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + * @covers OAuth\OAuth2\Service\Paypal::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + * @covers OAuth\OAuth2\Service\Paypal::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnMessage() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('message=some_error')); + + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + * @covers OAuth\OAuth2\Service\Paypal::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnName() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('name=some_error')); + + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + * @covers OAuth\OAuth2\Service\Paypal::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Paypal::__construct + * @covers OAuth\OAuth2\Service\Paypal::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Paypal( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/RedditTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/RedditTest.php new file mode 100644 index 00000000..e8741e6f --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/RedditTest.php @@ -0,0 +1,193 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Reddit; +use OAuth\Common\Token\TokenInterface; + +class RedditTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + * @covers OAuth\OAuth2\Service\Reddit::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://ssl.reddit.com/api/v1/authorize', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + * @covers OAuth\OAuth2\Service\Reddit::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://ssl.reddit.com/api/v1/access_token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + * @covers OAuth\OAuth2\Service\Reddit::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('Bearer foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + * @covers OAuth\OAuth2\Service\Reddit::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + * @covers OAuth\OAuth2\Service\Reddit::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + * @covers OAuth\OAuth2\Service\Reddit::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Reddit::__construct + * @covers OAuth\OAuth2\Service\Reddit::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Reddit( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/RunKeeperTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/RunKeeperTest.php new file mode 100644 index 00000000..671bd0cf --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/RunKeeperTest.php @@ -0,0 +1,207 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\RunKeeper; +use OAuth\Common\Token\TokenInterface; + +class RunKeeperTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + * @covers OAuth\OAuth2\Service\RunKeeper::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://runkeeper.com/apps/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + * @covers OAuth\OAuth2\Service\RunKeeper::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://runkeeper.com/apps/token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + * @covers OAuth\OAuth2\Service\RunKeeper::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('/user'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('Bearer foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + * @covers OAuth\OAuth2\Service\RunKeeper::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + * @covers OAuth\OAuth2\Service\RunKeeper::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnErrorDescription() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error_description=some_error')); + + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + * @covers OAuth\OAuth2\Service\RunKeeper::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + * @covers OAuth\OAuth2\Service\RunKeeper::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\RunKeeper::__construct + * @covers OAuth\OAuth2\Service\RunKeeper::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new RunKeeper( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/SoundCloudTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/SoundCloudTest.php new file mode 100644 index 00000000..ac988ba2 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/SoundCloudTest.php @@ -0,0 +1,159 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\SoundCloud; +use OAuth\Common\Token\TokenInterface; + +class SoundCloudTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\SoundCloud::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new SoundCloud( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\SoundCloud::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new SoundCloud( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\SoundCloud::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new SoundCloud( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\SoundCloud::__construct + * @covers OAuth\OAuth2\Service\SoundCloud::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new SoundCloud( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://soundcloud.com/connect', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\SoundCloud::__construct + * @covers OAuth\OAuth2\Service\SoundCloud::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new SoundCloud( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://api.soundcloud.com/oauth2/token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\SoundCloud::__construct + * @covers OAuth\OAuth2\Service\SoundCloud::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new SoundCloud( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\SoundCloud::__construct + * @covers OAuth\OAuth2\Service\SoundCloud::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new SoundCloud( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\SoundCloud::__construct + * @covers OAuth\OAuth2\Service\SoundCloud::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new SoundCloud( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\SoundCloud::__construct + * @covers OAuth\OAuth2\Service\SoundCloud::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new SoundCloud( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/UstreamTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/UstreamTest.php new file mode 100644 index 00000000..48965ae0 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/UstreamTest.php @@ -0,0 +1,193 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Ustream; +use OAuth\Common\Token\TokenInterface; + +class UstreamTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + * @covers OAuth\OAuth2\Service\Ustream::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://www.ustream.tv/oauth2/authorize', + $service->getAuthorizationEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + * @covers OAuth\OAuth2\Service\Ustream::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame( + 'https://www.ustream.tv/oauth2/token', + $service->getAccessTokenEndpoint()->getAbsoluteUri() + ); + } + + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + * @covers OAuth\OAuth2\Service\Ustream::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('Bearer foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + * @covers OAuth\OAuth2\Service\Ustream::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + * @covers OAuth\OAuth2\Service\Ustream::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + * @covers OAuth\OAuth2\Service\Ustream::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Ustream::__construct + * @covers OAuth\OAuth2\Service\Ustream::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Ustream( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/VkontakteTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/VkontakteTest.php new file mode 100644 index 00000000..7a8279b2 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/VkontakteTest.php @@ -0,0 +1,159 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Vkontakte; +use OAuth\Common\Token\TokenInterface; + +class VkontakteTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Vkontakte::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Vkontakte( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Vkontakte::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Vkontakte( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Vkontakte::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Vkontakte( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Vkontakte::__construct + * @covers OAuth\OAuth2\Service\Vkontakte::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Vkontakte( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://oauth.vk.com/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Vkontakte::__construct + * @covers OAuth\OAuth2\Service\Vkontakte::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Vkontakte( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://oauth.vk.com/access_token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Vkontakte::__construct + * @covers OAuth\OAuth2\Service\Vkontakte::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Vkontakte( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Vkontakte::__construct + * @covers OAuth\OAuth2\Service\Vkontakte::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Vkontakte( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Vkontakte::__construct + * @covers OAuth\OAuth2\Service\Vkontakte::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); + + $service = new Vkontakte( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Vkontakte::__construct + * @covers OAuth\OAuth2\Service\Vkontakte::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); + + $service = new Vkontakte( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/YammerTest.php b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/YammerTest.php new file mode 100644 index 00000000..86440395 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/OAuth2/Service/YammerTest.php @@ -0,0 +1,187 @@ +<?php + +namespace OAuthTest\Unit\OAuth2\Service; + +use OAuth\OAuth2\Service\Yammer; +use OAuth\Common\Token\TokenInterface; + +class YammerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + */ + public function testConstructCorrectInterfaceWithoutCustomUri() + { + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + */ + public function testConstructCorrectInstanceWithoutCustomUri() + { + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + */ + public function testConstructCorrectInstanceWithCustomUri() + { + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array(), + $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); + } + + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + * @covers OAuth\OAuth2\Service\Yammer::getAuthorizationEndpoint + */ + public function testGetAuthorizationEndpoint() + { + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://www.yammer.com/dialog/oauth', $service->getAuthorizationEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + * @covers OAuth\OAuth2\Service\Yammer::getAccessTokenEndpoint + */ + public function testGetAccessTokenEndpoint() + { + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertSame('https://www.yammer.com/oauth2/access_token.json', $service->getAccessTokenEndpoint()->getAbsoluteUri()); + } + + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + * @covers OAuth\OAuth2\Service\Yammer::getAuthorizationMethod + */ + public function testGetAuthorizationMethod() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); + + $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); + $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); + $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); + + $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); + $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); + + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $storage + ); + + $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); + + $this->assertTrue(array_key_exists('Authorization', $headers)); + $this->assertTrue(in_array('Bearer foo', $headers, true)); + } + + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + * @covers OAuth\OAuth2\Service\Yammer::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); + + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + * @covers OAuth\OAuth2\Service\Yammer::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseThrowsExceptionOnError() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); + + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); + + $service->requestAccessToken('foo'); + } + + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + * @covers OAuth\OAuth2\Service\Yammer::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithoutRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":{"token":"foo", "expires_at":null}}')); + + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } + + /** + * @covers OAuth\OAuth2\Service\Yammer::__construct + * @covers OAuth\OAuth2\Service\Yammer::parseAccessTokenResponse + */ + public function testParseAccessTokenResponseValidWithRefreshToken() + { + $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); + $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":{"token":"foo", "expires_at":null},"refresh_token":"baz"}')); + + $service = new Yammer( + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $client, + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); + } +} diff --git a/vendor/lusitanian/oauth/tests/Unit/ServiceFactoryTest.php b/vendor/lusitanian/oauth/tests/Unit/ServiceFactoryTest.php new file mode 100644 index 00000000..26588dc0 --- /dev/null +++ b/vendor/lusitanian/oauth/tests/Unit/ServiceFactoryTest.php @@ -0,0 +1,311 @@ +<?php +/** + * @category OAuth + * @package Tests + * @author David Desberg <david@daviddesberg.com> + * @author Chris Heng <bigblah@gmail.com> + * @author Pieter Hordijk <info@pieterhordijk.com> + * @copyright Copyright (c) 2013 The authors + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ +namespace OAuth\Unit; + +use OAuth\ServiceFactory; + +class ServiceFactoryTest extends \PHPUnit_Framework_TestCase +{ + /** + * @covers OAuth\ServiceFactory::setHttpClient + */ + public function testSetHttpClient() + { + $factory = new ServiceFactory(); + + $this->assertInstanceOf( + '\\OAuth\\ServiceFactory', + $factory->setHttpClient($this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface')) + ); + } + + /** + * @covers OAuth\ServiceFactory::registerService + */ + public function testRegisterServiceThrowsExceptionNonExistentClass() + { + $this->setExpectedException('\\OAuth\Common\Exception\Exception'); + + $factory = new ServiceFactory(); + $factory->registerService('foo', 'bar'); + } + + /** + * @covers OAuth\ServiceFactory::registerService + */ + public function testRegisterServiceThrowsExceptionWithClassIncorrectImplementation() + { + $this->setExpectedException('\\OAuth\Common\Exception\Exception'); + + $factory = new ServiceFactory(); + $factory->registerService('foo', 'OAuth\\ServiceFactory'); + } + + /** + * @covers OAuth\ServiceFactory::registerService + */ + public function testRegisterServiceSuccessOAuth1() + { + $factory = new ServiceFactory(); + + $this->assertInstanceOf( + '\\OAuth\\ServiceFactory', + $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake') + ); + } + + /** + * @covers OAuth\ServiceFactory::registerService + */ + public function testRegisterServiceSuccessOAuth2() + { + $factory = new ServiceFactory(); + + $this->assertInstanceOf( + '\\OAuth\\ServiceFactory', + $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake') + ); + } + + /** + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV1Service + */ + public function testCreateServiceOAuth1NonRegistered() + { + $factory = new ServiceFactory(); + + $service = $factory->createService( + 'twitter', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\Twitter', $service); + } + + /** + * @covers OAuth\ServiceFactory::registerService + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV1Service + */ + public function testCreateServiceOAuth1Registered() + { + $factory = new ServiceFactory(); + + $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake'); + + $service = $factory->createService( + 'foo', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\OAuth1\Service\\ServiceInterface', $service); + $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake', $service); + } + + /** + * @covers OAuth\ServiceFactory::registerService + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV1Service + */ + public function testCreateServiceOAuth1RegisteredAndNonRegisteredSameName() + { + $factory = new ServiceFactory(); + + $factory->registerService('twitter', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake'); + + $service = $factory->createService( + 'twitter', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\OAuth1\Service\\ServiceInterface', $service); + $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake', $service); + } + + /** + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV2Service + * @covers OAuth\ServiceFactory::resolveScopes + */ + public function testCreateServiceOAuth2NonRegistered() + { + $factory = new ServiceFactory(); + + $service = $factory->createService( + 'facebook', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\Facebook', $service); + } + + /** + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV2Service + * @covers OAuth\ServiceFactory::resolveScopes + */ + public function testCreateServiceOAuth2Registered() + { + $factory = new ServiceFactory(); + + $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); + + $service = $factory->createService( + 'foo', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); + $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service); + } + + /** + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV2Service + * @covers OAuth\ServiceFactory::resolveScopes + */ + public function testCreateServiceOAuth2RegisteredAndNonRegisteredSameName() + { + $factory = new ServiceFactory(); + + $factory->registerService('facebook', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); + + $service = $factory->createService( + 'facebook', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); + $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service); + } + + /** + * @covers OAuth\ServiceFactory::registerService + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV1Service + */ + public function testCreateServiceThrowsExceptionOnPassingScopesToV1Service() + { + $this->setExpectedException('\\OAuth\Common\Exception\Exception'); + + $factory = new ServiceFactory(); + + $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake'); + + $service = $factory->createService( + 'foo', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array('bar') + ); + } + + /** + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + */ + public function testCreateServiceNonExistentService() + { + $factory = new ServiceFactory(); + + $service = $factory->createService( + 'foo', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertNull($service); + } + + /** + * @covers OAuth\ServiceFactory::registerService + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV2Service + * @covers OAuth\ServiceFactory::resolveScopes + */ + public function testCreateServicePrefersOauth2() + { + $factory = new ServiceFactory(); + + $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake'); + $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); + + $service = $factory->createService( + 'foo', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') + ); + + $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); + $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service); + } + + /** + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV2Service + * @covers OAuth\ServiceFactory::resolveScopes + */ + public function testCreateServiceOAuth2RegisteredWithClassConstantsAsScope() + { + $factory = new ServiceFactory(); + + $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); + + $service = $factory->createService( + 'foo', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array('FOO') + ); + + $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); + $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service); + } + + /** + * @covers OAuth\ServiceFactory::createService + * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName + * @covers OAuth\ServiceFactory::buildV2Service + * @covers OAuth\ServiceFactory::resolveScopes + */ + public function testCreateServiceOAuth2RegisteredWithCustomScope() + { + $factory = new ServiceFactory(); + + $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); + + $service = $factory->createService( + 'foo', + $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), + $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), + array('custom') + ); + + $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); + $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service); + } +} |