-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-70346: Configurable product shows on frontend after deleting …
…child products - Add plugin around delete to update all indexers for child products - Add class to update all indexers related to product - Unit Tests - Functional test
- Loading branch information
Eric Bohanon
committed
Sep 5, 2017
1 parent
9223ab3
commit e6bbe78
Showing
11 changed files
with
524 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
app/code/Magento/Catalog/Model/Indexer/Product/Full.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model\Indexer\Product; | ||
|
||
use Magento\Framework\Indexer\ActionInterface; | ||
use Magento\Framework\Indexer\IndexerRegistry; | ||
use Magento\PageCache\Model\Config; | ||
use Magento\Framework\App\Cache\TypeListInterface; | ||
|
||
/** | ||
* Reindex all relevant product indexers | ||
*/ | ||
class Full implements ActionInterface | ||
{ | ||
/** | ||
* @var IndexerRegistry | ||
*/ | ||
private $indexerRegistry; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $pageCacheConfig; | ||
|
||
/** | ||
* @var TypeListInterface | ||
*/ | ||
private $cacheTypeList; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private $indexerList; | ||
|
||
/** | ||
* Initialize dependencies | ||
* | ||
* @param IndexerRegistry $indexerRegistry | ||
* @param Config $pageCacheConfig | ||
* @param TypeListInterface $cacheTypeList | ||
* @param string[] $indexerList | ||
*/ | ||
public function __construct( | ||
IndexerRegistry $indexerRegistry, | ||
Config $pageCacheConfig, | ||
TypeListInterface $cacheTypeList, | ||
array $indexerList | ||
) { | ||
$this->indexerRegistry = $indexerRegistry; | ||
$this->pageCacheConfig = $pageCacheConfig; | ||
$this->cacheTypeList = $cacheTypeList; | ||
$this->indexerList = $indexerList; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function executeFull() | ||
{ | ||
foreach ($this->indexerList as $indexerName) { | ||
$indexer = $this->indexerRegistry->get($indexerName); | ||
if (!$indexer->isScheduled()) { | ||
$indexer->reindexAll(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function executeList(array $ids) | ||
{ | ||
if (!empty($ids)) { | ||
foreach ($this->indexerList as $indexerName) { | ||
$indexer = $this->indexerRegistry->get($indexerName); | ||
if (!$indexer->isScheduled()) { | ||
$indexer->reindexList($ids); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function executeRow($id) | ||
{ | ||
if (!empty($id)) { | ||
foreach ($this->indexerList as $indexerName) { | ||
$indexer = $this->indexerRegistry->get($indexerName); | ||
if (!$indexer->isScheduled()) { | ||
$indexer->reindexRow($id); | ||
} | ||
} | ||
} | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/FullTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product; | ||
|
||
use Magento\Catalog\Model\Indexer\Product\Full; | ||
use Magento\Framework\Indexer\IndexerInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Magento\Framework\Indexer\IndexerRegistry; | ||
use Magento\PageCache\Model\Config; | ||
use Magento\Framework\App\Cache\TypeListInterface; | ||
|
||
class FullTest extends TestCase | ||
{ | ||
/** | ||
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var IndexerRegistry|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $indexerRegistryMock; | ||
|
||
/** | ||
* @var Config|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $configMock; | ||
|
||
/** | ||
* @var TypeListInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $typeListMock; | ||
|
||
/** | ||
* @var Full | ||
*/ | ||
private $full; | ||
|
||
public function setUp() | ||
{ | ||
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); | ||
$this->indexerRegistryMock = $this->createMock(IndexerRegistry::class); | ||
$this->configMock = $this->createMock(Config::class); | ||
$this->typeListMock = $this->getMockForAbstractClass(TypeListInterface::class, [], "", false); | ||
|
||
$this->full = $this->objectManager->getObject( | ||
Full::class, | ||
[ | ||
'indexerRegistry' => $this->indexerRegistryMock, | ||
'pageCacheConfig' => $this->configMock, | ||
'cacheTypeList' => $this->typeListMock, | ||
'indexerList' => ['catalog_indexer', 'product_indexer', 'stock_indexer', 'search_indexer'] | ||
] | ||
); | ||
} | ||
|
||
public function testExecuteFull() | ||
{ | ||
$indexerMock = $this->getMockForAbstractClass(IndexerInterface::class, [], "", false); | ||
$indexerMock->expects($this->exactly(4))->method('isScheduled')->willReturn(false); | ||
$indexerMock->expects($this->exactly(4))->method('reindexAll'); | ||
$this->indexerRegistryMock->expects($this->exactly(4))->method('get')->willReturn($indexerMock); | ||
$this->configMock->expects($this->once())->method('isEnabled')->willReturn(true); | ||
$this->typeListMock->expects($this->once())->method('invalidate')->with('full_page'); | ||
|
||
$this->full->executeFull(); | ||
} | ||
|
||
public function testExecuteFullPageCacheDisabled() | ||
{ | ||
$indexerMock = $this->getMockForAbstractClass(IndexerInterface::class, [], "", false); | ||
$indexerMock->expects($this->exactly(4))->method('isScheduled')->willReturn(false); | ||
$indexerMock->expects($this->exactly(4))->method('reindexAll'); | ||
$this->indexerRegistryMock->expects($this->exactly(4))->method('get')->willReturn($indexerMock); | ||
$this->configMock->expects($this->once())->method('isEnabled')->willReturn(false); | ||
$this->typeListMock->expects($this->never())->method('invalidate'); | ||
|
||
$this->full->executeFull(); | ||
} | ||
|
||
public function testExecuteList() | ||
{ | ||
$indexerMock = $this->getMockForAbstractClass(IndexerInterface::class, [], "", false); | ||
$indexerMock->expects($this->exactly(4))->method('isScheduled')->willReturn(false); | ||
$indexerMock->expects($this->exactly(4))->method('reindexList')->with([1, 2]); | ||
$this->indexerRegistryMock->expects($this->exactly(4))->method('get')->willReturn($indexerMock); | ||
$this->configMock->expects($this->once())->method('isEnabled')->willReturn(true); | ||
$this->typeListMock->expects($this->once())->method('invalidate')->with('full_page'); | ||
|
||
$this->full->executeList([1, 2]); | ||
} | ||
|
||
public function testExecuteListPageCacheDisabled() | ||
{ | ||
$indexerMock = $this->getMockForAbstractClass(IndexerInterface::class, [], "", false); | ||
$indexerMock->expects($this->exactly(4))->method('isScheduled')->willReturn(false); | ||
$indexerMock->expects($this->exactly(4))->method('reindexList')->with([1, 2]); | ||
$this->indexerRegistryMock->expects($this->exactly(4))->method('get')->willReturn($indexerMock); | ||
$this->configMock->expects($this->once())->method('isEnabled')->willReturn(false); | ||
$this->typeListMock->expects($this->never())->method('invalidate'); | ||
|
||
$this->full->executeList([1, 2]); | ||
} | ||
|
||
public function testExecuteRow() | ||
{ | ||
$indexerMock = $this->getMockForAbstractClass(IndexerInterface::class, [], "", false); | ||
$indexerMock->expects($this->exactly(4))->method('isScheduled')->willReturn(false); | ||
$indexerMock->expects($this->exactly(4))->method('reindexRow')->with(1); | ||
$this->indexerRegistryMock->expects($this->exactly(4))->method('get')->willReturn($indexerMock); | ||
$this->configMock->expects($this->once())->method('isEnabled')->willReturn(true); | ||
$this->typeListMock->expects($this->once())->method('invalidate')->with('full_page'); | ||
|
||
$this->full->executeRow(1); | ||
} | ||
|
||
public function testExecuteRowPageCacheDisabled() | ||
{ | ||
$indexerMock = $this->getMockForAbstractClass(IndexerInterface::class, [], "", false); | ||
$indexerMock->expects($this->exactly(4))->method('isScheduled')->willReturn(false); | ||
$indexerMock->expects($this->exactly(4))->method('reindexRow')->with(1); | ||
$this->indexerRegistryMock->expects($this->exactly(4))->method('get')->willReturn($indexerMock); | ||
$this->configMock->expects($this->once())->method('isEnabled')->willReturn(false); | ||
$this->typeListMock->expects($this->never())->method('invalidate'); | ||
|
||
$this->full->executeRow(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.