Skip to content

Commit

Permalink
Merge pull request #1473 from magento-okapis/BundledPR-Sep8
Browse files Browse the repository at this point in the history
[okapis] MAGETWO-71024: [Tech Debt] Skipped unit/integration tests needs to be re-examined.
  • Loading branch information
pdohogne-magento authored Sep 9, 2017
2 parents 2bd4d5a + 164899b commit 1e87722
Show file tree
Hide file tree
Showing 60 changed files with 1,054 additions and 456 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@

use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing;

class Import extends \Magento\Catalog\Model\Indexer\Product\Price\Plugin\AbstractPlugin
class Import
{
/**
* @var \Magento\Framework\Indexer\IndexerRegistry
*/
private $indexerRegistry;

/**
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
*/
public function __construct(\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry)
{
$this->indexerRegistry = $indexerRegistry;
}

/**
* After import handler
*
Expand All @@ -18,9 +31,7 @@ class Import extends \Magento\Catalog\Model\Indexer\Product\Price\Plugin\Abstrac
*/
public function afterSaveAdvancedPricing(AdvancedPricing $subject)
{
if (!$this->getPriceIndexer()->isScheduled()) {
$this->invalidateIndexer();
}
$this->invalidateIndexer();
}

/**
Expand All @@ -32,18 +43,19 @@ public function afterSaveAdvancedPricing(AdvancedPricing $subject)
*/
public function afterDeleteAdvancedPricing(AdvancedPricing $subject)
{
if (!$this->getPriceIndexer()->isScheduled()) {
$this->invalidateIndexer();
}
$this->invalidateIndexer();
}

/**
* Get price indexer
* Invalidate indexer
*
* @return \Magento\Framework\Indexer\IndexerInterface
* @return void
*/
protected function getPriceIndexer()
private function invalidateIndexer()
{
return $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID);
$priceIndexer = $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID);
if (!$priceIndexer->isScheduled()) {
$priceIndexer->invalidate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ class ImportTest extends \PHPUnit\Framework\TestCase
/**
* @var \Magento\Framework\Indexer\IndexerInterface |\PHPUnit_Framework_MockObject_MockObject
*/
protected $indexer;
private $indexer;

/**
* @var Import |\PHPUnit_Framework_MockObject_MockObject
*/
protected $import;
private $import;

/**
* @var \Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing|\PHPUnit_Framework_MockObject_MockObject
*/
protected $advancedPricing;
private $advancedPricing;

/**
* @var \Magento\Framework\Indexer\IndexerRegistry|\PHPUnit_Framework_MockObject_MockObject
*/
private $indexerRegistry;

protected function setUp()
{
Expand All @@ -33,29 +38,58 @@ protected function setUp()
'',
false
);
$this->import = $this->createPartialMock(
\Magento\AdvancedPricingImportExport\Model\Indexer\Product\Price\Plugin\Import::class,
['getPriceIndexer', 'invalidateIndexer']
$this->indexerRegistry = $this->createMock(
\Magento\Framework\Indexer\IndexerRegistry::class
);
$this->import = new \Magento\AdvancedPricingImportExport\Model\Indexer\Product\Price\Plugin\Import(
$this->indexerRegistry
);
$this->advancedPricing = $this->createMock(
\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing::class
);
$this->import->expects($this->any())->method('getPriceIndexer')->willReturn($this->indexer);
$this->indexerRegistry->expects($this->any())
->method('get')
->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)
->willReturn($this->indexer);
}

public function testAfterSaveAdvancedPricing()
public function testAfterSaveReindexIsOnSave()
{
$this->indexer->expects($this->once())->method('isScheduled')->willReturn(false);
$this->import->expects($this->once())->method('invalidateIndexer');
$this->indexer->expects($this->once())
->method('isScheduled')
->willReturn(false);
$this->indexer->expects($this->once())
->method('invalidate');
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
}

public function testAfterSaveReindexIsOnSchedule()
{
$this->indexer->expects($this->once())
->method('isScheduled')
->willReturn(true);
$this->indexer->expects($this->never())
->method('invalidate');
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
}

public function testAfterDeleteAdvancedPricing()
public function testAfterDeleteReindexIsOnSave()
{
$this->indexer->expects($this->once())->method('isScheduled')->willReturn(false);
$this->import->expects($this->once())->method('invalidateIndexer');
$this->indexer->expects($this->once())
->method('isScheduled')
->willReturn(false);
$this->indexer->expects($this->once())
->method('invalidate');
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
}

