-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework some tests, still missing significant coverage
- Loading branch information
1 parent
383c0f4
commit 9b28d0f
Showing
8 changed files
with
136 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
use Mockery as M; | ||
use AdamWathan\EloquentOAuth\Authenticator; | ||
|
||
class AuthenticatorTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
M::close(); | ||
} | ||
|
||
public function test_login_creates_new_user_if_no_matching_user_exists() | ||
{ | ||
$auth = M::mock('Illuminate\\Auth\\AuthManager'); | ||
$users = M::mock('AdamWathan\\EloquentOAuth\\UserStore'); | ||
$identities = M::mock('AdamWathan\\EloquentOAuth\\IdentityStore')->shouldIgnoreMissing(); | ||
|
||
$userDetails = M::mock('AdamWathan\\EloquentOAuth\\ProviderUserDetails'); | ||
|
||
$user = M::mock('stdClass')->shouldIgnoreMissing(); | ||
|
||
$authenticator = new Authenticator($auth, $users, $identities); | ||
|
||
$users->shouldReceive('create')->andReturn($user); | ||
$users->shouldReceive('store')->once(); | ||
$auth->shouldReceive('login')->with($user)->once(); | ||
|
||
$authenticator->login('provider', $userDetails); | ||
} | ||
|
||
public function test_login_uses_existing_user_if_matching_user_exists() | ||
{ | ||
$auth = M::mock('Illuminate\\Auth\\AuthManager'); | ||
$users = M::mock('AdamWathan\\EloquentOAuth\\UserStore')->shouldIgnoreMissing(); | ||
$identities = M::mock('AdamWathan\\EloquentOAuth\\IdentityStore')->shouldIgnoreMissing(); | ||
|
||
$userDetails = M::mock('AdamWathan\\EloquentOAuth\\ProviderUserDetails'); | ||
$identity = M::mock('AdamWathan\\EloquentOAuth\\OAuthIdentity'); | ||
|
||
$user = M::mock('stdClass')->shouldIgnoreMissing(); | ||
|
||
$authenticator = new Authenticator($auth, $users, $identities); | ||
|
||
$identities->shouldReceive('userExists')->andReturn(true); | ||
$identities->shouldReceive('getByProvider')->andReturn($identity); | ||
$users->shouldReceive('create')->never(); | ||
$users->shouldReceive('findByIdentity')->andReturn($user); | ||
$auth->shouldReceive('login')->with($user)->once(); | ||
|
||
$authenticator->login('provider', $userDetails); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
use Mockery as M; | ||
use AdamWathan\EloquentOAuth\Authorizer; | ||
|
||
class AuthorizerTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
M::close(); | ||
} | ||
|
||
public function test_placeholder() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,4 +114,46 @@ public function test_store() | |
|
||
$this->assertEquals(1, OAuthIdentity::count()); | ||
} | ||
|
||
public function test_user_exists_returns_true_when_user_exists() | ||
{ | ||
OAuthIdentity::create(array( | ||
'user_id' => 2, | ||
'provider' => 'facebook', | ||
'provider_user_id' => 'bazfoo', | ||
'access_token' => 'def456', | ||
)); | ||
$details = new ProviderUserDetails(array( | ||
'accessToken' => 'new-token', | ||
'userId' => 'bazfoo', | ||
'nickname' => 'john.doe', | ||
'firstName' => 'John', | ||
'lastName' => 'Doe', | ||
'email' => '[email protected]', | ||
'imageUrl' => 'http://example.com/photos/john_doe.jpg', | ||
)); | ||
$identities = new IdentityStore; | ||
$this->assertTrue($identities->userExists('facebook', $details)); | ||
} | ||
|
||
public function test_user_exists_returns_false_when_user_doesnt_exist() | ||
{ | ||
OAuthIdentity::create(array( | ||
'user_id' => 2, | ||
'provider' => 'facebook', | ||
'provider_user_id' => 'foobar', | ||
'access_token' => 'def456', | ||
)); | ||
$details = new ProviderUserDetails(array( | ||
'accessToken' => 'new-token', | ||
'userId' => 'bazfoo', | ||
'nickname' => 'john.doe', | ||
'firstName' => 'John', | ||
'lastName' => 'Doe', | ||
'email' => '[email protected]', | ||
'imageUrl' => 'http://example.com/photos/john_doe.jpg', | ||
)); | ||
$identities = new IdentityStore; | ||
$this->assertFalse($identities->userExists('facebook', $details)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters