Include all vendor files in the repo to be easier for people

This commit is contained in:
Frédéric Guillot
2014-11-06 06:41:47 -05:00
parent c91ff61cdf
commit c80c15dcc3
677 changed files with 130567 additions and 2 deletions

View File

@@ -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);
}
}

View File

@@ -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']);
}
}

View File

@@ -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']);
}
}

View File

@@ -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);
}
}
}

View File

@@ -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());
}
}

View File

@@ -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&param2=second');
$this->assertSame('param1=first&param2=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&param2=value2');
$this->assertSame('http://example.com?param1=value1&param2=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&param2=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());
}
}