UsernamePasswordTokenTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\UsernamePasswordToken;
  11. use Symfony\Component\Security\Role\Role;
  12. class UsernamePasswordTokenTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testConstructor()
  15. {
  16. $token = new UsernamePasswordToken('foo', 'bar');
  17. $this->assertFalse($token->isAuthenticated());
  18. $token = new UsernamePasswordToken('foo', 'bar', array('ROLE_FOO'));
  19. $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
  20. $this->assertTrue($token->isAuthenticated());
  21. }
  22. /**
  23. * @expectedException LogicException
  24. */
  25. public function testSetAuthenticatedToTrue()
  26. {
  27. $token = new UsernamePasswordToken('foo', 'bar');
  28. $token->setAuthenticated(true);
  29. }
  30. public function testSetAuthenticatedToFalse()
  31. {
  32. $token = new UsernamePasswordToken('foo', 'bar');
  33. $token->setAuthenticated(false);
  34. $this->assertFalse($token->isAuthenticated());
  35. }
  36. public function testEraseCredentials()
  37. {
  38. $token = new UsernamePasswordToken('foo', 'bar');
  39. $token->eraseCredentials();
  40. $this->assertEquals('', $token->getCredentials());
  41. }
  42. }