Skip to content

Commit 6d2516f

Browse files
author
Yaroslav Onischenko
committed
MAGETWO-44250: [Import/Export] Product doesn't exist on backend but still visible on frontend
1 parent 3d6e1cc commit 6d2516f

File tree

2 files changed

+124
-63
lines changed

2 files changed

+124
-63
lines changed

app/code/Magento/PageCache/Model/Controller/Result/BuiltinPlugin.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ public function aroundRenderResult(
6666
) {
6767
$result = $proceed($response);
6868
$usePlugin = $this->registry->registry('use_page_cache_plugin');
69-
if (!$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN
70-
|| !$usePlugin) {
69+
if (!$usePlugin || !$this->config->isEnabled()
70+
|| $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN
71+
) {
7172
return $result;
7273
}
7374

@@ -76,6 +77,16 @@ public function aroundRenderResult(
7677
$response->setHeader('X-Magento-Cache-Control', $cacheControl);
7778
$response->setHeader('X-Magento-Cache-Debug', 'MISS', true);
7879
}
80+
81+
$tagsHeader = $response->getHeader('X-Magento-Tags');
82+
$tags = [];
83+
if ($tagsHeader) {
84+
$tags = explode(',', $tagsHeader->getFieldValue());
85+
$response->clearHeader('X-Magento-Tags');
86+
}
87+
$tags = array_unique(array_merge($tags, [\Magento\PageCache\Model\Cache\Type::CACHE_TAG]));
88+
$response->setHeader('X-Magento-Tags', implode(',', $tags));
89+
7990
$this->kernel->process($response);
8091
return $result;
8192
}

app/code/Magento/PageCache/Test/Unit/Model/Controller/Result/BuiltinPluginTest.php

Lines changed: 111 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,83 +11,133 @@
1111
class BuiltinPluginTest extends \PHPUnit_Framework_TestCase
1212
{
1313
/**
14-
* @param bool $usePlugin
15-
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $getHeaderCount
16-
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setCacheControlHeaderCount
17-
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $setCacheDebugHeaderCount
18-
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $getModeCount
19-
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $processCount
20-
* @dataProvider dataProvider
14+
* @var \Magento\PageCache\Model\Controller\Result\BuiltinPlugin
2115
*/
22-
public function testAroundResult(
23-
$usePlugin, $getHeaderCount, $setCacheControlHeaderCount, $setCacheDebugHeaderCount, $getModeCount,
24-
$processCount
25-
) {
26-
$cacheControl = 'test';
27-
28-
$header = $this->getMockBuilder('Zend\Http\Header\HeaderInterface')
29-
->getMockForAbstractClass();
30-
$header->expects($this->any())->method('getFieldValue')
31-
->willReturn($cacheControl);
32-
33-
$response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
34-
$response->expects($getHeaderCount)
35-
->method('getHeader')
36-
->with('Cache-Control')
37-
->willReturn($header);
38-
$response->expects($setCacheControlHeaderCount)->method('setHeader')
39-
->with('X-Magento-Cache-Control', $cacheControl);
40-
$response->expects($setCacheDebugHeaderCount)->method('setHeader')
41-
->with('X-Magento-Cache-Debug', 'MISS', true);
42-
43-
/** @var \Magento\Framework\Controller\ResultInterface $result */
16+
protected $plugin;
17+
18+
/**
19+
* @var \Magento\Framework\Controller\ResultInterface
20+
*/
21+
protected $subject;
22+
23+
/**
24+
* @var \Closure
25+
*/
26+
protected $closure;
27+
28+
/**
29+
* @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $response;
32+
33+
/**
34+
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $registry;
37+
38+
/**
39+
* @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
protected $state;
42+
43+
/**
44+
* @var \Zend\Http\Header\HeaderInterface|\PHPUnit_Framework_MockObject_MockObject
45+
*/
46+
protected $header;
47+
48+
/**
49+
* @var \Magento\Framework\App\PageCache\Kernel|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
protected $kernel;
52+
53+
protected function setUp()
54+
{
4455
$result = $this->getMock('Magento\Framework\Controller\ResultInterface', [], [], '', false);
45-
$closure = function () use ($result) {
56+
$this->closure = function() use ($result) {
4657
return $result;
4758
};
4859

49-
/** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject $registry */
50-
$registry = $this->getMock('Magento\Framework\Registry', [], [], '', false);
51-
$registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')
52-
->will($this->returnValue($usePlugin));
53-
54-
/** @var \Magento\PageCache\Model\Config|\PHPUnit_Framework_MockObject_MockObject $config */
55-
$config = $this->getMock('Magento\PageCache\Model\Config', [], [], '', false);
56-
$config->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
57-
$config->expects($this->once())->method('getType')
58-
->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN));
60+
$this->header = $this->getMock('Zend\Http\Header\HeaderInterface', [], [], '', false);
61+
$this->subject = $this->getMock('Magento\Framework\Controller\ResultInterface', [], [], '', false);
62+
$this->response = $this->getMock(
63+
'Magento\Framework\App\Response\Http',
64+
['getHeader', 'clearHeader', 'setHeader'],
65+
[],
66+
'',
67+
false
68+
);
69+
$this->response->expects($this->any())->method('getHeader')->willReturnMap(
70+
[
71+
['X-Magento-Tags', $this->header],
72+
['Cache-Control', $this->header]
73+
]
74+
);
5975

60-
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject $state */
61-
$state = $this->getMock('Magento\Framework\App\State', [], [], '', false);
62-
$state->expects($getModeCount)->method('getMode')
63-
->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
76+
$this->registry = $this->getMock('Magento\Framework\Registry', [], [], '', false);
6477

65-
$kernel = $this->getMock('Magento\Framework\App\PageCache\Kernel', [], [], '', false);
66-
$kernel->expects($processCount)->method('process')->with($response);
78+
$config = $this->getMock('Magento\PageCache\Model\Config', ['isEnabled', 'getType'], [], '', false);
79+
$config->expects($this->any())->method('isEnabled')->willReturn(true);
80+
$config->expects($this->any())->method('getType')->willReturn(\Magento\PageCache\Model\Config::BUILT_IN);
6781

68-
$subject = $this->getMock('Magento\Framework\Controller\ResultInterface', [], [], '', false);
82+
$this->kernel = $this->getMock('Magento\Framework\App\PageCache\Kernel', [], [], '', false);
6983

70-
/** @var \Magento\PageCache\Model\Controller\Result\BuiltinPlugin $plugin */
71-
$plugin = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
84+
$this->state = $this->getMock('Magento\Framework\App\State', [], [], '', false);
85+
$this->plugin = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
7286
'Magento\PageCache\Model\Controller\Result\BuiltinPlugin',
7387
[
74-
'registry' => $registry,
88+
'registry' => $this->registry,
7589
'config' => $config,
76-
'kernel' => $kernel,
77-
'state' => $state
90+
'kernel' => $this->kernel,
91+
'state' => $this->state
7892
]
7993
);
80-
$this->assertSame($result, $plugin->aroundRenderResult($subject, $closure, $response));
8194
}
8295