public function testAfterDeleteReindexIsOnSchedule()
{
$this->indexer->expects($this->once())
->method('isScheduled')
->willReturn(true);
$this->indexer->expects($this->never())
->method('invalidate');
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
}
}
32 changes: 15 additions & 17 deletions app/code/Magento/Catalog/Controller/Adminhtml/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@ abstract class Category extends \Magento\Backend\App\Action
const ADMIN_RESOURCE = 'Magento_Catalog::categories';

/**
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
*/
private $dateTimeFilter;
protected $dateFilter;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date|null $dateFilter
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter = null
) {
$this->dateFilter = $dateFilter;
parent::__construct($context);
}

/**
* Initialize requested category and put it into registry.
Expand Down Expand Up @@ -125,20 +137,6 @@ protected function ajaxRequestResponse($category, $resultPage)
return $resultJson;
}

/**
* @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
*
* @deprecated 101.0.0
*/
private function getDateTimeFilter()
{
if ($this->dateTimeFilter === null) {
$this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class);
}
return $this->dateTimeFilter;
}

/**
* Datetime data preprocessing
*
Expand All @@ -154,7 +152,7 @@ protected function dateTimePreprocessing($category, $postData)
foreach ($attributes as $attrKey => $attribute) {
if ($attribute->getBackend()->getType() == 'datetime') {
if (array_key_exists($attrKey, $postData) && $postData[$attrKey] != '') {
$dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
$dateFieldFilters[$attrKey] = $this->dateFilter;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
* @param StoreManagerInterface $storeManager
* @param \Magento\Eav\Model\Config $eavConfig
*/
Expand All @@ -69,10 +70,11 @@ public function __construct(
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\View\LayoutFactory $layoutFactory,
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
StoreManagerInterface $storeManager,
\Magento\Eav\Model\Config $eavConfig = null
) {
parent::__construct($context);
parent::__construct($context, $dateFilter);
$this->resultRawFactory = $resultRawFactory;
$this->resultJsonFactory = $resultJsonFactory;
$this->layoutFactory = $layoutFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function syncData($indexer, $destinationTable, $ids)
protected function processRelations($indexer, $ids, $onlyParents = false)
{
$parentIds = $indexer->getRelationsByChild($ids);
$childIds = $onlyParents ? [] : $indexer->getRelationsByParent($ids);
$childIds = $onlyParents ? [] : $indexer->getRelationsByParent($parentIds);
return array_unique(array_merge($ids, $childIds, $parentIds));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Indexer\Product\Price;

use Magento\Customer\Api\Data\GroupInterface;
use Magento\Framework\Indexer\IndexerRegistry;

/**
* Invalidate price index
*/
class InvalidateIndex implements UpdateIndexInterface
{
/**
* @var IndexerRegistry
*/
private $indexerRegistry;

/**
* Constructor
*
* @param IndexerRegistry $indexerRegistry
*/
public function __construct(
IndexerRegistry $indexerRegistry
) {
$this->indexerRegistry = $indexerRegistry;
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function update(GroupInterface $group, $isGroupNew)
{
$this->indexerRegistry->get(Processor::INDEXER_ID)->invalidate();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,44 @@
namespace Magento\Catalog\Model\Indexer\Product\Price\Plugin;

use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Api\Data\GroupInterface;
use \Magento\Catalog\Model\Indexer\Product\Price\UpdateIndexInterface;

class CustomerGroup extends AbstractPlugin
class CustomerGroup
{
/**
* Invalidate the indexer after the group is saved.
*
* @param GroupRepositoryInterface $subject
* @param string $result
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @var UpdateIndexInterface
*/
public function afterSave(GroupRepositoryInterface $subject, $result)
{
$this->invalidateIndexer();
return $result;
}
private $updateIndex;

/**
* Invalidate the indexer after the group is deleted.
* Constructor
*
* @param GroupRepositoryInterface $subject
* @param string $result
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param UpdateIndexInterface $updateIndex
*/
public function afterDelete(GroupRepositoryInterface $subject, $result)
{
$this->invalidateIndexer();
return $result;
public function __construct(
UpdateIndexInterface $updateIndex
) {
$this->updateIndex = $updateIndex;
}

/**
* Invalidate the indexer after the group is deleted.
* Update price index after customer group saved
*
* @param GroupRepositoryInterface $subject
* @param string $result
* @return string
* @param \Closure $proceed
* @param GroupInterface $result
* @return GroupInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterDeleteById(GroupRepositoryInterface $subject, $result)
{
$this->invalidateIndexer();
return $result;
public function aroundSave(
GroupRepositoryInterface $subject,
\Closure $proceed,
GroupInterface $group
) {
$isGroupNew = !$group->getId();
$group = $proceed($group);
$this->updateIndex->update($group, $isGroupNew);
return $group;
}
}
Loading

0 comments on commit 1e87722

Please sign in to comment.