Permalink
Browse files

[OAuthProvider] Added more tests

  • Loading branch information...
1 parent 21c4b52 commit 41a0713f7fdb63ed7a5b37d31e15a84631ec6733 @willdurand willdurand committed May 7, 2012
@@ -60,8 +60,8 @@ public function authenticate(TokenInterface $token)
if ($accessToken = $this->serverService->verifyAccessToken($tokenString)) {
$scope = $accessToken->getScope();
- $user = $accessToken->getUser();
-
+ $user = $accessToken->getUser();
+
$roles = (null !== $user) ? $user->getRoles() : array();
if (!empty($scope)) {
@@ -35,6 +35,10 @@ public function testAuthenticateReturnsTokenIfValid()
$token = new OAuthToken();
$token->setToken('x');
+ $this->user->expects($this->once())
+ ->method('getRoles')
+ ->will($this->returnValue(array('ROLE_USER')));
+
$accessToken = new AccessToken();
$accessToken->setUser($this->user);
@@ -48,7 +52,10 @@ public function testAuthenticateReturnsTokenIfValid()
$this->assertSame($this->user, $result->getUser());
$this->assertEquals($token->getToken(), $result->getToken());
$this->assertTrue($result->isAuthenticated());
- $this->assertCount(0, $result->getRoles());
+ $this->assertCount(1, $result->getRoles());
+
+ $roles = $result->getRoles();
+ $this->assertEquals('ROLE_USER', $roles[0]->getRole());
}
public function testAuthenticateReturnsTokenIfValidEvenIfNullData()

0 comments on commit 41a0713

Please sign in to comment.