123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace Symfony\Tests\Component\Security\Authentication\Token;
- use Symfony\Component\Security\Authentication\Token\RememberMeToken;
- use Symfony\Component\Security\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'),
- );
- }
- public function testPersistentToken()
- {
- $token = new RememberMeToken($this->getUser(), 'fookey', 'foo');
- $persistentToken = $this->getMock('Symfony\Component\Security\Authentication\RememberMe\PersistentTokenInterface');
- $this->assertNull($token->getPersistentToken());
- $token->setPersistentToken($persistentToken);
- $this->assertSame($persistentToken, $token->getPersistentToken());
- }
- protected function getUser($roles = array('ROLE_FOO'))
- {
- $user = $this->getMock('Symfony\Component\Security\User\AccountInterface');
- $user
- ->expects($this->once())
- ->method('getRoles')
- ->will($this->returnValue($roles))
- ;
- return $user;
- }
- }
|