|
@@ 60-75 (lines=16) @@
|
| 57 |
|
$this->assertEquals('max-age=0, no-cache, private', $response->headers->get('Cache-Control')); |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
public function testOnKernelRequestNonMaster() |
| 61 |
|
{ |
| 62 |
|
$request = new Request(); |
| 63 |
|
$request->setMethod('HEAD'); |
| 64 |
|
|
| 65 |
|
$requestMatcher = $this->getRequestMatcher($request, true); |
| 66 |
|
$hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator'); |
| 67 |
|
$hashGenerator->shouldReceive('generateHash')->never(); |
| 68 |
|
|
| 69 |
|
$userContextListener = new UserContextListener($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash'); |
| 70 |
|
$event = $this->getKernelRequestEvent($request, HttpKernelInterface::SUB_REQUEST); |
| 71 |
|
|
| 72 |
|
$userContextListener->onKernelRequest($event); |
| 73 |
|
|
| 74 |
|
$this->assertNull($event->getResponse()); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
public function testOnKernelRequestCached() |
| 78 |
|
{ |
|
@@ 100-117 (lines=18) @@
|
| 97 |
|
$this->assertEquals('max-age=30, public', $response->headers->get('Cache-Control')); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
public function testOnKernelRequestNotMatched() |
| 101 |
|
{ |
| 102 |
|
$request = new Request(); |
| 103 |
|
$request->setMethod('HEAD'); |
| 104 |
|
|
| 105 |
|
$requestMatcher = $this->getRequestMatcher($request, false); |
| 106 |
|
$hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator'); |
| 107 |
|
$hashGenerator->shouldReceive('generateHash')->andReturn('hash'); |
| 108 |
|
|
| 109 |
|
$userContextListener = new UserContextListener($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash'); |
| 110 |
|
$event = $this->getKernelRequestEvent($request); |
| 111 |
|
|
| 112 |
|
$userContextListener->onKernelRequest($event); |
| 113 |
|
|
| 114 |
|
$response = $event->getResponse(); |
| 115 |
|
|
| 116 |
|
$this->assertNull($response); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
public function testOnKernelResponse() |
| 120 |
|
{ |
|
@@ 157-171 (lines=15) @@
|
| 154 |
|
/** |
| 155 |
|
* If there is no hash in the request, vary on the user identifier. |
| 156 |
|
*/ |
| 157 |
|
public function testOnKernelResponseNotCached() |
| 158 |
|
{ |
| 159 |
|
$request = new Request(); |
| 160 |
|
$request->setMethod('HEAD'); |
| 161 |
|
|
| 162 |
|
$requestMatcher = $this->getRequestMatcher($request, false); |
| 163 |
|
$hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator'); |
| 164 |
|
|
| 165 |
|
$userContextListener = new UserContextListener($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash'); |
| 166 |
|
$event = $this->getKernelResponseEvent($request); |
| 167 |
|
|
| 168 |
|
$userContextListener->onKernelResponse($event); |
| 169 |
|
|
| 170 |
|
$this->assertEquals('X-SessionId', $event->getResponse()->headers->get('Vary')); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
/** |
| 174 |
|
* If there is no hash in the request, vary on the user identifier. |