CookieClearingLogoutHandlerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\ResponseHeaderBag;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Security\Http\Logout\CookieClearingLogoutHandler;
  15. class CookieClearingLogoutHandlerTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function testLogout()
  18. {
  19. $request = new Request();
  20. $response = new Response();
  21. $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
  22. $handler = new CookieClearingLogoutHandler(array('foo' => array('path' => '/foo', 'domain' => 'foo.foo'), 'foo2' => array('path' => null, 'domain' => null)));
  23. $cookies = $response->headers->getCookies();
  24. $this->assertEquals(0, count($cookies));
  25. $handler->logout($request, $response, $token);
  26. $cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
  27. $this->assertEquals(2, count($cookies));
  28. $cookie = $cookies['foo.foo']['/foo']['foo'];
  29. $this->assertEquals('foo', $cookie->getName());
  30. $this->assertEquals('/foo', $cookie->getPath());
  31. $this->assertEquals('foo.foo', $cookie->getDomain());
  32. $this->assertTrue($cookie->isCleared());
  33. $cookie = $cookies['']['/']['foo2'];
  34. $this->assertStringStartsWith('foo2', $cookie->getName());
  35. $this->assertEquals('/', $cookie->getPath());
  36. $this->assertNull($cookie->getDomain());
  37. $this->assertTrue($cookie->isCleared());
  38. }
  39. }