This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/HttpKernel/EventListener/EsiListenerTest.php

67 lines
2.7 KiB
PHP
Raw Normal View History

2010-11-02 19:00:18 +00:00
<?php
/*
* This file is part of the Symfony package.
2010-11-02 19:00:18 +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.
*/
namespace Symfony\Tests\Component\HttpKernel\EventListener;
2010-11-02 19:00:18 +00:00
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpKernel\EventListener\EsiListener;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
2010-11-02 19:00:18 +00:00
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcher;
2010-11-02 19:00:18 +00:00
class EsiListenerTest extends \PHPUnit_Framework_TestCase
{
public function testFilterDoesNothingForSubRequests()
{
$dispatcher = new EventDispatcher();
$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());
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
2010-11-02 19:00:18 +00:00
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
2010-11-02 19:00:18 +00:00
}
public function testFilterWhenThereIsSomeEsiIncludes()
{
$dispatcher = new EventDispatcher();
$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());
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
2010-11-02 19:00:18 +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()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$response = new Response('foo');
2010-11-02 19:00:18 +00:00
$listener = new EsiListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
2010-11-02 19:00:18 +00:00
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
2010-11-02 19:00:18 +00:00
}
}