TokenTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace Symfony\Tests\Component\Security\Authentication\Token;
  10. use Symfony\Component\Security\Authentication\Token\Token as BaseToken;
  11. use Symfony\Component\Security\Role\Role;
  12. class Token extends BaseToken
  13. {
  14. }
  15. class TokenTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @covers Symfony\Component\Security\Authentication\Token\Token::__construct
  19. */
  20. public function testConstructor()
  21. {
  22. $token = new Token(array('ROLE_FOO'));
  23. $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
  24. $token = new Token(array(new Role('ROLE_FOO')));
  25. $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
  26. $token = new Token(array(new Role('ROLE_FOO'), 'ROLE_BAR'));
  27. $this->assertEquals(array(new Role('ROLE_FOO'), new Role('ROLE_BAR')), $token->getRoles());
  28. }
  29. /**
  30. * @covers Symfony\Component\Security\Authentication\Token\Token::addRole
  31. * @covers Symfony\Component\Security\Authentication\Token\Token::getRoles
  32. */
  33. public function testAddRole()
  34. {
  35. $token = new Token();
  36. $token->addRole(new Role('ROLE_FOO'));
  37. $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
  38. $token->addRole(new Role('ROLE_BAR'));
  39. $this->assertEquals(array(new Role('ROLE_FOO'), new Role('ROLE_BAR')), $token->getRoles());
  40. }
  41. /**
  42. * @covers Symfony\Component\Security\Authentication\Token\Token::isAuthenticated
  43. * @covers Symfony\Component\Security\Authentication\Token\Token::setAuthenticated
  44. */
  45. public function testAuthenticatedFlag()
  46. {
  47. $token = new Token();
  48. $this->assertFalse($token->isAuthenticated());
  49. $token->setAuthenticated(true);
  50. $this->assertTrue($token->isAuthenticated());
  51. $token->setAuthenticated(false);
  52. $this->assertFalse($token->isAuthenticated());
  53. }
  54. /**
  55. * @covers Symfony\Component\Security\Authentication\Token\Token::isImmutable
  56. * @covers Symfony\Component\Security\Authentication\Token\Token::setImmutable
  57. */
  58. public function testImmutableFlag()
  59. {
  60. $token = new Token();
  61. $this->assertFalse($token->isImmutable());
  62. $token->setImmutable(true);
  63. $this->assertTrue($token->isImmutable());
  64. $token->setImmutable(false);
  65. $this->assertFalse($token->isImmutable());
  66. }
  67. }