/**
* @dataProvider getConfigureParams
*
* @param Response $response
* @param Request $request
* @param int $lifetime
* @param array $private_headers
* @param bool $expected_public
*/
public function testConfigure(Response $response, Request $request, $lifetime, array $private_headers, $expected_public)
{
$last_modified = new \DateTime();
if ($response->getEtag()) {
$etag = $response->getEtag();
} else {
$etag = md5('bar');
$this->key_builder->expects($this->once())->method('getEtag')->with($response)->will($this->returnValue($etag));
$etag = '"' . $etag . '"';
}
$this->request_stack->expects($this->once())->method('getMasterRequest')->will($this->returnValue($request));
$expires = null;
if ($lifetime >= 0) {
$expires = clone $last_modified;
$expires->modify(sprintf('now +%s seconds', $lifetime));
}
$configurator = new ResponseConfigurator($this->key_builder, $this->request_stack, $private_headers);
// exec test method
$configured_response = $configurator->configure($response, $last_modified, $lifetime);
$this->assertEquals($response, $configured_response);
$this->assertEquals($last_modified, $response->getLastModified());
$this->assertEquals($etag, $response->getEtag());
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertTrue($response->headers->hasCacheControlDirective($expected_public ? 'public' : 'private'));
if ($lifetime >= 0) {
$this->assertEquals($lifetime, $response->headers->getCacheControlDirective('max-age'));
$this->assertEquals($expires, $response->getExpires());
if ($expected_public) {
$this->assertEquals($lifetime, $response->headers->getCacheControlDirective('s-maxage'));
}
}
}