PreAuthenticatedTokenTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\PreAuthenticatedToken;
  11. use Symfony\Component\Security\Role\Role;
  12. class PreAuthenticatedTokenTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testConstructor()
  15. {
  16. $token = new PreAuthenticatedToken('foo', 'bar');
  17. $this->assertFalse($token->isAuthenticated());
  18. $token = new PreAuthenticatedToken('foo', 'bar', array('ROLE_FOO'));
  19. $this->assertTrue($token->isAuthenticated());
  20. $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
  21. }
  22. public function testGetCredentials()
  23. {
  24. $token = new PreAuthenticatedToken('foo', 'bar');
  25. $this->assertEquals('bar', $token->getCredentials());
  26. }
  27. public function testGetUser()
  28. {
  29. $token = new PreAuthenticatedToken('foo', 'bar');
  30. $this->assertEquals('foo', $token->getUser());
  31. }
  32. public function testEraseCredentials()
  33. {
  34. $token = new PreAuthenticatedToken('foo', 'bar');
  35. $token->eraseCredentials();
  36. $this->assertEquals('', $token->getCredentials());
  37. }
  38. }