CookieClearingLogoutHandlerTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 testLogout()
  17. {
  18. $request = new Request();
  19. $response = new Response();
  20. $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
  21. $handler = new CookieClearingLogoutHandler(array('foo' => array('path' => '/foo', 'domain' => 'foo.foo'), 'foo2' => array('path' => null, 'domain' => null)));
  22. $this->assertFalse($response->headers->hasCookie('foo'));
  23. $handler->logout($request, $response, $token);
  24. $cookies = $response->headers->getCookies();
  25. $this->assertEquals(2, count($cookies));
  26. $cookie = $cookies['foo'];
  27. $this->assertEquals('foo', $cookie->getName());
  28. $this->assertEquals('/foo', $cookie->getPath());
  29. $this->assertEquals('foo.foo', $cookie->getDomain());
  30. $this->assertTrue($cookie->isCleared());
  31. $cookie = $cookies['foo2'];
  32. $this->assertStringStartsWith('foo2', $cookie->getName());
  33. $this->assertNull($cookie->getPath());
  34. $this->assertNull($cookie->getDomain());
  35. $this->assertTrue($cookie->isCleared());
  36. }
  37. }