Skip to content

Commit 43553a2

Browse files
author
mtanniru
committed
Merge remote-tracking branch 'origin/MAGETWO-55682-backport_55514_2.0.x' into MAGETWO-55682-backport_55514_2.0.x
2 parents cf3d738 + 19fab2b commit 43553a2

File tree

10 files changed

+522
-56
lines changed

10 files changed

+522
-56
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\Indexer\Category;
8+
9+
/**
10+
* Class AffectCache
11+
* @deprecated
12+
*/
13+
class AffectCache
14+
{
15+
/**
16+
* @var \Magento\Framework\Indexer\CacheContext
17+
*/
18+
protected $context;
19+
20+
/**
21+
* @param \Magento\Framework\Indexer\CacheContext $context
22+
*/
23+
public function __construct(
24+
\Magento\Framework\Indexer\CacheContext $context
25+
) {
26+
$this->context = $context;
27+
}
28+
29+
/**
30+
* @param \Magento\Framework\Indexer\ActionInterface $subject
31+
* @param array $ids
32+
* @return array
33+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
34+
*/
35+
public function beforeExecute(\Magento\Framework\Indexer\ActionInterface $subject, $ids)
36+
{
37+
$this->context->registerEntities(\Magento\Catalog\Model\Category::CACHE_TAG, $ids);
38+
return [$ids];
39+
}
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\Indexer\Product;
8+
9+
/**
10+
* Class AffectCache
11+
* @deprecated
12+
*/
13+
class AffectCache
14+
{
15+
/**
16+
* @var \Magento\Framework\Indexer\CacheContext $context
17+
*/
18+
protected $context;
19+
20+
/**
21+
* @param \Magento\Framework\Indexer\CacheContext $context
22+
*/
23+
public function __construct(
24+
\Magento\Framework\Indexer\CacheContext $context
25+
) {
26+
$this->context = $context;
27+
}
28+
29+
/**
30+
* @param \Magento\Framework\Indexer\ActionInterface $subject
31+
* @param array $ids
32+
* @return array
33+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
34+
*/
35+
public function beforeExecute(\Magento\Framework\Indexer\ActionInterface $subject, $ids)
36+
{
37+
$this->context->registerEntities(\Magento\Catalog\Model\Product::CACHE_TAG, $ids);
38+
return [$ids];
39+
}
40+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
9+
namespace Magento\Catalog\Test\Unit\Model\Indexer\Category;
10+
11+
/**
12+
* Class AffectCacheTest
13+
* @deprecated
14+
*/
15+
class AffectCacheTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var \Magento\Catalog\Model\Indexer\Category\AffectCache
19+
*/
20+
protected $plugin;
21+
22+
/**
23+
* @var \Magento\Framework\Indexer\CacheContext|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
protected $contextMock;
26+
27+
/**
28+
* @var \Magento\Framework\Indexer\ActionInterface|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
protected $subjectMock;
31+
32+
/**
33+
* Set up
34+
*/
35+
public function setUp()
36+
{
37+
$this->subjectMock = $this->getMockForAbstractClass('Magento\Framework\Indexer\ActionInterface',
38+
[], '', false, true, true, []);
39+
$this->contextMock = $this->getMock('Magento\Framework\Indexer\CacheContext',
40+
[], [], '', false);
41+
$this->plugin = new \Magento\Catalog\Model\Indexer\Category\AffectCache($this->contextMock);
42+
}
43+
44+
/**
45+
* test beforeExecute
46+
*/
47+
public function testBeforeExecute()
48+
{
49+
$expectedIds = [5, 6, 7];
50+
$this->contextMock->expects($this->once())
51+
->method('registerEntities')
52+
->with($this->equalTo(\Magento\Catalog\Model\Category::ENTITY),
53+
$this->equalTo($expectedIds))
54+
->will($this->returnValue($this->contextMock));
55+
$actualIds = $this->plugin->beforeExecute($this->subjectMock, $expectedIds);
56+
$this->assertEquals([$expectedIds], $actualIds);
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
9+
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product;
10+
11+
/**
12+
* Class AffectCacheTest
13+
* @deprecated
14+
*/
15+
class AffectCacheTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var \Magento\PageCache\Model\Indexer\Product\RefreshPlugin
19+
*/
20+
protected $plugin;
21+
22+
/**
23+
* @var \Magento\Framework\Indexer\CacheContext|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
protected $contextMock;
26+
27+
/**
28+
* @var \Magento\Framework\Indexer\ActionInterface|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
protected $subjectMock;
31+
32+
/**
33+
* Set up
34+
*/
35+
public function setUp()
36+
{
37+
$this->subjectMock = $this->getMockForAbstractClass('Magento\Framework\Indexer\ActionInterface',
38+
[], '', false, true, true, []);
39+
$this->contextMock = $this->getMock('Magento\Framework\Indexer\CacheContext',
40+
[], [], '', false);
41+
$this->plugin = new \Magento\Catalog\Model\Indexer\Product\AffectCache($this->contextMock);
42+
}
43+
44+
/**
45+
* test beforeExecute
46+
*/
47+
public function testBeforeExecute()
48+
{
49+
$expectedIds = [1, 2, 3];
50+
$this->contextMock->expects($this->once())
51+
->method('registerEntities')
52+
->with($this->equalTo(\Magento\Catalog\Model\Product::ENTITY),
53+
$this->equalTo($expectedIds))
54+
->will($this->returnValue($this->contextMock));
55+
$actualIds = $this->plugin->beforeExecute($this->subjectMock, $expectedIds);
56+
$this->assertEquals([$expectedIds], $actualIds);
57+
}
58+
}

app/code/Magento/Catalog/Test/Unit/Pricing/Render/FinalPriceBoxTest.php

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase
4444
/**
4545
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
4646
*/
47-
protected $logger;
47+
protected $loggerMock;
4848

4949
/**
5050
* @var \Magento\Framework\Pricing\Render\RendererPool|\PHPUnit_Framework_MockObject_MockObject
@@ -58,6 +58,7 @@ class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase
5858

5959
protected function setUp()
6060
{
61+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
6162
$this->product = $this->getMock(
6263
'Magento\Catalog\Model\Product',
6364
['getPriceInfo', '__wakeup', 'getCanShowPrice'],
@@ -70,71 +71,30 @@ protected function setUp()
7071
->method('getPriceInfo')
7172
->will($this->returnValue($this->priceInfo));
7273

73-
$eventManager = $this->getMock('Magento\Framework\Event\Test\Unit\ManagerStub', [], [], '', false);
74-
$config = $this->getMock('Magento\Store\Model\Store\Config', [], [], '', false);
7574
$this->layout = $this->getMock('Magento\Framework\View\Layout', [], [], '', false);
7675

7776
$this->priceBox = $this->getMock('Magento\Framework\Pricing\Render\PriceBox', [], [], '', false);
78-
$this->logger = $this->getMock('Psr\Log\LoggerInterface');
77+
$this->loggerMock = $this->getMock('Psr\Log\LoggerInterface');
7978

8079
$this->layout->expects($this->any())
8180
->method('getBlock')
8281
->will($this->returnValue($this->priceBox));
8382

84-
$cacheState = $this->getMockBuilder(\Magento\Framework\App\Cache\StateInterface::class)
85-
->getMockForAbstractClass();
86-
87-
$appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
88-
->disableOriginalConstructor()
89-
->getMock();
90-
91-
$resolver = $this->getMockBuilder(\Magento\Framework\View\Element\Template\File\Resolver::class)
92-
->disableOriginalConstructor()
93-
->getMock();
94-
95-
$urlBuilder = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
96-
->getMockForAbstractClass();
97-
9883
$store = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
9984
->getMockForAbstractClass();
10085

101-
$storeManager = $this->getMockBuilder('\Magento\Store\Model\StoreManagerInterface')
86+
$storeManagerMock = $this->getMockBuilder('\Magento\Store\Model\StoreManagerInterface')
10287
->setMethods(['getStore', 'getCode'])
10388
->getMockForAbstractClass();
104-
$storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
105-
106-
$scopeConfigMock = $this->getMockForAbstractClass('Magento\Framework\App\Config\ScopeConfigInterface');
107-
$context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
108-
$context->expects($this->any())
109-
->method('getEventManager')
110-
->will($this->returnValue($eventManager));
111-
$context->expects($this->any())
112-
->method('getStoreConfig')
113-
->will($this->returnValue($config));
114-
$context->expects($this->any())
115-
->method('getLayout')
116-
->will($this->returnValue($this->layout));
117-
$context->expects($this->any())
118-
->method('getLogger')
119-
->will($this->returnValue($this->logger));
120-
$context->expects($this->any())
121-
->method('getScopeConfig')
122-
->will($this->returnValue($scopeConfigMock));
123-
$context->expects($this->any())
124-
->method('getCacheState')
125-
->will($this->returnValue($cacheState));
126-
$context->expects($this->any())
127-
->method('getStoreManager')
128-
->will($this->returnValue($storeManager));
129-
$context->expects($this->any())
130-
->method('getAppState')
131-
->will($this->returnValue($appState));
132-
$context->expects($this->any())
133-
->method('getResolver')
134-
->will($this->returnValue($resolver));
135-
$context->expects($this->any())
136-
->method('getUrlBuilder')
137-
->will($this->returnValue($urlBuilder));
89+
$storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store));
90+
91+
$context = $objectManager->getObject(
92+
'Magento\Framework\View\Element\Template\Context',
93+
[
94+
'storeManager' => $storeManagerMock,
95+
'logger' => $this->loggerMock
96+
]
97+
);
13898

13999
$this->rendererPool = $this->getMockBuilder('Magento\Framework\Pricing\Render\RendererPool')
140100
->disableOriginalConstructor()
@@ -145,7 +105,6 @@ protected function setUp()
145105
->method('getPriceCode')
146106
->will($this->returnValue(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE));
147107

148-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
149108
$this->object = $objectManager->getObject(
150109
'Magento\Catalog\Pricing\Render\FinalPriceBox',
151110
[
@@ -224,7 +183,7 @@ public function testRenderMsrpEnabled()
224183

225184
public function testRenderMsrpNotRegisteredException()
226185
{
227-
$this->logger->expects($this->once())
186+
$this->loggerMock->expects($this->once())
228187
->method('critical');
229188

230189
$this->priceInfo->expects($this->once())
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Indexer\Model\Processor;
8+
9+
/**
10+
* Class InvalidateCache
11+
* @deprecated
12+
*/
13+
class InvalidateCache
14+
{
15+
/**
16+
* @var \Magento\Framework\Indexer\CacheContext
17+
*/
18+
protected $context;
19+
20+
/**
21+
* @var \Magento\Framework\Event\Manager
22+
*/
23+
protected $eventManager;
24+
25+
/**
26+
* @var \Magento\Framework\Module\Manager
27+
*/
28+
protected $moduleManager;
29+
30+
/**
31+
* @param \Magento\Framework\Indexer\CacheContext $context
32+
* @param \Magento\Framework\Event\Manager $eventManager
33+
* @param \Magento\Framework\Module\Manager $moduleManager
34+
*/
35+
public function __construct(
36+
\Magento\Framework\Indexer\CacheContext $context,
37+
\Magento\Framework\Event\Manager $eventManager,
38+
\Magento\Framework\Module\Manager $moduleManager
39+
) {
40+
$this->context = $context;
41+
$this->eventManager = $eventManager;
42+
$this->moduleManager = $moduleManager;
43+
}
44+
45+
/**
46+
* Update indexer views
47+
*
48+
* @param \Magento\Indexer\Model\Processor $subject
49+
* @return void
50+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
51+
*/
52+
public function afterUpdateMview(\Magento\Indexer\Model\Processor $subject)
53+
{
54+
if ($this->moduleManager->isEnabled('Magento_PageCache')) {
55+
$this->eventManager->dispatch('clean_cache_after_reindex', ['object' => $this->context]);
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)