Skip to content

Commit 757f79c

Browse files
committed
MAGETWO-64282: Out of stock associated products to configurable are not full page cache cleaned #8009
- Fix tests.
1 parent 53b0f19 commit 757f79c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

app/code/Magento/CatalogInventory/Model/Indexer/Stock/CacheCleaner.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public function __construct(
7575
}
7676

7777
/**
78+
* Clean cache by product ids.
79+
*
7880
* @param array $productIds
7981
* @param callable $reindex
8082
* @return void
@@ -92,6 +94,8 @@ public function clean(array $productIds, callable $reindex)
9294
}
9395

9496
/**
97+
* Get current stock statuses for product ids.
98+
*
9599
* @param array $productIds
96100
* @return array
97101
*/
@@ -158,6 +162,8 @@ private function getProductIdsForCacheClean(array $productStatusesBefore, array
158162
}
159163

160164
/**
165+
* Get database connection.
166+
*
161167
* @return AdapterInterface
162168
*/
163169
private function getConnection()

app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/CacheCleanerTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\DB\Adapter\AdapterInterface;
1313
use Magento\Framework\DB\Select;
1414
use Magento\Framework\Event\ManagerInterface;
15+
use Magento\Framework\EntityManager\MetadataPool;
1516
use Magento\Framework\Indexer\CacheContext;
1617
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1718
use Magento\Catalog\Model\Product;
@@ -43,6 +44,11 @@ class CacheCleanerTest extends \PHPUnit\Framework\TestCase
4344
*/
4445
private $cacheContextMock;
4546

47+
/**
48+
* @var MetadataPool |\PHPUnit_Framework_MockObject_MockObject
49+
*/
50+
private $metadataPoolMock;
51+
4652
/**
4753
* @var StockConfigurationInterface|\PHPUnit_Framework_MockObject_MockObject
4854
*/
@@ -61,6 +67,8 @@ protected function setUp()
6167
->setMethods(['getStockThresholdQty'])->getMockForAbstractClass();
6268
$this->cacheContextMock = $this->getMockBuilder(CacheContext::class)->disableOriginalConstructor()->getMock();
6369
$this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->getMock();
70+
$this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class)
71+
->setMethods(['getMetadata', 'getLinkField'])->disableOriginalConstructor()->getMock();
6472
$this->selectMock = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
6573

6674
$this->resourceMock->expects($this->any())
@@ -73,7 +81,8 @@ protected function setUp()
7381
'resource' => $this->resourceMock,
7482
'stockConfiguration' => $this->stockConfigurationMock,
7583
'cacheContext' => $this->cacheContextMock,
76-
'eventManager' => $this->eventManagerMock
84+
'eventManager' => $this->eventManagerMock,
85+
'metadataPool' => $this->metadataPoolMock
7786
]
7887
);
7988
}
@@ -90,6 +99,7 @@ public function testClean($stockStatusBefore, $stockStatusAfter, $qtyAfter, $sto
9099
$productId = 123;
91100
$this->selectMock->expects($this->any())->method('from')->willReturnSelf();
92101
$this->selectMock->expects($this->any())->method('where')->willReturnSelf();
102+
$this->selectMock->expects($this->any())->method('joinLeft')->willReturnSelf();
93103
$this->connectionMock->expects($this->exactly(2))->method('select')->willReturn($this->selectMock);
94104
$this->connectionMock->expects($this->exactly(2))->method('fetchAll')->willReturnOnConsecutiveCalls(
95105
[
@@ -105,7 +115,10 @@ public function testClean($stockStatusBefore, $stockStatusAfter, $qtyAfter, $sto
105115
->with(Product::CACHE_TAG, [$productId]);
106116
$this->eventManagerMock->expects($this->once())->method('dispatch')
107117
->with('clean_cache_by_tags', ['object' => $this->cacheContextMock]);
108-
118+
$this->metadataPoolMock->expects($this->exactly(2))->method('getMetadata')
119+
->willReturnSelf();
120+
$this->metadataPoolMock->expects($this->exactly(2))->method('getLinkField')
121+
->willReturn('row_id');
109122
$callback = function () {
110123
};
111124
$this->unit->clean([], $callback);
@@ -136,6 +149,7 @@ public function testNotCleanCache($stockStatusBefore, $stockStatusAfter, $qtyAft
136149
$productId = 123;
137150
$this->selectMock->expects($this->any())->method('from')->willReturnSelf();
138151
$this->selectMock->expects($this->any())->method('where')->willReturnSelf();
152+
$this->selectMock->expects($this->any())->method('joinLeft')->willReturnSelf();
139153
$this->connectionMock->expects($this->exactly(2))->method('select')->willReturn($this->selectMock);
140154
$this->connectionMock->expects($this->exactly(2))->method('fetchAll')->willReturnOnConsecutiveCalls(
141155
[
@@ -149,6 +163,10 @@ public function testNotCleanCache($stockStatusBefore, $stockStatusAfter, $qtyAft
149163
->willReturn($stockThresholdQty);
150164
$this->cacheContextMock->expects($this->never())->method('registerEntities');
151165
$this->eventManagerMock->expects($this->never())->method('dispatch');
166+
$this->metadataPoolMock->expects($this->exactly(2))->method('getMetadata')
167+
->willReturnSelf();
168+
$this->metadataPoolMock->expects($this->exactly(2))->method('getLinkField')
169+
->willReturn('row_id');
152170

153171
$callback = function () {
154172
};

0 commit comments

Comments
 (0)