CookieClearingLogoutHandlerTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Component\Security\Http\Tests\Logout;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  15. use Symfony\Component\Security\Http\Logout\CookieClearingLogoutHandler;
  16. class CookieClearingLogoutHandlerTest extends TestCase
  17. {
  18. public function testLogout()
  19. {
  20. $request = new Request();
  21. $response = new Response();
  22. $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
  23. $handler = new CookieClearingLogoutHandler(array('foo' => array('path' => '/foo', 'domain' => 'foo.foo'), 'foo2' => array('path' => null, 'domain' => null)));
  24. $cookies = $response->headers->getCookies();
  25. $this->assertCount(0, $cookies);
  26. $handler->logout($request, $response, $token);
  27. $cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
  28. $this->assertCount(2, $cookies);
  29. $cookie = $cookies['foo.foo']['/foo']['foo'];
  30. $this->assertEquals('foo', $cookie->getName());
  31. $this->assertEquals('/foo', $cookie->getPath());
  32. $this->assertEquals('foo.foo', $cookie->getDomain());
  33. $this->assertTrue($cookie->isCleared());
  34. $cookie = $cookies['']['/']['foo2'];
  35. $this->assertStringStartsWith('foo2', $cookie->getName());
  36. $this->assertEquals('/', $cookie->getPath());
  37. $this->assertNull($cookie->getDomain());
  38. $this->assertTrue($cookie->isCleared());
  39. }
  40. }