18 private $entitySpecificHandlesListMock;
30 private $_observerMock;
40 $this->_configMock = $this->createPartialMock(\
Magento\PageCache\Model\Config::class, [
'getType',
'isEnabled']);
41 $this->entitySpecificHandlesListMock = $this->createMock(EntitySpecificHandlesList::class);
43 $this->_model = new \Magento\PageCache\Observer\ProcessLayoutRenderElement(
45 $this->entitySpecificHandlesListMock,
46 new \
Magento\Framework\Serialize\Serializer\Json(),
47 new \
Magento\Framework\Serialize\Serializer\Base64Json()
49 $this->_observerMock = $this->createPartialMock(\
Magento\Framework\Event\Observer::class, [
'getEvent']);
50 $this->_layoutMock = $this->createPartialMock(
51 \
Magento\Framework\View\Layout::class,
52 [
'isCacheable',
'getBlock',
'getUpdate',
'getHandles']
54 $this->_blockMock = $this->getMockForAbstractClass(
55 \
Magento\Framework\View\Element\AbstractBlock::class,
61 [
'getData',
'isScopePrivate',
'getNameInLayout',
'getUrl']
63 $this->_transport = new \Magento\Framework\DataObject([
'output' =>
'test output html']);
81 $eventMock = $this->createPartialMock(
82 \
Magento\Framework\Event::class,
83 [
'getLayout',
'getElementName',
'getTransport']
85 $this->_observerMock->expects($this->once())->method(
'getEvent')->will($this->returnValue($eventMock));
86 $eventMock->expects($this->once())->method(
'getLayout')->will($this->returnValue($this->_layoutMock));
87 $this->_configMock->expects($this->any())->method(
'isEnabled')->will($this->returnValue($cacheState));
90 $eventMock->expects($this->once())
91 ->method(
'getElementName')
92 ->will($this->returnValue(
'blockName'));
94 $eventMock->expects($this->once())
95 ->method(
'getTransport')
96 ->will($this->returnValue($this->_transport));
98 $this->_layoutMock->expects($this->once())
99 ->method(
'isCacheable')
100 ->will($this->returnValue(
true));
102 $this->_layoutMock->expects($this->any())
103 ->method(
'getUpdate')
104 ->will($this->returnSelf());
106 $this->_layoutMock->expects($this->any())
107 ->method(
'getHandles')
108 ->will($this->returnValue([
'default',
'catalog_product_view',
'catalog_product_view_id_1']));
110 $this->entitySpecificHandlesListMock->expects($this->any())
111 ->method(
'getHandles')
112 ->will($this->returnValue([
'catalog_product_view_id_1']));
114 $this->_layoutMock->expects($this->once())
116 ->will($this->returnValue($this->_blockMock));
118 if ($varnishIsEnabled) {
119 $this->_blockMock->expects($this->once())
122 ->will($this->returnValue($blockTtl));
123 $this->_blockMock->expects($this->any())
126 'page_cache/block/esi',
127 [
'blocks' =>
'[null]',
128 'handles' =>
'WyJkZWZhdWx0IiwiY2F0YWxvZ19wcm9kdWN0X3ZpZXciXQ==']
132 'page_cache/block/wrapesi/with/handles/WyJkZWZhdWx0IiwiY2F0YWxvZ19wcm9kdWN0X3ZpZXciXQ==' 136 if ($scopeIsPrivate) {
137 $this->_blockMock->expects($this->once())
138 ->method(
'getNameInLayout')
139 ->will($this->returnValue(
'testBlockName'));
140 $this->_blockMock->expects($this->once())
141 ->method(
'isScopePrivate')
142 ->will($this->returnValue($scopeIsPrivate));
144 $this->_configMock->expects($this->any())->method(
'getType')->will($this->returnValue($varnishIsEnabled));
146 $this->_model->execute($this->_observerMock);
148 $this->assertEquals($expectedOutput, $this->_transport[
'output']);
153 $expectedOutput =
'<esi:include src="page_cache/block/wrapesi/with/handles/YW5kL290aGVyL3N0dWZm" />';
154 $eventMock = $this->createPartialMock(
155 \
Magento\Framework\Event::class,
156 [
'getLayout',
'getElementName',
'getTransport']
158 $expectedUrl =
'page_cache/block/wrapesi/with/handles/' . base64_encode(
'and/other/stuff');
160 $this->_observerMock->expects($this->once())->method(
'getEvent')->will($this->returnValue($eventMock));
161 $eventMock->expects($this->once())->method(
'getLayout')->will($this->returnValue($this->_layoutMock));
162 $this->_configMock->expects($this->any())->method(
'isEnabled')->will($this->returnValue(
true));
164 $eventMock->expects($this->once())
165 ->method(
'getElementName')
166 ->will($this->returnValue(
'blockName'));
168 $eventMock->expects($this->once())
169 ->method(
'getTransport')
170 ->will($this->returnValue($this->_transport));
172 $this->_layoutMock->expects($this->once())
173 ->method(
'isCacheable')
174 ->will($this->returnValue(
true));
176 $this->_layoutMock->expects($this->any())
177 ->method(
'getUpdate')
178 ->will($this->returnSelf());
180 $this->_layoutMock->expects($this->any())
181 ->method(
'getHandles')
182 ->will($this->returnValue([]));
184 $this->_layoutMock->expects($this->once())
186 ->will($this->returnValue($this->_blockMock));
188 $this->entitySpecificHandlesListMock->expects($this->any())
189 ->method(
'getHandles')
190 ->will($this->returnValue([
'catalog_product_view_id_1']));
192 $this->_blockMock->expects($this->once())
195 ->will($this->returnValue(100));
196 $this->_blockMock->expects($this->any())
198 ->will($this->returnValue($expectedUrl));
200 $this->_blockMock->expects($this->once())
201 ->method(
'getNameInLayout')
202 ->will($this->returnValue(
'testBlockName'));
204 $this->_configMock->expects($this->any())->method(
'getType')->will($this->returnValue(
true));
206 $this->_model->execute($this->_observerMock);
208 $this->assertEquals($expectedOutput, $this->_transport[
'output']);
219 'full_page type and Varnish enabled, public scope, ttl is set' => [
224 '<esi:include src="page_cache/block/wrapesi/with/handles/' 225 .
'WyJkZWZhdWx0IiwiY2F0YWxvZ19wcm9kdWN0X3ZpZXciXQ==" />',
227 'full_page type and Varnish enabled, public scope, ttl is not set' => [
234 'full_page type enabled, Varnish disabled, public scope, ttl is set' => [
241 'full_page type enabled, Varnish disabled, public scope, ttl is not set' => [
248 'full_page type enabled, Varnish disabled, private scope, ttl is not set' => [
253 '<!-- BLOCK testBlockName -->test output html<!-- /BLOCK testBlockName -->',
255 'full_page type is disabled, Varnish enabled' => [
false,
true,
false,
null,
'test output html']
testExecuteWithBase64Encode()
testExecute( $cacheState, $varnishIsEnabled, $scopeIsPrivate, $blockTtl, $expectedOutput)
processLayoutRenderDataProvider()