diff options
author | Bernhard Schussek <bschussek@gmail.com> | 2013-09-16 10:03:00 +0200 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2013-09-18 09:16:41 +0200 |
commit | 5a6aaab2c35213f5ca7e57f061fbb2675e2ece35 (patch) | |
tree | 461816fef8160401dc113d3fef190fb437d01cc7 /Tests/Core/Authentication/Token | |
parent | 513a354be10f0ed87933adcb788e48660f8e6ed4 (diff) | |
download | symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.zip symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.tar.gz symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.tar.bz2 |
[Security] Split the component into 3 sub-components Core, ACL, HTTP
Diffstat (limited to 'Tests/Core/Authentication/Token')
5 files changed, 0 insertions, 478 deletions
diff --git a/Tests/Core/Authentication/Token/AbstractTokenTest.php b/Tests/Core/Authentication/Token/AbstractTokenTest.php deleted file mode 100644 index 783c27e..0000000 --- a/Tests/Core/Authentication/Token/AbstractTokenTest.php +++ /dev/null @@ -1,244 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Security\Tests\Core\Authentication\Token; - -use Symfony\Component\Security\Core\Role\Role; - -class TestUser -{ - protected $name; - - public function __construct($name) - { - $this->name = $name; - } - - public function __toString() - { - return $this->name; - } -} - -class AbstractTokenTest extends \PHPUnit_Framework_TestCase -{ - public function testGetUsername() - { - $token = $this->getToken(array('ROLE_FOO')); - $token->setUser('fabien'); - $this->assertEquals('fabien', $token->getUsername()); - - $token->setUser(new TestUser('fabien')); - $this->assertEquals('fabien', $token->getUsername()); - - $user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); - $user->expects($this->once())->method('getUsername')->will($this->returnValue('fabien')); - $token->setUser($user); - $this->assertEquals('fabien', $token->getUsername()); - } - - public function testEraseCredentials() - { - $token = $this->getToken(array('ROLE_FOO')); - - $user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); - $user->expects($this->once())->method('eraseCredentials'); - $token->setUser($user); - - $token->eraseCredentials(); - } - - /** - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::serialize - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::unserialize - */ - public function testSerialize() - { - $token = $this->getToken(array('ROLE_FOO')); - $token->setAttributes(array('foo' => 'bar')); - - $uToken = unserialize(serialize($token)); - - $this->assertEquals($token->getRoles(), $uToken->getRoles()); - $this->assertEquals($token->getAttributes(), $uToken->getAttributes()); - } - - /** - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::__construct - */ - public function testConstructor() - { - $token = $this->getToken(array('ROLE_FOO')); - $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles()); - - $token = $this->getToken(array(new Role('ROLE_FOO'))); - $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles()); - - $token = $this->getToken(array(new Role('ROLE_FOO'), 'ROLE_BAR')); - $this->assertEquals(array(new Role('ROLE_FOO'), new Role('ROLE_BAR')), $token->getRoles()); - } - - /** - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::isAuthenticated - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::setAuthenticated - */ - public function testAuthenticatedFlag() - { - $token = $this->getToken(); - $this->assertFalse($token->isAuthenticated()); - - $token->setAuthenticated(true); - $this->assertTrue($token->isAuthenticated()); - - $token->setAuthenticated(false); - $this->assertFalse($token->isAuthenticated()); - } - - /** - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::getAttributes - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::setAttributes - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::hasAttribute - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::getAttribute - * @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::setAttribute - */ - public function testAttributes() - { - $attributes = array('foo' => 'bar'); - $token = $this->getToken(); - $token->setAttributes($attributes); - - $this->assertEquals($attributes, $token->getAttributes(), '->getAttributes() returns the token attributes'); - $this->assertEquals('bar', $token->getAttribute('foo'), '->getAttribute() returns the value of an attribute'); - $token->setAttribute('foo', 'foo'); - $this->assertEquals('foo', $token->getAttribute('foo'), '->setAttribute() changes the value of an attribute'); - $this->assertTrue($token->hasAttribute('foo'), '->hasAttribute() returns true if the attribute is defined'); - $this->assertFalse($token->hasAttribute('oof'), '->hasAttribute() returns false if the attribute is not defined'); - - try { - $token->getAttribute('foobar'); - $this->fail('->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist'); - } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist'); - $this->assertEquals('This token has no "foobar" attribute.', $e->getMessage(), '->getAttribute() throws an \InvalidArgumentException exception when the attribute does not exist'); - } - } - - /** - * @dataProvider getUsers - */ - public function testSetUser($user) - { - $token = $this->getToken(); - $token->setUser($user); - $this->assertSame($user, $token->getUser()); - } - - public function getUsers() - { - $user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); - $advancedUser = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface'); - - return array( - array($advancedUser), - array($user), - array(new TestUser('foo')), - array('foo'), - ); - } - - /** - * @dataProvider getUserChanges - */ - public function testSetUserSetsAuthenticatedToFalseWhenUserChanges($firstUser, $secondUser) - { - $token = $this->getToken(); - $token->setAuthenticated(true); - $this->assertTrue($token->isAuthenticated()); - - $token->setUser($firstUser); - $this->assertTrue($token->isAuthenticated()); - - $token->setUser($secondUser); - $this->assertFalse($token->isAuthenticated()); - } - - public function getUserChanges() - { - $user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); - $advancedUser = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface'); - - return array( - array( - 'foo', 'bar', - ), - array( - 'foo', new TestUser('bar'), - ), - array( - 'foo', $user, - ), - array( - 'foo', $advancedUser - ), - array( - $user, 'foo' - ), - array( - $advancedUser, 'foo' - ), - array( - $user, new TestUser('foo'), - ), - array( - $advancedUser, new TestUser('foo'), - ), - array( - new TestUser('foo'), new TestUser('bar'), - ), - array( - new TestUser('foo'), 'bar', - ), - array( - new TestUser('foo'), $user, - ), - array( - new TestUser('foo'), $advancedUser, - ), - array( - $user, $advancedUser - ), - array( - $advancedUser, $user - ), - ); - } - - /** - * @dataProvider getUsers - */ - public function testSetUserDoesNotSetAuthenticatedToFalseWhenUserDoesNotChange($user) - { - $token = $this->getToken(); - $token->setAuthenticated(true); - $this->assertTrue($token->isAuthenticated()); - - $token->setUser($user); - $this->assertTrue($token->isAuthenticated()); - - $token->setUser($user); - $this->assertTrue($token->isAuthenticated()); - } - - protected function getToken(array $roles = array()) - { - return $this->getMockForAbstractClass('Symfony\Component\Security\Core\Authentication\Token\AbstractToken', array($roles)); - } -} diff --git a/Tests/Core/Authentication/Token/AnonymousTokenTest.php b/Tests/Core/Authentication/Token/AnonymousTokenTest.php deleted file mode 100644 index 135397b..0000000 --- a/Tests/Core/Authentication/Token/AnonymousTokenTest.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Security\Tests\Core\Authentication\Token; - -use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; -use Symfony\Component\Security\Core\Role\Role; - -class AnonymousTokenTest extends \PHPUnit_Framework_TestCase -{ - public function testConstructor() - { - $token = new AnonymousToken('foo', 'bar'); - $this->assertTrue($token->isAuthenticated()); - - $token = new AnonymousToken('foo', 'bar', array('ROLE_FOO')); - $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles()); - } - - public function testGetKey() - { - $token = new AnonymousToken('foo', 'bar'); - $this->assertEquals('foo', $token->getKey()); - } - - public function testGetCredentials() - { - $token = new AnonymousToken('foo', 'bar'); - $this->assertEquals('', $token->getCredentials()); - } - - public function testGetUser() - { - $token = new AnonymousToken('foo', 'bar'); - $this->assertEquals('bar', $token->getUser()); - } -} diff --git a/Tests/Core/Authentication/Token/PreAuthenticatedTokenTest.php b/Tests/Core/Authentication/Token/PreAuthenticatedTokenTest.php deleted file mode 100644 index 59a533a..0000000 --- a/Tests/Core/Authentication/Token/PreAuthenticatedTokenTest.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Security\Tests\Core\Authentication\Token; - -use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken; -use Symfony\Component\Security\Core\Role\Role; - -class PreAuthenticatedTokenTest extends \PHPUnit_Framework_TestCase -{ - public function testConstructor() - { - $token = new PreAuthenticatedToken('foo', 'bar', 'key'); - $this->assertFalse($token->isAuthenticated()); - - $token = new PreAuthenticatedToken('foo', 'bar', 'key', array('ROLE_FOO')); - $this->assertTrue($token->isAuthenticated()); - $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles()); - $this->assertEquals('key', $token->getProviderKey()); - } - - public function testGetCredentials() - { - $token = new PreAuthenticatedToken('foo', 'bar', 'key'); - $this->assertEquals('bar', $token->getCredentials()); - } - - public function testGetUser() - { - $token = new PreAuthenticatedToken('foo', 'bar', 'key'); - $this->assertEquals('foo', $token->getUser()); - } - - public function testEraseCredentials() - { - $token = new PreAuthenticatedToken('foo', 'bar', 'key'); - $token->eraseCredentials(); - $this->assertEquals('', $token->getCredentials()); - } -} diff --git a/Tests/Core/Authentication/Token/RememerMeTokenTest.php b/Tests/Core/Authentication/Token/RememerMeTokenTest.php deleted file mode 100644 index 03275fa..0000000 --- a/Tests/Core/Authentication/Token/RememerMeTokenTest.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Security\Tests\Core\Authentication\Token; - -use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken; -use Symfony\Component\Security\Core\Role\Role; - -class RememberMeTokenTest extends \PHPUnit_Framework_TestCase -{ - public function testConstructor() - { - $user = $this->getUser(); - $token = new RememberMeToken($user, 'fookey', 'foo'); - - $this->assertEquals('fookey', $token->getProviderKey()); - $this->assertEquals('foo', $token->getKey()); - $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles()); - $this->assertSame($user, $token->getUser()); - $this->assertTrue($token->isAuthenticated()); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testConstructorKeyCannotBeNull() - { - new RememberMeToken( - $this->getUser(), - null, - null - ); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testConstructorKeyCannotBeEmptyString() - { - new RememberMeToken( - $this->getUser(), - '', - '' - ); - } - - /** - * @expectedException PHPUnit_Framework_Error - * @dataProvider getUserArguments - */ - public function testConstructorUserCannotBeNull($user) - { - new RememberMeToken($user, 'foo', 'foo'); - } - - public function getUserArguments() - { - return array( - array(null), - array('foo'), - ); - } - - protected function getUser($roles = array('ROLE_FOO')) - { - $user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); - $user - ->expects($this->once()) - ->method('getRoles') - ->will($this->returnValue($roles)) - ; - - return $user; - } -} diff --git a/Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php b/Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php deleted file mode 100644 index 3da20eb..0000000 --- a/Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Security\Tests\Core\Authentication\Token; - -use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; -use Symfony\Component\Security\Core\Role\Role; - -class UsernamePasswordTokenTest extends \PHPUnit_Framework_TestCase -{ - public function testConstructor() - { - $token = new UsernamePasswordToken('foo', 'bar', 'key'); - $this->assertFalse($token->isAuthenticated()); - - $token = new UsernamePasswordToken('foo', 'bar', 'key', array('ROLE_FOO')); - $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles()); - $this->assertTrue($token->isAuthenticated()); - $this->assertEquals('key', $token->getProviderKey()); - } - - /** - * @expectedException LogicException - */ - public function testSetAuthenticatedToTrue() - { - $token = new UsernamePasswordToken('foo', 'bar', 'key'); - $token->setAuthenticated(true); - } - - public function testSetAuthenticatedToFalse() - { - $token = new UsernamePasswordToken('foo', 'bar', 'key'); - $token->setAuthenticated(false); - $this->assertFalse($token->isAuthenticated()); - } - - public function testEraseCredentials() - { - $token = new UsernamePasswordToken('foo', 'bar', 'key'); - $token->eraseCredentials(); - $this->assertEquals('', $token->getCredentials()); - } - - public function testToString() - { - $token = new UsernamePasswordToken('foo', '', 'foo', array('A', 'B')); - $this->assertEquals('UsernamePasswordToken(user="foo", authenticated=true, roles="A, B")', (string) $token); - } -} |