83-
/**
84-
* @return array
85-
*/
86-
public function dataProvider()
96+
public function testAroundResultWithoutPlugin()
8797
{
88-
return [
89-
[true, $this->once(), $this->at(1), $this->at(2), $this->once(), $this->once()],
90-
[false, $this->never(), $this->never(), $this->never(), $this->never(), $this->never()]
91-
];
98+
$this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->willReturn(false);
99+
$this->kernel->expects($this->never())->method('process')->with($this->response);
100+
$this->assertSame(
101+
call_user_func($this->closure),
102+
$this->plugin->aroundRenderResult($this->subject, $this->closure, $this->response)
103+
);
104+
}
105+
106+
public function testAroundResultWithPlugin()
107+
{
108+
$this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->willReturn(true);
109+
$this->state->expects($this->once())->method('getMode')->willReturn(null);
110+
$this->header->expects($this->any())->method('getFieldValue')->willReturn('tag,tag');
111+
$this->response->expects($this->once())->method('clearHeader')->with('X-Magento-Tags');
112+
$this->response->expects($this->once())->method('setHeader')->with(
113+
'X-Magento-Tags',
114+
'tag,' . \Magento\PageCache\Model\Cache\Type::CACHE_TAG
115+
);
116+
$this->kernel->expects($this->once())->method('process')->with($this->response);
117+
$result = call_user_func($this->closure);
118+
$this->assertSame($result, $this->plugin->aroundRenderResult($this->subject, $this->closure, $this->response));
119+
}
120+
121+
public function testAroundResultWithPluginDeveloperMode()
122+
{
123+
$this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->willReturn(true);
124+
$this->state->expects($this->once())->method('getMode')
125+
->willReturn(\Magento\Framework\App\State::MODE_DEVELOPER);
126+
127+
$this->header->expects($this->any())->method('getFieldValue')->willReturnOnConsecutiveCalls('test', 'tag,tag2');
128+
129+
$this->response->expects($this->any())->method('setHeader')->withConsecutive(
130+
['X-Magento-Cache-Control', 'test'],
131+
['X-Magento-Cache-Debug', 'MISS', true],
132+
['X-Magento-Tags', 'tag,tag2,' . \Magento\PageCache\Model\Cache\Type::CACHE_TAG]
133+
);
134+
135+
$this->response->expects($this->once())->method('clearHeader')->with('X-Magento-Tags');
136+
$this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')
137+
->will($this->returnValue(true));
138+
$this->kernel->expects($this->once())->method('process')->with($this->response);
139+
140+
$result = call_user_func($this->closure);
141+
$this->assertSame($result, $this->plugin->aroundRenderResult($this->subject, $this->closure, $this->response));
92142
}
93143
}

0 commit comments

Comments
 (0)