Laravel version update
Laravel version update
This commit is contained in:
70
vendor/laravel/socialite/tests/OAuthOneTest.php
vendored
Normal file
70
vendor/laravel/socialite/tests/OAuthOneTest.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use Mockery as m;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Socialite\One\AbstractProvider;
|
||||
|
||||
class OAuthOneTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testRedirectGeneratesTheProperSymfonyRedirectResponse()
|
||||
{
|
||||
$server = m::mock('League\OAuth1\Client\Server\Twitter');
|
||||
$server->shouldReceive('getTemporaryCredentials')->once()->andReturn('temp');
|
||||
$server->shouldReceive('getAuthorizationUrl')->once()->with('temp')->andReturn('http://auth.url');
|
||||
$request = Request::create('foo');
|
||||
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
|
||||
$session->shouldReceive('put')->once()->with('oauth.temp', 'temp');
|
||||
|
||||
$provider = new OAuthOneTestProviderStub($request, $server);
|
||||
$response = $provider->redirect();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
|
||||
}
|
||||
|
||||
public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
|
||||
{
|
||||
$server = m::mock('League\OAuth1\Client\Server\Twitter');
|
||||
$temp = m::mock('League\OAuth1\Client\Credentials\TemporaryCredentials');
|
||||
$server->shouldReceive('getTokenCredentials')->once()->with($temp, 'oauth_token', 'oauth_verifier')->andReturn(
|
||||
$token = m::mock('League\OAuth1\Client\Credentials\TokenCredentials')
|
||||
);
|
||||
$server->shouldReceive('getUserDetails')->once()->with($token)->andReturn($user = m::mock('League\OAuth1\Client\Server\User'));
|
||||
$token->shouldReceive('getIdentifier')->once()->andReturn('identifier');
|
||||
$token->shouldReceive('getSecret')->once()->andReturn('secret');
|
||||
$user->uid = 'uid';
|
||||
$user->email = 'foo@bar.com';
|
||||
$user->extra = ['extra' => 'extra'];
|
||||
$request = Request::create('foo', 'GET', ['oauth_token' => 'oauth_token', 'oauth_verifier' => 'oauth_verifier']);
|
||||
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
|
||||
$session->shouldReceive('get')->once()->with('oauth.temp')->andReturn($temp);
|
||||
|
||||
$provider = new OAuthOneTestProviderStub($request, $server);
|
||||
$user = $provider->user();
|
||||
|
||||
$this->assertInstanceOf('Laravel\Socialite\One\User', $user);
|
||||
$this->assertEquals('uid', $user->id);
|
||||
$this->assertEquals('foo@bar.com', $user->email);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testExceptionIsThrownWhenVerifierIsMissing()
|
||||
{
|
||||
$server = m::mock('League\OAuth1\Client\Server\Twitter');
|
||||
$request = Request::create('foo');
|
||||
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
|
||||
|
||||
$provider = new OAuthOneTestProviderStub($request, $server);
|
||||
$user = $provider->user();
|
||||
}
|
||||
}
|
||||
|
||||
class OAuthOneTestProviderStub extends AbstractProvider
|
||||
{
|
||||
}
|
106
vendor/laravel/socialite/tests/OAuthTwoTest.php
vendored
Normal file
106
vendor/laravel/socialite/tests/OAuthTwoTest.php
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
use Mockery as m;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Socialite\Two\User;
|
||||
use Laravel\Socialite\Two\AbstractProvider;
|
||||
|
||||
class OAuthTwoTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testRedirectGeneratesTheProperSymfonyRedirectResponse()
|
||||
{
|
||||
$request = Request::create('foo');
|
||||
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
|
||||
$session->shouldReceive('put')->once();
|
||||
$provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect');
|
||||
$response = $provider->redirect();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
|
||||
$this->assertEquals('http://auth.url', $response->getTargetUrl());
|
||||
}
|
||||
|
||||
public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
|
||||
{
|
||||
$request = Request::create('foo', 'GET', ['state' => str_repeat('A', 40), 'code' => 'code']);
|
||||
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
|
||||
$session->shouldReceive('pull')->once()->with('state')->andReturn(str_repeat('A', 40));
|
||||
$provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect_uri');
|
||||
$provider->http = m::mock('StdClass');
|
||||
$provider->http->shouldReceive('post')->once()->with('http://token.url', [
|
||||
'headers' => ['Accept' => 'application/json'], 'form_params' => ['client_id' => 'client_id', 'client_secret' => 'client_secret', 'code' => 'code', 'redirect_uri' => 'redirect_uri'],
|
||||
])->andReturn($response = m::mock('StdClass'));
|
||||
$response->shouldReceive('getBody')->once()->andReturn('access_token=access_token');
|
||||
$user = $provider->user();
|
||||
|
||||
$this->assertInstanceOf('Laravel\Socialite\Two\User', $user);
|
||||
$this->assertEquals('foo', $user->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Laravel\Socialite\Two\InvalidStateException
|
||||
*/
|
||||
public function testExceptionIsThrownIfStateIsInvalid()
|
||||
{
|
||||
$request = Request::create('foo', 'GET', ['state' => str_repeat('B', 40), 'code' => 'code']);
|
||||
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
|
||||
$session->shouldReceive('pull')->once()->with('state')->andReturn(str_repeat('A', 40));
|
||||
$provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect');
|
||||
$user = $provider->user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Laravel\Socialite\Two\InvalidStateException
|
||||
*/
|
||||
public function testExceptionIsThrownIfStateIsNotSet()
|
||||
{
|
||||
$request = Request::create('foo', 'GET', ['state' => 'state', 'code' => 'code']);
|
||||
$request->setLaravelSession($session = m::mock('Illuminate\Contracts\Session\Session'));
|
||||
$session->shouldReceive('pull')->once()->with('state');
|
||||
$provider = new OAuthTwoTestProviderStub($request, 'client_id', 'client_secret', 'redirect');
|
||||
$user = $provider->user();
|
||||
}
|
||||
}
|
||||
|
||||
class OAuthTwoTestProviderStub extends AbstractProvider
|
||||
{
|
||||
public $http;
|
||||
|
||||
protected function getAuthUrl($state)
|
||||
{
|
||||
return 'http://auth.url';
|
||||
}
|
||||
|
||||
protected function getTokenUrl()
|
||||
{
|
||||
return 'http://token.url';
|
||||
}
|
||||
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
return ['id' => 'foo'];
|
||||
}
|
||||
|
||||
protected function mapUserToObject(array $user)
|
||||
{
|
||||
return (new User)->map(['id' => $user['id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a fresh instance of the Guzzle HTTP client.
|
||||
*
|
||||
* @return \GuzzleHttp\Client
|
||||
*/
|
||||
protected function getHttpClient()
|
||||
{
|
||||
if ($this->http) {
|
||||
return $this->http;
|
||||
}
|
||||
|
||||
return $this->http = m::mock('StdClass');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user