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.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-12-03 10:52:17 +00:00
|
|
|
namespace Symfony\Tests\Component\HttpKernel\Security\Logout;
|
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpKernel\Security\Logout\CookieClearingLogoutHandler;
|
|
|
|
|
|
|
|
class CookieClearingLogoutHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testConstructor()
|
|
|
|
{
|
|
|
|
$cookieNames = array('foo', 'foo2', 'foo3');
|
2011-01-15 17:53:30 +00:00
|
|
|
|
2010-12-03 10:52:17 +00:00
|
|
|
$handler = new CookieClearingLogoutHandler($cookieNames);
|
2011-01-15 17:53:30 +00:00
|
|
|
|
2010-12-03 10:52:17 +00:00
|
|
|
$this->assertEquals($cookieNames, $handler->getCookieNames());
|
|
|
|
}
|
2011-01-15 17:53:30 +00:00
|
|
|
|
2010-12-03 10:52:17 +00:00
|
|
|
public function testLogout()
|
|
|
|
{
|
|
|
|
$request = new Request();
|
|
|
|
$response = new Response();
|
|
|
|
$token = $this->getMock('Symfony\Component\Security\Authentication\Token\TokenInterface');
|
2011-01-15 17:53:30 +00:00
|
|
|
|
2010-12-03 10:52:17 +00:00
|
|
|
$handler = new CookieClearingLogoutHandler(array('foo', 'foo2'));
|
2011-01-15 17:53:30 +00:00
|
|
|
|
|
|
|
$this->assertFalse($response->headers->hasCookie('foo'));
|
|
|
|
|
2010-12-03 10:52:17 +00:00
|
|
|
$handler->logout($request, $response, $token);
|
2011-01-15 17:53:30 +00:00
|
|
|
|
|
|
|
$cookies = $response->headers->getCookies();
|
2010-12-03 10:52:17 +00:00
|
|
|
$this->assertEquals(2, count($cookies));
|
2011-01-15 17:53:30 +00:00
|
|
|
|
|
|
|
$cookie = $cookies['foo'];
|
|
|
|
$this->assertEquals('foo', $cookie->getName());
|
|
|
|
$this->assertTrue($cookie->isCleared());
|
|
|
|
|
|
|
|
$cookie = $cookies['foo2'];
|
|
|
|
$this->assertStringStartsWith('foo2', $cookie->getName());
|
|
|
|
$this->assertTrue($cookie->isCleared());
|
2010-12-03 10:52:17 +00:00
|
|
|
}
|
|
|
|
}
|