32 $this->layoutMock = $this->getMockForAbstractClass(
33 \
Magento\Framework\View\Layout::class,
39 [
'isCacheable',
'getAllBlocks']
42 $this->configMock = $this->createMock(\
Magento\PageCache\Model\Config::class);
44 $this->model = new \Magento\PageCache\Model\Layout\LayoutPlugin(
60 $this->layoutMock->expects($this->once())->method(
'isCacheable')->will($this->returnValue($layoutIsCacheable));
61 $this->configMock->expects($this->any())->method(
'isEnabled')->will($this->returnValue($cacheState));
63 if ($layoutIsCacheable && $cacheState) {
64 $this->configMock->expects($this->once())->method(
'getTtl')->will($this->returnValue($maxAge));
65 $this->responseMock->expects($this->once())->method(
'setPublicHeaders')->with($maxAge);
67 $this->responseMock->expects($this->never())->method(
'setPublicHeaders');
69 $output = $this->model->afterGenerateXml($this->layoutMock,
$result);
79 'Full_cache state is true, Layout is cache-able' => [
true,
true],
80 'Full_cache state is true, Layout is not cache-able' => [
true,
false],
81 'Full_cache state is false, Layout is not cache-able' => [
false,
false],
82 'Full_cache state is false, Layout is cache-able' => [
false,
true]
94 public function testAfterGetOutput($cacheState, $layoutIsCacheable, $expectedTags, $configCacheType, $ttl)
97 $this->configMock->expects($this->any())->method(
'isEnabled')->will($this->returnValue($cacheState));
98 $blockStub = $this->createPartialMock(
99 \
Magento\PageCache\Test\Unit\Block\Controller\StubBlock::class,
102 $blockStub->setTtl($ttl);
103 $blockStub->expects($this->any())->method(
'getIdentities')->willReturn([
'identity1',
'identity2']);
104 $this->layoutMock->expects($this->once())->method(
'isCacheable')->will($this->returnValue($layoutIsCacheable));
105 $this->layoutMock->expects($this->any())->method(
'getAllBlocks')->will($this->returnValue([$blockStub]));
107 $this->configMock->expects($this->any())->method(
'getType')->will($this->returnValue($configCacheType));
109 if ($layoutIsCacheable && $cacheState) {
110 $this->responseMock->expects($this->once())->method(
'setHeader')->with(
'X-Magento-Tags', $expectedTags);
112 $this->responseMock->expects($this->never())->method(
'setHeader');
114 $output = $this->model->afterGetOutput($this->layoutMock, $html);
115 $this->assertSame(
$output, $html);
123 $tags =
'identity1,identity2';
125 'Cacheable layout, Full_cache state is true' => [
true,
true, $tags,
null, 0],
126 'Non-cacheable layout' => [
true,
false,
null,
null, 0],
128 'Cacheable layout with Varnish, Full_cache state is false' => [
135 'Cacheable layout with Varnish and esi' => [
143 'Cacheable layout with Builtin, Full_cache state is false' => [
150 'Cacheable layout with Builtin and esi' => [
afterGenerateXmlDataProvider()
afterGetOutputDataProvider()
testAfterGenerateXml($cacheState, $layoutIsCacheable)
testAfterGetOutput($cacheState, $layoutIsCacheable, $expectedTags, $configCacheType, $ttl)