8 use \Magento\Framework\App\PageCache\Kernel;
9 use \Magento\Framework\App\Http\ContextFactory;
10 use \Magento\Framework\App\Response\HttpFactory;
33 private $fullPageCacheMock;
36 private $httpResponseMock;
39 private $contextFactoryMock;
42 private $httpFactoryMock;
55 $headersMock = $this->createMock(\
Zend\
Http\Headers::class);
56 $this->cacheMock = $this->createMock(\
Magento\Framework\
App\PageCache\Cache::class);
57 $this->fullPageCacheMock = $this->createMock(\
Magento\PageCache\Model\
Cache\Type::class);
58 $this->contextMock = $this->createMock(\
Magento\Framework\
App\
Http\Context::class);
59 $this->httpResponseMock = $this->createMock(\
Magento\Framework\
App\
Response\Http::class);
60 $this->identifierMock = $this->createMock(\
Magento\Framework\
App\PageCache\Identifier::class);
61 $this->requestMock = $this->createMock(\
Magento\Framework\
App\Request\Http::class);
62 $this->serializer = $this->createMock(\
Magento\Framework\
Serialize\SerializerInterface::class);
64 $this->contextFactoryMock = $this->createPartialMock(ContextFactory::class, [
'create']);
65 $this->httpFactoryMock = $this->createPartialMock(HttpFactory::class, [
'create']);
66 $this->responseMock->expects($this->any())->method(
'getHeaders')->willReturn($headersMock);
68 $this->kernel =
new Kernel(
70 $this->identifierMock,
73 $this->contextFactoryMock,
74 $this->httpFactoryMock,
78 $reflection = new \ReflectionClass(\
Magento\Framework\
App\PageCache\Kernel::class);
79 $reflectionProperty = $reflection->getProperty(
'fullPageCache');
80 $reflectionProperty->setAccessible(
true);
81 $reflectionProperty->setValue($this->kernel, $this->fullPageCacheMock);
93 $this->serializer->expects($this->once())
94 ->method(
'unserialize')
97 return json_decode(
$value,
true);
101 $this->contextFactoryMock
102 ->expects($this->once())
106 'data' => [
'context_data'],
107 'default' => [
'context_default_data']
110 ->willReturn($this->contextMock);
112 $this->httpFactoryMock
113 ->expects($this->once())
115 ->with([
'context' => $this->contextMock])
116 ->willReturn($this->httpResponseMock);
118 $this->requestMock->expects($this->once())->method(
'isGet')->will($this->returnValue($isGet));
119 $this->requestMock->expects($this->any())->method(
'isHead')->will($this->returnValue($isHead));
120 $this->fullPageCacheMock->expects(
127 $this->returnValue(json_encode(
$cache))
129 $this->httpResponseMock->expects($this->once())->method(
'setStatusCode')->with(
$cache[
'status_code']);
130 $this->httpResponseMock->expects($this->once())->method(
'setContent')->with(
$cache[
'content']);
131 $this->httpResponseMock->expects($this->once())->method(
'setHeader')->with(0,
'header',
true);
132 $this->identifierMock->expects($this->any())->method(
'getValue')->will($this->returnValue(
$id));
133 $this->assertEquals($this->httpResponseMock, $this->kernel->load());
143 'data' => [
'context_data'],
144 'default' => [
'context_default_data']
146 'status_code' =>
'status_code',
147 'content' =>
'content',
148 'headers' => [
'header']
152 [
'existing key',
$data,
true,
false],
153 [
'existing key',
$data,
false,
true],
166 $this->requestMock->expects($this->once())->method(
'isGet')->will($this->returnValue($isGet));
167 $this->requestMock->expects($this->any())->method(
'isHead')->will($this->returnValue($isHead));
168 $this->fullPageCacheMock->expects(
175 $this->returnValue(json_encode(
$cache))
177 $this->identifierMock->expects($this->any())->method(
'getValue')->will($this->returnValue(
$id));
178 $this->assertEquals(
false, $this->kernel->load());
187 [
'existing key', [],
false,
false],
188 [
'non existing key',
false,
true,
false],
189 [
'non existing key',
false,
false,
false]
199 $this->serializer->expects($this->once())
200 ->method(
'serialize')
201 ->willReturnCallback(
203 return json_encode(
$value);
207 $cacheControlHeader = \Zend\Http\Header\CacheControl::fromString(
208 'Cache-Control: public, max-age=100, s-maxage=100' 211 $this->responseMock->expects(
218 $this->returnValue($cacheControlHeader)
220 $this->responseMock->expects(
223 'getHttpResponseCode' 224 )->willReturn($httpCode);
225 $this->requestMock->expects($this->once())
228 $this->responseMock->expects($this->once())
229 ->method(
'setNoCacheHeaders');
230 $this->responseMock->expects($this->at($at[0]))
231 ->method(
'getHeader')
232 ->with(
'X-Magento-Tags');
233 $this->responseMock->expects($this->at($at[1]))
234 ->method(
'clearHeader')
235 ->with($this->equalTo(
'Set-Cookie'));
236 $this->responseMock->expects($this->at($at[2]))
237 ->method(
'clearHeader')
238 ->with($this->equalTo(
'X-Magento-Tags'));
239 $this->fullPageCacheMock->expects($this->once())
241 $this->kernel->process($this->responseMock);
264 $header = \Zend\Http\Header\CacheControl::fromString(
"Cache-Control: $cacheControlHeader");
265 $this->responseMock->expects(
272 $this->returnValue($header)
274 $this->responseMock->expects($this->any())->method(
'getHttpResponseCode')->will($this->returnValue($httpCode));
275 $this->requestMock->expects($this->any())->method(
'isGet')->will($this->returnValue($isGet));
276 if ($overrideHeaders) {
277 $this->responseMock->expects($this->once())->method(
'setNoCacheHeaders');
279 $this->fullPageCacheMock->expects($this->never())->method(
'save');
280 $this->kernel->process($this->responseMock);
289 [
'private, max-age=100', 200,
true,
false],
290 [
'private, max-age=100', 200,
false,
false],
291 [
'private, max-age=100', 500,
true,
false],
292 [
'no-store, no-cache, must-revalidate, max-age=0', 200,
true,
false],
293 [
'no-store, no-cache, must-revalidate, max-age=0', 200,
false,
false],
294 [
'no-store, no-cache, must-revalidate, max-age=0', 404,
true,
false],
295 [
'no-store, no-cache, must-revalidate, max-age=0', 500,
true,
false],
296 [
'public, max-age=100, s-maxage=100', 500,
true,
true],
297 [
'public, max-age=100, s-maxage=100', 200,
false,
true]
testProcessSaveCache($httpCode, $at)
dataProviderForResultWithCachedData()
processNotSaveCacheProvider()
testProcessSaveCacheDataProvider()
dataProviderForResultWithoutCachedData()
testLoadWithCachedData($id, $cache, $isGet, $isHead)
testLoadWithoutCachedData($id, $cache, $isGet, $isHead)
testProcessNotSaveCache($cacheControlHeader, $httpCode, $isGet, $overrideHeaders)