|
@@ -15,10 +15,57 @@ use Symfony\Component\Security\Role\Role;
|
|
|
|
|
|
class Token extends BaseToken
|
|
class Token extends BaseToken
|
|
{
|
|
{
|
|
|
|
+ public function setUser($user)
|
|
|
|
+ {
|
|
|
|
+ $this->user = $user;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function setCredentials($credentials)
|
|
|
|
+ {
|
|
|
|
+ $this->credentials = $credentials;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
class TokenTest extends \PHPUnit_Framework_TestCase
|
|
class TokenTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
{
|
|
|
|
+ public function testMagicToString()
|
|
|
|
+ {
|
|
|
|
+ $token = new Token(array('ROLE_FOO'));
|
|
|
|
+ $token->setUser('fabien');
|
|
|
|
+ $this->assertEquals('fabien', (string) $token);
|
|
|
|
+
|
|
|
|
+ $token->setUser(new \stdClass('fabien'));
|
|
|
|
+ $this->assertEquals('n/a', (string) $token);
|
|
|
|
+
|
|
|
|
+ $user = $this->getMock('Symfony\Component\Security\User\AccountInterface');
|
|
|
|
+ $user->expects($this->once())->method('getUsername')->will($this->returnValue('fabien'));
|
|
|
|
+
|
|
|
|
+ $token->setUser($user);
|
|
|
|
+ $this->assertEquals('fabien', (string) $token);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function testEraseCredentials()
|
|
|
|
+ {
|
|
|
|
+ $token = new Token(array('ROLE_FOO'));
|
|
|
|
+
|
|
|
|
+ $credentials = $this->getMock('Symfony\Component\Security\User\AccountInterface');
|
|
|
|
+ $credentials->expects($this->once())->method('eraseCredentials');
|
|
|
|
+ $token->setCredentials($credentials);
|
|
|
|
+
|
|
|
|
+ $user = $this->getMock('Symfony\Component\Security\User\AccountInterface');
|
|
|
|
+ $user->expects($this->once())->method('eraseCredentials');
|
|
|
|
+ $token->setUser($user);
|
|
|
|
+
|
|
|
|
+ $token->eraseCredentials();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function testSerialize()
|
|
|
|
+ {
|
|
|
|
+ $token = new Token(array('ROLE_FOO'));
|
|
|
|
+
|
|
|
|
+ $this->assertEquals($token, unserialize(serialize($token)));
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @covers Symfony\Component\Security\Authentication\Token\Token::__construct
|
|
* @covers Symfony\Component\Security\Authentication\Token\Token::__construct
|
|
*/
|
|
*/
|