Skip to content

Commit 79ebeb7

Browse files
committed
ACP2E-2015: Customizable Option Image link is broken
1 parent 44dc316 commit 79ebeb7

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\PageCache\Model\App\FrontController;
77

8+
use Magento\Framework\App\PageCache\NotCacheableInterface;
89
use Magento\Framework\App\Response\Http as ResponseHttp;
910

1011
/**
@@ -73,7 +74,7 @@ public function aroundDispatch(
7374
$result = $this->kernel->load();
7475
if ($result === false) {
7576
$result = $proceed($request);
76-
if ($result instanceof ResponseHttp) {
77+
if ($result instanceof ResponseHttp && !$result instanceof NotCacheableInterface) {
7778
$this->addDebugHeaders($result);
7879
$this->kernel->process($result);
7980
}

app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Laminas\Http\Header\GenericHeader;
1212
use Magento\Framework\App\FrontControllerInterface;
1313
use Magento\Framework\App\PageCache\Kernel;
14+
use Magento\Framework\App\PageCache\NotCacheableInterface;
1415
use Magento\Framework\App\PageCache\Version;
1516
use Magento\Framework\App\RequestInterface;
1617
use Magento\Framework\App\Response\Http;
@@ -243,6 +244,41 @@ public function testAroundDispatchDisabled($state): void
243244
);
244245
}
245246

247+
/**
248+
* @return void
249+
*/
250+
public function testAroundNotCacheableResponse(): void
251+
{
252+
$this->configMock
253+
->expects($this->once())
254+
->method('getType')
255+
->willReturn(Config::BUILT_IN);
256+
$this->configMock->expects($this->once())
257+
->method('isEnabled')
258+
->willReturn(true);
259+
$this->versionMock
260+
->expects($this->once())
261+
->method('process');
262+
$this->kernelMock->expects($this->once())
263+
->method('load')
264+
->willReturn(false);
265+
$this->stateMock->expects($this->never())
266+
->method('getMode');
267+
$this->kernelMock->expects($this->never())
268+
->method('process');
269+
$this->responseMock->expects($this->never())
270+
->method('setHeader');
271+
$notCacheableResponse = $this->createMock(NotCacheableInterface::class);
272+
$this->assertSame(
273+
$notCacheableResponse,
274+
$this->plugin->aroundDispatch(
275+
$this->frontControllerMock,
276+
fn () => $notCacheableResponse,
277+
$this->requestMock
278+
)
279+
);
280+
}
281+
246282
/**
247283
* @return array
248284
*/

lib/internal/Magento/Framework/App/PageCache/Kernel.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
/**
1212
* Builtin cache processor
13+
*
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1315
*/
1416
class Kernel
1517
{
@@ -140,6 +142,7 @@ public function process(\Magento\Framework\App\Response\Http $response)
140142
$maxAge = $matches[1];
141143
$response->setNoCacheHeaders();
142144
if (($response->getHttpResponseCode() == 200 || $response->getHttpResponseCode() == 404)
145+
&& !$response instanceof NotCacheableInterface
143146
&& ($this->request->isGet() || $this->request->isHead())
144147
) {
145148
$tagsHeader = $response->getHeader('X-Magento-Tags');

lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\App\PageCache\Cache;
1515
use Magento\Framework\App\PageCache\Identifier;
1616
use Magento\Framework\App\PageCache\Kernel;
17+
use Magento\Framework\App\PageCache\NotCacheableInterface;
1718
use Magento\Framework\App\Request\Http;
1819
use Magento\Framework\App\Response\HttpFactory;
1920
use Magento\Framework\Serialize\SerializerInterface;
@@ -328,4 +329,28 @@ public function processNotSaveCacheProvider(): array
328329
['public, max-age=100, s-maxage=100', 200, false, true]
329330
];
330331
}
332+
333+
public function testProcessNotSaveCacheForNotCacheableResponse(): void
334+
{
335+
$header = CacheControl::fromString("Cache-Control: public, max-age=100, s-maxage=100");
336+
$notCacheableResponse = $this->getMockBuilder(\Magento\Framework\App\Response\File::class)
337+
->disableOriginalConstructor()
338+
->getMock();
339+
340+
$notCacheableResponse->expects($this->once())
341+
->method('getHeader')
342+
->with('Cache-Control')
343+
->willReturn($header);
344+
$notCacheableResponse->expects($this->any())
345+
->method('getHttpResponseCode')
346+
->willReturn(200);
347+
$notCacheableResponse->expects($this->once())
348+
->method('setNoCacheHeaders');
349+
$this->requestMock
350+
->expects($this->any())->method('isGet')
351+
->willReturn(true);
352+
$this->fullPageCacheMock->expects($this->never())
353+
->method('save');
354+
$this->kernel->process($notCacheableResponse);
355+
}
331356
}

0 commit comments

Comments
 (0)