UsernamePasswordTokenTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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', 'key');
  18. $this->assertFalse($token->isAuthenticated());
  19. $token = new UsernamePasswordToken('foo', 'bar', 'key', array('ROLE_FOO'));
  20. $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
  21. $this->assertTrue($token->isAuthenticated());
  22. $this->assertEquals('key', $token->getProviderKey());
  23. }
  24. /**
  25. * @expectedException LogicException
  26. */
  27. public function testSetAuthenticatedToTrue()
  28. {
  29. $token = new UsernamePasswordToken('foo', 'bar', 'key');
  30. $token->setAuthenticated(true);
  31. }
  32. public function testSetAuthenticatedToFalse()
  33. {
  34. $token = new UsernamePasswordToken('foo', 'bar', 'key');
  35. $token->setAuthenticated(false);
  36. $this->assertFalse($token->isAuthenticated());
  37. }
  38. public function testEraseCredentials()
  39. {
  40. $token = new UsernamePasswordToken('foo', 'bar', 'key');
  41. $token->eraseCredentials();
  42. $this->assertEquals('', $token->getCredentials());
  43. }
  44. }