2010-12-03 10:52:17 +00:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-26 20:34:11 +00:00
|
|
|
namespace Symfony\Tests\Component\Security\Http\Logout;
|
2010-12-03 10:52:17 +00:00
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2011-07-11 21:54:08 +01:00
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
2010-12-03 10:52:17 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2011-01-26 20:34:11 +00:00
|
|
|
use Symfony\Component\Security\Http\Logout\CookieClearingLogoutHandler;
|
2010-12-03 10:52:17 +00:00
|
|
|
|
|
|
|
class CookieClearingLogoutHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testLogout()
|
|
|
|
{
|
|
|
|
$request = new Request();
|
|
|
|
$response = new Response();
|
2011-01-26 20:34:11 +00:00
|
|
|
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
|
2011-01-15 17:53:30 +00:00
|
|
|
|
2011-02-14 19:24:48 +00:00
|
|
|
$handler = new CookieClearingLogoutHandler(array('foo' => array('path' => '/foo', 'domain' => 'foo.foo'), 'foo2' => array('path' => null, 'domain' => null)));
|
2011-01-15 17:53:30 +00:00
|
|
|
|
2011-07-11 21:54:08 +01:00
|
|
|
$cookies = $response->headers->getCookies();
|
2012-01-18 13:42:47 +00:00
|
|
|
$this->assertCount(0, $cookies);
|
2011-01-15 17:53:30 +00:00
|
|
|
|
2010-12-03 10:52:17 +00:00
|
|
|
$handler->logout($request, $response, $token);
|
2011-01-15 17:53:30 +00:00
|
|
|
|
2011-07-11 21:54:08 +01:00
|
|
|
$cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
2012-01-18 13:42:47 +00:00
|
|
|
$this->assertCount(2, $cookies);
|
2011-01-15 17:53:30 +00:00
|
|
|
|
2011-07-11 21:54:08 +01:00
|
|
|
$cookie = $cookies['foo.foo']['/foo']['foo'];
|
2011-01-15 17:53:30 +00:00
|
|
|
$this->assertEquals('foo', $cookie->getName());
|
2011-02-14 19:24:48 +00:00
|
|
|
$this->assertEquals('/foo', $cookie->getPath());
|
|
|
|
$this->assertEquals('foo.foo', $cookie->getDomain());
|
2011-01-15 17:53:30 +00:00
|
|
|
$this->assertTrue($cookie->isCleared());
|
|
|
|
|
2011-09-28 09:49:50 +01:00
|
|
|
$cookie = $cookies['']['/']['foo2'];
|
2011-01-15 17:53:30 +00:00
|
|
|
$this->assertStringStartsWith('foo2', $cookie->getName());
|
2011-09-28 09:49:50 +01:00
|
|
|
$this->assertEquals('/', $cookie->getPath());
|
2011-02-14 19:24:48 +00:00
|
|
|
$this->assertNull($cookie->getDomain());
|
2011-01-15 17:53:30 +00:00
|
|
|
$this->assertTrue($cookie->isCleared());
|
2010-12-03 10:52:17 +00:00
|
|
|
}
|
2011-01-25 19:28:26 +00:00
|
|
|
}
|