PreAuthenticatedTokenTest.php 1.5 KB

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