2010-11-02 19:00:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-11-02 19:00:18 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-11-02 19:00:18 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-05-31 09:09:25 +01:00
|
|
|
namespace Symfony\Tests\Component\HttpKernel\EventListener;
|
2010-11-02 19:00:18 +00:00
|
|
|
|
2011-01-26 20:38:45 +00:00
|
|
|
use Symfony\Component\HttpKernel\HttpCache\Esi;
|
2011-05-31 09:09:25 +01:00
|
|
|
use Symfony\Component\HttpKernel\EventListener\EsiListener;
|
2011-03-13 18:16:56 +00:00
|
|
|
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
2011-06-21 15:34:33 +01:00
|
|
|
use Symfony\Component\HttpKernel\KernelEvents;
|
2010-11-02 19:00:18 +00:00
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
2011-03-07 14:42:52 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2011-03-13 18:16:56 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
2010-11-02 19:00:18 +00:00
|
|
|
|
|
|
|
class EsiListenerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testFilterDoesNothingForSubRequests()
|
|
|
|
{
|
2011-03-13 18:16:56 +00:00
|
|
|
$dispatcher = new EventDispatcher();
|
2011-03-07 14:42:52 +00:00
|
|
|
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
|
|
|
$response = new Response('foo <esi:include src="" />');
|
2010-11-02 19:00:18 +00:00
|
|
|
$listener = new EsiListener(new Esi());
|
|
|
|
|
2011-06-21 15:34:33 +01:00
|
|
|
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
|
2011-03-13 18:16:56 +00:00
|
|
|
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
|
2011-06-21 15:34:33 +01:00
|
|
|
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
2010-11-02 19:00:18 +00:00
|
|
|
|
2011-03-13 18:16:56 +00:00
|
|
|
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
|
2010-11-02 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFilterWhenThereIsSomeEsiIncludes()
|
|
|
|
{
|
2011-03-13 18:16:56 +00:00
|
|
|
$dispatcher = new EventDispatcher();
|
2011-03-07 14:42:52 +00:00
|
|
|
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
|
|
|
$response = new Response('foo <esi:include src="" />');
|
2010-11-02 19:00:18 +00:00
|
|
|
$listener = new EsiListener(new Esi());
|
|
|
|
|
2011-06-21 15:34:33 +01:00
|
|
|
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
|
2011-03-13 18:16:56 +00:00
|
|
|
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
|
2011-06-21 15:34:33 +01:00
|
|
|
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
2010-11-02 19:00:18 +00:00
|
|
|
|
2011-03-13 18:16:56 +00:00
|
|
|
$this->assertEquals('content="ESI/1.0"', $event->getResponse()->headers->get('Surrogate-Control'));
|
2010-11-02 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFilterWhenThereIsNoEsiIncludes()
|
|
|
|
{
|
2011-03-13 18:16:56 +00:00
|
|
|
$dispatcher = new EventDispatcher();
|
2011-03-07 14:42:52 +00:00
|
|
|
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
|
|
|
$response = new Response('foo');
|
2010-11-02 19:00:18 +00:00
|
|
|
$listener = new EsiListener(new Esi());
|
|
|
|
|
2011-06-21 15:34:33 +01:00
|
|
|
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
|
2011-03-13 18:16:56 +00:00
|
|
|
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
|
2011-06-21 15:34:33 +01:00
|
|
|
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
|
2010-11-02 19:00:18 +00:00
|
|
|
|
2011-03-13 18:16:56 +00:00
|
|
|
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
|
2010-11-02 19:00:18 +00:00
|
|
|
}
|
|
|
|
}
|