forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge magento/2.4-develop into magento-architects/revert-5305-ECP-98
- Loading branch information
Showing
11 changed files
with
568 additions
and
32 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
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
129 changes: 129 additions & 0 deletions
129
app/code/Magento/Customer/Test/Unit/Setup/RecurringDataTest.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,129 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Test\Unit\Setup; | ||
|
||
use Magento\Framework\Indexer\IndexerInterface; | ||
use Magento\Framework\Indexer\StateInterface; | ||
use Magento\Framework\Indexer\IndexerRegistry; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
use Magento\Customer\Model\Customer; | ||
use Magento\Customer\Setup\RecurringData; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; | ||
|
||
/** | ||
* Test for recurring data | ||
*/ | ||
class RecurringDataTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var ObjectManagerHelper | ||
*/ | ||
private $objectManagerHelper; | ||
|
||
/** | ||
* @var IndexerInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $indexer; | ||
|
||
/** | ||
* @var StateInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $state; | ||
|
||
/** | ||
* @var IndexerRegistry|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $indexerRegistry; | ||
|
||
/** | ||
* @var ModuleDataSetupInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $setup; | ||
|
||
/** | ||
* @var ModuleContextInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* @var RecurringData | ||
*/ | ||
private $recurringData; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->objectManagerHelper = new ObjectManagerHelper($this); | ||
$this->state = $this->getMockBuilder(StateInterface::class) | ||
->setMethods(['getStatus']) | ||
->getMockForAbstractClass(); | ||
$this->indexer = $this->getMockBuilder(IndexerInterface::class) | ||
->setMethods(['getState', 'reindexAll']) | ||
->getMockForAbstractClass(); | ||
$this->indexer->expects($this->any()) | ||
->method('getState') | ||
->willReturn($this->state); | ||
$this->indexerRegistry = $this->getMockBuilder(IndexerRegistry::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['get']) | ||
->getMock(); | ||
$this->indexerRegistry->expects($this->any()) | ||
->method('get') | ||
->with(Customer::CUSTOMER_GRID_INDEXER_ID) | ||
->willReturn($this->indexer); | ||
$this->setup = $this->getMockBuilder(ModuleDataSetupInterface::class) | ||
->setMethods(['tableExists']) | ||
->getMockForAbstractClass(); | ||
$this->context = $this->getMockBuilder(ModuleContextInterface::class) | ||
->getMockForAbstractClass(); | ||
|
||
$this->recurringData = $this->objectManagerHelper->getObject( | ||
RecurringData::class, | ||
[ | ||
'indexerRegistry' => $this->indexerRegistry | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @param bool $isTableExists | ||
* @param string $indexerState | ||
* @param int $countReindex | ||
* @return void | ||
* @dataProvider installDataProvider | ||
*/ | ||
public function testInstall(bool $isTableExists, string $indexerState, int $countReindex) | ||
{ | ||
$this->setup->expects($this->any()) | ||
->method('tableExists') | ||
->with('customer_grid_flat') | ||
->willReturn($isTableExists); | ||
$this->state->expects($this->any()) | ||
->method('getStatus') | ||
->willReturn($indexerState); | ||
$this->indexer->expects($this->exactly($countReindex)) | ||
->method('reindexAll'); | ||
$this->recurringData->install($this->setup, $this->context); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function installDataProvider() : array | ||
{ | ||
return [ | ||
[true, StateInterface::STATUS_INVALID, 1], | ||
[false, StateInterface::STATUS_INVALID, 1], | ||
[true, StateInterface::STATUS_VALID, 0], | ||
[false, StateInterface::STATUS_VALID, 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
24 changes: 24 additions & 0 deletions
24
app/code/Magento/SalesRule/Model/Rule/QuoteResetAppliedRules.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,24 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\SalesRule\Model\Rule; | ||
|
||
use Magento\SalesRule\Model\Spi\QuoteResetAppliedRulesInterface; | ||
|
||
/** | ||
* Reset applied rules to quote | ||
*/ | ||
class QuoteResetAppliedRules implements QuoteResetAppliedRulesInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute(\Magento\Quote\Api\Data\CartInterface $quote): void | ||
{ | ||
$quote->setCartFixedRules([]); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/code/Magento/SalesRule/Model/Spi/QuoteResetAppliedRulesInterface.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,22 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\SalesRule\Model\Spi; | ||
|
||
/** | ||
* Reset applied rules to quote | ||
*/ | ||
interface QuoteResetAppliedRulesInterface | ||
{ | ||
/** | ||
* Reset applied rules to quote | ||
* | ||
* @param \Magento\Quote\Api\Data\CartInterface $quote | ||
* @return void | ||
*/ | ||
public function execute(\Magento\Quote\Api\Data\CartInterface $quote): void; | ||
} |
39 changes: 39 additions & 0 deletions
39
app/code/Magento/SalesRule/Observer/QuoteResetAppliedRulesObserver.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,39 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\SalesRule\Observer; | ||
|
||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\SalesRule\Model\Spi\QuoteResetAppliedRulesInterface; | ||
|
||
/** | ||
* Reset applied rules to quote before collecting totals | ||
*/ | ||
class QuoteResetAppliedRulesObserver implements ObserverInterface | ||
{ | ||
/** | ||
* @var QuoteResetAppliedRulesInterface | ||
*/ | ||
private $resetAppliedRules; | ||
|
||
/** | ||
* @param QuoteResetAppliedRulesInterface $resetAppliedRules | ||
*/ | ||
public function __construct(QuoteResetAppliedRulesInterface $resetAppliedRules) | ||
{ | ||
$this->resetAppliedRules = $resetAppliedRules; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
$this->resetAppliedRules->execute($observer->getQuote()); | ||
} | ||
} |
Oops, something went wrong.