Skip to content

Commit 6680740

Browse files
committed
MAGETWO-91388: Enable caching of AJAX requests on Varnish/Fastly
1 parent 066e0d7 commit 6680740

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

app/code/Magento/Swatches/Controller/Ajax/Media.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Class Media
1414
*/
15-
class Media extends \Magento\Framework\App\Action\Action
15+
class Media extends \Magento\Framework\App\Action\Action implements \Magento\Framework\App\Action\HttpGetActionInterface
1616
{
1717
/**
1818
* @var \Magento\Catalog\Model\Product Factory

app/code/Magento/Swatches/Test/Unit/Controller/Ajax/MediaTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class MediaTest extends \PHPUnit\Framework\TestCase
2020
/** @var \Magento\Catalog\Model\ProductFactory|\PHPUnit_Framework_MockObject_MockObject */
2121
private $productModelFactoryMock;
2222

23+
/** @var \Magento\PageCache\Model\Config|\PHPUnit_Framework_MockObject_MockObject */
24+
private $config;
25+
2326
/** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */
2427
private $productMock;
2528

@@ -29,6 +32,9 @@ class MediaTest extends \PHPUnit\Framework\TestCase
2932
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
3033
private $requestMock;
3134

35+
/** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */
36+
private $responseMock;
37+
3238
/** @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */
3339
private $resultFactory;
3440

@@ -57,11 +63,20 @@ protected function setUp()
5763
\Magento\Catalog\Model\ProductFactory::class,
5864
['create']
5965
);
66+
$this->config = $this->createMock(\Magento\PageCache\Model\Config::class);
67+
$this->config->method('getTtl')->willReturn(1);
68+
6069
$this->productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
6170
$this->contextMock = $this->createMock(\Magento\Framework\App\Action\Context::class);
6271

6372
$this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
6473
$this->contextMock->method('getRequest')->willReturn($this->requestMock);
74+
$this->responseMock = $this->getMockBuilder(\Magento\Framework\App\ResponseInterface::class)
75+
->disableOriginalConstructor()
76+
->setMethods(['setPublicHeaders'])
77+
->getMockForAbstractClass();
78+
$this->responseMock->method('setPublicHeaders')->willReturnSelf();
79+
$this->contextMock->method('getResponse')->willReturn($this->responseMock);
6580
$this->resultFactory = $this->createPartialMock(\Magento\Framework\Controller\ResultFactory::class, ['create']);
6681
$this->contextMock->method('getResultFactory')->willReturn($this->resultFactory);
6782

@@ -73,7 +88,8 @@ protected function setUp()
7388
[
7489
'context' => $this->contextMock,
7590
'swatchHelper' => $this->swatchHelperMock,
76-
'productModelFactory' => $this->productModelFactoryMock
91+
'productModelFactory' => $this->productModelFactoryMock,
92+
'config' => $this->config
7793
]
7894
);
7995
}
@@ -86,6 +102,10 @@ public function testExecute()
86102
->method('load')
87103
->with(59)
88104
->willReturn($this->productMock);
105+
$this->productMock
106+
->expects($this->once())
107+
->method('getIdentities')
108+
->willReturn(['tags']);
89109

90110
$this->productModelFactoryMock
91111
->expects($this->once())

app/code/Magento/Swatches/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"magento/module-configurable-product": "*",
1414
"magento/module-customer": "*",
1515
"magento/module-eav": "*",
16+
"magento/module-page-cache": "*",
1617
"magento/module-media-storage": "*",
1718
"magento/module-store": "*",
1819
"magento/module-theme": "*"

0 commit comments

Comments
 (0)