UsernamePasswordTokenTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Security\Authentication\Token;
  11. use Symfony\Component\Security\Authentication\Token\UsernamePasswordToken;
  12. use Symfony\Component\Security\Role\Role;
  13. class UsernamePasswordTokenTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testConstructor()
  16. {
  17. $token = new UsernamePasswordToken('foo', 'bar');
  18. $this->assertFalse($token->isAuthenticated());
  19. $token = new UsernamePasswordToken('foo', 'bar', array('ROLE_FOO'));
  20. $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
  21. $this->assertTrue($token->isAuthenticated());
  22. }
  23. /**
  24. * @expectedException LogicException
  25. */
  26. public function testSetAuthenticatedToTrue()
  27. {
  28. $token = new UsernamePasswordToken('foo', 'bar');
  29. $token->setAuthenticated(true);
  30. }
  31. public function testSetAuthenticatedToFalse()
  32. {
  33. $token = new UsernamePasswordToken('foo', 'bar');
  34. $token->setAuthenticated(false);
  35. $this->assertFalse($token->isAuthenticated());
  36. }
  37. public function testEraseCredentials()
  38. {
  39. $token = new UsernamePasswordToken('foo', 'bar');
  40. $token->eraseCredentials();
  41. $this->assertEquals('', $token->getCredentials());
  42. }
  43. }