CookieClearingLogoutHandlerTest.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\Http\Logout;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Security\Http\Logout\CookieClearingLogoutHandler;
  14. class CookieClearingLogoutHandlerTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testConstructor()
  17. {
  18. $cookieNames = array('foo', 'foo2', 'foo3');
  19. $handler = new CookieClearingLogoutHandler($cookieNames);
  20. $this->assertEquals($cookieNames, $handler->getCookieNames());
  21. }
  22. public function testLogout()
  23. {
  24. $request = new Request();
  25. $response = new Response();
  26. $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
  27. $handler = new CookieClearingLogoutHandler(array('foo', 'foo2'));
  28. $this->assertFalse($response->headers->hasCookie('foo'));
  29. $handler->logout($request, $response, $token);
  30. $cookies = $response->headers->getCookies();
  31. $this->assertEquals(2, count($cookies));
  32. $cookie = $cookies['foo'];
  33. $this->assertEquals('foo', $cookie->getName());
  34. $this->assertTrue($cookie->isCleared());
  35. $cookie = $cookies['foo2'];
  36. $this->assertStringStartsWith('foo2', $cookie->getName());
  37. $this->assertTrue($cookie->isCleared());
  38. }
  39. }