diff --git a/app/code/Magento/Catalog/Model/CategoryLink.php b/app/code/Magento/Catalog/Model/CategoryLink.php index fe640a72d0b6d..38c6f77483de2 100644 --- a/app/code/Magento/Catalog/Model/CategoryLink.php +++ b/app/code/Magento/Catalog/Model/CategoryLink.php @@ -3,39 +3,41 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Catalog\Model; +use Magento\Catalog\Api\Data\CategoryLinkExtensionInterface; +use Magento\Catalog\Api\Data\CategoryLinkInterface; +use Magento\Framework\Model\AbstractExtensibleModel; + /** * @codeCoverageIgnore */ -class CategoryLink extends \Magento\Framework\Api\AbstractExtensibleObject implements - \Magento\Catalog\Api\Data\CategoryLinkInterface +class CategoryLink extends AbstractExtensibleModel implements CategoryLinkInterface { - /**#@+ - * Constants - */ - const KEY_POSITION = 'position'; - const KEY_CATEGORY_ID = 'category_id'; - /**#@-*/ + public const KEY_POSITION = 'position'; + public const KEY_CATEGORY_ID = 'category_id'; /** - * {@inheritdoc} + * @inheritdoc */ public function getPosition() { - return $this->_get(self::KEY_POSITION); + return $this->getData(self::KEY_POSITION); } /** - * {@inheritdoc} + * @inheritdoc */ public function getCategoryId() { - return $this->_get(self::KEY_CATEGORY_ID); + return $this->getData(self::KEY_CATEGORY_ID); } /** + * @inheritDoc + * * @param int $position * @return $this */ @@ -56,7 +58,7 @@ public function setCategoryId($categoryId) } /** - * {@inheritdoc} + * @inheritdoc * * @return \Magento\Catalog\Api\Data\CategoryLinkExtensionInterface|null */ @@ -66,14 +68,13 @@ public function getExtensionAttributes() } /** - * {@inheritdoc} + * @inheritdoc * * @param \Magento\Catalog\Api\Data\CategoryLinkExtensionInterface $extensionAttributes * @return $this */ - public function setExtensionAttributes( - \Magento\Catalog\Api\Data\CategoryLinkExtensionInterface $extensionAttributes - ) { + public function setExtensionAttributes(CategoryLinkExtensionInterface $extensionAttributes) + { return $this->_setExtensionAttributes($extensionAttributes); } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Category/Flat/Plugin/StoreGroup.php b/app/code/Magento/Catalog/Model/Indexer/Category/Flat/Plugin/StoreGroup.php index 670f19db725f7..16f96d794a97b 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Category/Flat/Plugin/StoreGroup.php +++ b/app/code/Magento/Catalog/Model/Indexer/Category/Flat/Plugin/StoreGroup.php @@ -5,18 +5,13 @@ */ namespace Magento\Catalog\Model\Indexer\Category\Flat\Plugin; -use Magento\Framework\Model\ResourceModel\Db\AbstractDb; -use Magento\Framework\Model\AbstractModel; -use Magento\Framework\Indexer\IndexerRegistry; use Magento\Catalog\Model\Indexer\Category\Flat\State; +use Magento\Framework\Indexer\IndexerRegistry; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; class StoreGroup { - /** - * @var bool - */ - private $needInvalidating; - /** * @var IndexerRegistry */ @@ -48,35 +43,21 @@ protected function validate(AbstractModel $group) return $group->dataHasChangedFor('root_category_id') && !$group->isObjectNew(); } - /** - * Check if need invalidate flat category indexer - * - * @param AbstractDb $subject - * @param AbstractModel $group - * - * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function beforeSave(AbstractDb $subject, AbstractModel $group) - { - $this->needInvalidating = $this->validate($group); - } - /** * Invalidate flat category indexer if root category changed for store group * * @param AbstractDb $subject - * @param AbstractDb $objectResource - * + * @param AbstractDb $result + * @param AbstractModel $group * @return AbstractDb * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterSave(AbstractDb $subject, AbstractDb $objectResource) + public function afterSave(AbstractDb $subject, AbstractDb $result, AbstractModel $group) { - if ($this->needInvalidating && $this->state->isFlatEnabled()) { + if ($this->validate($group) && $this->state->isFlatEnabled()) { $this->indexerRegistry->get(State::INDEXER_ID)->invalidate(); } - return $objectResource; + return $result; } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreGroup.php b/app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreGroup.php index 005936a75e6d6..12a9d85dc416b 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreGroup.php +++ b/app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreGroup.php @@ -5,19 +5,14 @@ */ namespace Magento\Catalog\Model\Indexer\Category\Product\Plugin; -use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Framework\Model\ResourceModel\Db\AbstractDb; -use Magento\Framework\Model\AbstractModel; use Magento\Catalog\Model\Indexer\Category\Product; use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer; +use Magento\Framework\Indexer\IndexerRegistry; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; class StoreGroup { - /** - * @var bool - */ - private $needInvalidating; - /** * @var IndexerRegistry */ @@ -40,36 +35,23 @@ public function __construct( $this->tableMaintainer = $tableMaintainer; } - /** - * Check if need invalidate flat category indexer - * - * @param AbstractDb $subject - * @param AbstractModel $group - * - * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function beforeSave(AbstractDb $subject, AbstractModel $group) - { - $this->needInvalidating = $this->validate($group); - } - /** * Invalidate flat product * * @param AbstractDb $subject - * @param AbstractDb $objectResource + * @param AbstractDb $result + * @param AbstractModel $group * * @return AbstractDb * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterSave(AbstractDb $subject, AbstractDb $objectResource) + public function afterSave(AbstractDb $subject, AbstractDb $result, AbstractModel $group) { - if ($this->needInvalidating) { + if ($this->validate($group)) { $this->indexerRegistry->get(Product::INDEXER_ID)->invalidate(); } - return $objectResource; + return $result; } /** diff --git a/app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreView.php b/app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreView.php index b6f9e6adf4a1c..78353f56a0e13 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreView.php +++ b/app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreView.php @@ -5,18 +5,18 @@ */ namespace Magento\Catalog\Model\Indexer\Category\Product\Plugin; -use Magento\Framework\Model\ResourceModel\Db\AbstractDb; use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; class StoreView extends StoreGroup { /** * Validate changes for invalidating indexer * - * @param \Magento\Framework\Model\AbstractModel $store + * @param AbstractModel $store * @return bool */ - protected function validate(\Magento\Framework\Model\AbstractModel $store) + protected function validate(AbstractModel $store) { return $store->isObjectNew() || $store->dataHasChangedFor('group_id'); } @@ -36,7 +36,7 @@ public function afterSave(AbstractDb $subject, AbstractDb $objectResource, Abstr $this->tableMaintainer->createTablesForStore($store->getId()); } - return parent::afterSave($subject, $objectResource); + return parent::afterSave($subject, $objectResource, $store); } /** diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Plugin/StoreView.php b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Plugin/StoreView.php index 95e525b2601f4..4503ca5ea23c7 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Plugin/StoreView.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Plugin/StoreView.php @@ -3,21 +3,26 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Catalog\Model\Indexer\Product\Eav\Plugin; +use Magento\Catalog\Model\Indexer\Product\Eav\Processor; +use Magento\Framework\Model\AbstractModel; +use Magento\Store\Model\ResourceModel\Store; + class StoreView { /** * Product attribute indexer processor * - * @var \Magento\Catalog\Model\Indexer\Product\Eav\Processor + * @var Processor */ protected $_indexerEavProcessor; /** - * @param \Magento\Catalog\Model\Indexer\Product\Eav\Processor $indexerEavProcessor + * @param Processor $indexerEavProcessor */ - public function __construct(\Magento\Catalog\Model\Indexer\Product\Eav\Processor $indexerEavProcessor) + public function __construct(Processor $indexerEavProcessor) { $this->_indexerEavProcessor = $indexerEavProcessor; } @@ -25,18 +30,19 @@ public function __construct(\Magento\Catalog\Model\Indexer\Product\Eav\Processor /** * Before save handler * - * @param \Magento\Store\Model\ResourceModel\Store $subject - * @param \Magento\Framework\Model\AbstractModel $object + * @param Store $subject + * @param Store $result + * @param AbstractModel $object * - * @return void + * @return Store * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function beforeSave( - \Magento\Store\Model\ResourceModel\Store $subject, - \Magento\Framework\Model\AbstractModel $object - ) { - if ((!$object->getId() || $object->dataHasChangedFor('group_id')) && $object->getIsActive()) { + public function afterSave(Store $subject, Store $result, AbstractModel $object) + { + if (($object->isObjectNew() || $object->dataHasChangedFor('group_id')) && $object->getIsActive()) { $this->_indexerEavProcessor->markIndexerAsInvalid(); } + + return $result; } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Plugin/Store.php b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Plugin/Store.php index ef7919193e609..38b9281f42cca 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Plugin/Store.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Plugin/Store.php @@ -6,19 +6,23 @@ namespace Magento\Catalog\Model\Indexer\Product\Flat\Plugin; +use Magento\Catalog\Model\Indexer\Product\Flat\Processor; +use Magento\Framework\Model\AbstractModel; +use Magento\Store\Model\ResourceModel\Store as StoreResourceModel; + class Store { /** * Product flat indexer processor * - * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor + * @var Processor */ protected $_productFlatIndexerProcessor; /** - * @param \Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor + * @param Processor $productFlatIndexerProcessor */ - public function __construct(\Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor) + public function __construct(Processor $productFlatIndexerProcessor) { $this->_productFlatIndexerProcessor = $productFlatIndexerProcessor; } @@ -26,18 +30,19 @@ public function __construct(\Magento\Catalog\Model\Indexer\Product\Flat\Processo /** * Before save handler * - * @param \Magento\Store\Model\ResourceModel\Store $subject - * @param \Magento\Framework\Model\AbstractModel $object + * @param StoreResourceModel $subject + * @param StoreResourceModel $result + * @param AbstractModel $object * - * @return void + * @return StoreResourceModel * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function beforeSave( - \Magento\Store\Model\ResourceModel\Store $subject, - \Magento\Framework\Model\AbstractModel $object - ) { - if (!$object->getId() || $object->dataHasChangedFor('group_id')) { + public function afterSave(StoreResourceModel $subject, StoreResourceModel $result, AbstractModel $object) + { + if ($object->isObjectNew() || $object->dataHasChangedFor('group_id')) { $this->_productFlatIndexerProcessor->markIndexerAsInvalid(); } + + return $result; } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Plugin/StoreGroup.php b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Plugin/StoreGroup.php index df62fe8d349e4..1276e60ac74b0 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Plugin/StoreGroup.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Plugin/StoreGroup.php @@ -6,19 +6,23 @@ namespace Magento\Catalog\Model\Indexer\Product\Flat\Plugin; +use Magento\Catalog\Model\Indexer\Product\Flat\Processor; +use Magento\Framework\Model\AbstractModel; +use Magento\Store\Model\ResourceModel\Group; + class StoreGroup { /** * Product flat indexer processor * - * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor + * @var Processor */ protected $_productFlatIndexerProcessor; /** - * @param \Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor + * @param Processor $productFlatIndexerProcessor */ - public function __construct(\Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor) + public function __construct(Processor $productFlatIndexerProcessor) { $this->_productFlatIndexerProcessor = $productFlatIndexerProcessor; } @@ -26,18 +30,19 @@ public function __construct(\Magento\Catalog\Model\Indexer\Product\Flat\Processo /** * Before save handler * - * @param \Magento\Store\Model\ResourceModel\Group $subject - * @param \Magento\Framework\Model\AbstractModel $object + * @param Group $subject + * @param Group $result + * @param AbstractModel $object * - * @return void + * @return Group * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function beforeSave( - \Magento\Store\Model\ResourceModel\Group $subject, - \Magento\Framework\Model\AbstractModel $object - ) { - if (!$object->getId() || $object->dataHasChangedFor('root_category_id')) { + public function afterSave(Group $subject, Group $result, AbstractModel $object) + { + if ($object->isObjectNew() || $object->dataHasChangedFor('root_category_id')) { $this->_productFlatIndexerProcessor->markIndexerAsInvalid(); } + + return $result; } } diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontPurchaseProductWithCustomOptionsTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontPurchaseProductWithCustomOptionsTest.xml index e768f7ba5317a..631d1d50077e9 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontPurchaseProductWithCustomOptionsTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontPurchaseProductWithCustomOptionsTest.xml @@ -152,7 +152,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Flat/Plugin/StoreGroupTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Flat/Plugin/StoreGroupTest.php index 7dba4ddfd3d8c..cb4fd12e8d6f2 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Flat/Plugin/StoreGroupTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Flat/Plugin/StoreGroupTest.php @@ -11,7 +11,6 @@ use Magento\Catalog\Model\Indexer\Category\Flat\State; use Magento\Framework\Indexer\IndexerInterface; use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Store\Model\Group as GroupModel; use Magento\Store\Model\ResourceModel\Group; use PHPUnit\Framework\MockObject\MockObject; @@ -22,32 +21,32 @@ class StoreGroupTest extends TestCase /** * @var MockObject|IndexerInterface */ - protected $indexerMock; + private $indexerMock; /** * @var MockObject|State */ - protected $stateMock; + private $stateMock; /** * @var StoreGroup */ - protected $model; + private $model; /** * @var MockObject|Group */ - protected $subjectMock; + private $subjectMock; /** * @var IndexerRegistry|MockObject */ - protected $indexerRegistryMock; + private $indexerRegistryMock; /** * @var MockObject|GroupModel */ - protected $groupMock; + private $groupMock; protected function setUp(): void { @@ -70,14 +69,10 @@ protected function setUp(): void $this->indexerRegistryMock = $this->createPartialMock(IndexerRegistry::class, ['get']); - $this->model = (new ObjectManager($this)) - ->getObject( - StoreGroup::class, - ['indexerRegistry' => $this->indexerRegistryMock, 'state' => $this->stateMock] - ); + $this->model = new StoreGroup($this->indexerRegistryMock, $this->stateMock); } - public function testBeforeAndAfterSave() + public function testAfterSave(): void { $this->stateMock->expects($this->once())->method('isFlatEnabled')->willReturn(true); $this->indexerMock->expects($this->once())->method('invalidate'); @@ -90,14 +85,14 @@ public function testBeforeAndAfterSave() ->with('root_category_id') ->willReturn(true); $this->groupMock->expects($this->once())->method('isObjectNew')->willReturn(false); - $this->model->beforeSave($this->subjectMock, $this->groupMock); + $this->assertSame( $this->subjectMock, $this->model->afterSave($this->subjectMock, $this->subjectMock, $this->groupMock) ); } - public function testBeforeAndAfterSaveNotNew() + public function testAfterSaveNotNew(): void { $this->stateMock->expects($this->never())->method('isFlatEnabled'); $this->groupMock->expects($this->once()) @@ -105,7 +100,7 @@ public function testBeforeAndAfterSaveNotNew() ->with('root_category_id') ->willReturn(true); $this->groupMock->expects($this->once())->method('isObjectNew')->willReturn(true); - $this->model->beforeSave($this->subjectMock, $this->groupMock); + $this->assertSame( $this->subjectMock, $this->model->afterSave($this->subjectMock, $this->subjectMock, $this->groupMock) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Flat/Plugin/StoreViewTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Flat/Plugin/StoreViewTest.php index 6f39cc9a7b220..d818af8f1233c 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Flat/Plugin/StoreViewTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Flat/Plugin/StoreViewTest.php @@ -12,6 +12,7 @@ use Magento\Framework\Indexer\IndexerInterface; use Magento\Framework\Indexer\IndexerRegistry; use Magento\Store\Model\ResourceModel\Store; +use Magento\Store\Model\Store as StoreModel; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -20,27 +21,27 @@ class StoreViewTest extends TestCase /** * @var MockObject|IndexerInterface */ - protected $indexerMock; + private $indexerMock; /** * @var MockObject|State */ - protected $stateMock; + private $stateMock; /** * @var StoreView */ - protected $model; + private $model; /** * @var IndexerRegistry|MockObject */ - protected $indexerRegistryMock; + private $indexerRegistryMock; /** - * @var MockObject + * @var Store|MockObject */ - protected $subjectMock; + private $subjectMock; protected function setUp(): void { @@ -65,50 +66,51 @@ protected function setUp(): void $this->model = new StoreView($this->indexerRegistryMock, $this->stateMock); } - public function testBeforeAndAfterSaveNewObject() + public function testAfterSaveNewObject(): void { $this->mockConfigFlatEnabled(); $this->mockIndexerMethods(); $storeMock = $this->createPartialMock( - \Magento\Store\Model\Store::class, + StoreModel::class, ['isObjectNew', 'dataHasChangedFor'] ); $storeMock->expects($this->once())->method('isObjectNew')->willReturn(true); - $this->model->beforeSave($this->subjectMock, $storeMock); + $this->assertSame( $this->subjectMock, $this->model->afterSave($this->subjectMock, $this->subjectMock, $storeMock) ); } - public function testBeforeAndAfterSaveHasChanged() + public function testAfterSaveHasChanged(): void { $storeMock = $this->createPartialMock( - \Magento\Store\Model\Store::class, + StoreModel::class, ['isObjectNew', 'dataHasChangedFor'] ); - $this->model->beforeSave($this->subjectMock, $storeMock); + $this->assertSame( $this->subjectMock, $this->model->afterSave($this->subjectMock, $this->subjectMock, $storeMock) ); } - public function testBeforeAndAfterSaveNoNeed() + public function testAfterSaveNoNeed(): void { $this->mockConfigFlatEnabledNever(); + $storeMock = $this->createPartialMock( - \Magento\Store\Model\Store::class, + StoreModel::class, ['isObjectNew', 'dataHasChangedFor'] ); - $this->model->beforeSave($this->subjectMock, $storeMock); + $this->assertSame( $this->subjectMock, $this->model->afterSave($this->subjectMock, $this->subjectMock, $storeMock) ); } - protected function mockIndexerMethods() + private function mockIndexerMethods(): void { $this->indexerMock->expects($this->once())->method('invalidate'); $this->indexerRegistryMock->expects($this->once()) @@ -117,12 +119,12 @@ protected function mockIndexerMethods() ->willReturn($this->indexerMock); } - protected function mockConfigFlatEnabled() + private function mockConfigFlatEnabled(): void { $this->stateMock->expects($this->once())->method('isFlatEnabled')->willReturn(true); } - protected function mockConfigFlatEnabledNever() + private function mockConfigFlatEnabledNever(): void { $this->stateMock->expects($this->never())->method('isFlatEnabled'); } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/StoreGroupTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/StoreGroupTest.php index 500f7f714e159..f7064b7e1117c 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/StoreGroupTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/StoreGroupTest.php @@ -9,9 +9,9 @@ use Magento\Catalog\Model\Indexer\Category\Product; use Magento\Catalog\Model\Indexer\Category\Product\Plugin\StoreGroup; +use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer; use Magento\Framework\Indexer\IndexerInterface; use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Store\Model\Group as GroupModel; use Magento\Store\Model\ResourceModel\Group; use PHPUnit\Framework\MockObject\MockObject; @@ -22,7 +22,7 @@ class StoreGroupTest extends TestCase /** * @var GroupModel|MockObject */ - private $groupMock; + private $groupModelMock; /** * @var MockObject|IndexerInterface @@ -32,13 +32,18 @@ class StoreGroupTest extends TestCase /** * @var MockObject|Group */ - private $subject; + private $subjectMock; /** * @var IndexerRegistry|MockObject */ private $indexerRegistryMock; + /** + * @var TableMaintainer|MockObject + */ + private $tableMaintainerMock; + /** * @var StoreGroup */ @@ -46,7 +51,7 @@ class StoreGroupTest extends TestCase protected function setUp(): void { - $this->groupMock = $this->createPartialMock( + $this->groupModelMock = $this->createPartialMock( GroupModel::class, ['dataHasChangedFor', 'isObjectNew'] ); @@ -59,44 +64,48 @@ protected function setUp(): void true, ['getId', 'getState'] ); - $this->subject = $this->createMock(Group::class); + $this->subjectMock = $this->createMock(Group::class); $this->indexerRegistryMock = $this->createPartialMock(IndexerRegistry::class, ['get']); + $this->tableMaintainerMock = $this->createMock(TableMaintainer::class); - $this->model = (new ObjectManager($this)) - ->getObject(StoreGroup::class, ['indexerRegistry' => $this->indexerRegistryMock]); + $this->model = new StoreGroup($this->indexerRegistryMock, $this->tableMaintainerMock); } /** * @param array $valueMap * @dataProvider changedDataProvider */ - public function testBeforeAndAfterSave($valueMap) + public function testAfterSave(array $valueMap): void { $this->mockIndexerMethods(); - $this->groupMock->expects($this->exactly(2))->method('dataHasChangedFor')->willReturnMap($valueMap); - $this->groupMock->expects($this->once())->method('isObjectNew')->willReturn(false); + $this->groupModelMock->expects($this->exactly(2))->method('dataHasChangedFor')->willReturnMap($valueMap); + $this->groupModelMock->expects($this->once())->method('isObjectNew')->willReturn(false); - $this->model->beforeSave($this->subject, $this->groupMock); - $this->assertSame($this->subject, $this->model->afterSave($this->subject, $this->subject, $this->groupMock)); + $this->assertSame( + $this->subjectMock, + $this->model->afterSave($this->subjectMock, $this->subjectMock, $this->groupModelMock) + ); } /** * @param array $valueMap * @dataProvider changedDataProvider */ - public function testBeforeAndAfterSaveNotNew($valueMap) + public function testAfterSaveNotNew(array $valueMap): void { - $this->groupMock->expects($this->exactly(2))->method('dataHasChangedFor')->willReturnMap($valueMap); - $this->groupMock->expects($this->once())->method('isObjectNew')->willReturn(true); + $this->groupModelMock->expects($this->exactly(2))->method('dataHasChangedFor')->willReturnMap($valueMap); + $this->groupModelMock->expects($this->once())->method('isObjectNew')->willReturn(true); - $this->model->beforeSave($this->subject, $this->groupMock); - $this->assertSame($this->subject, $this->model->afterSave($this->subject, $this->subject, $this->groupMock)); + $this->assertSame( + $this->subjectMock, + $this->model->afterSave($this->subjectMock, $this->subjectMock, $this->groupModelMock) + ); } /** * @return array */ - public function changedDataProvider() + public function changedDataProvider(): array { return [ [ @@ -106,18 +115,20 @@ public function changedDataProvider() ]; } - public function testBeforeAndAfterSaveWithoutChanges() + public function testAfterSaveWithoutChanges(): void { - $this->groupMock->expects($this->exactly(2)) + $this->groupModelMock->expects($this->exactly(2)) ->method('dataHasChangedFor') ->willReturnMap([['root_category_id', false], ['website_id', false]]); - $this->groupMock->expects($this->never())->method('isObjectNew'); + $this->groupModelMock->expects($this->never())->method('isObjectNew'); - $this->model->beforeSave($this->subject, $this->groupMock); - $this->assertSame($this->subject, $this->model->afterSave($this->subject, $this->subject, $this->groupMock)); + $this->assertSame( + $this->subjectMock, + $this->model->afterSave($this->subjectMock, $this->subjectMock, $this->groupModelMock) + ); } - private function mockIndexerMethods() + private function mockIndexerMethods(): void { $this->indexerMock->expects($this->once())->method('invalidate'); $this->indexerRegistryMock->expects($this->once()) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/StoreViewTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/StoreViewTest.php index 3108934d50f5a..4ecc2404153ba 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/StoreViewTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/StoreViewTest.php @@ -27,27 +27,27 @@ class StoreViewTest extends TestCase /** * @var MockObject|IndexerInterface */ - protected $indexerMock; + private $indexerMock; /** * @var StoreView */ - protected $model; + private $model; /** * @var IndexerRegistry|MockObject */ - protected $indexerRegistryMock; + private $indexerRegistryMock; /** * @var TableMaintainer|MockObject */ - protected $tableMaintainer; + private $tableMaintainerMock; /** - * @var MockObject + * @var Group|MockObject */ - protected $subject; + private $subjectMock; protected function setUp(): void { @@ -60,7 +60,7 @@ protected function setUp(): void true, ['getId', 'getState'] ); - $this->subject = $this->createMock(Group::class); + $this->subjectMock = $this->createMock(Group::class); $this->indexerRegistryMock = $this->createPartialMock(IndexerRegistry::class, ['get']); $this->storeMock = $this->createPartialMock( Store::class, @@ -70,47 +70,56 @@ protected function setUp(): void 'dataHasChangedFor' ] ); - $this->tableMaintainer = $this->createPartialMock( + $this->tableMaintainerMock = $this->createPartialMock( TableMaintainer::class, [ 'createTablesForStore' ] ); - $this->model = new StoreView($this->indexerRegistryMock, $this->tableMaintainer); + $this->model = new StoreView($this->indexerRegistryMock, $this->tableMaintainerMock); } - public function testAroundSaveNewObject() + public function testAfterSaveNewObject(): void { $this->mockIndexerMethods(); $this->storeMock->expects($this->atLeastOnce())->method('isObjectNew')->willReturn(true); $this->storeMock->expects($this->atLeastOnce())->method('getId')->willReturn(1); - $this->model->beforeSave($this->subject, $this->storeMock); - $this->assertSame($this->subject, $this->model->afterSave($this->subject, $this->subject, $this->storeMock)); + + $this->assertSame( + $this->subjectMock, + $this->model->afterSave($this->subjectMock, $this->subjectMock, $this->storeMock) + ); } - public function testAroundSaveHasChanged() + public function testAfterSaveHasChanged(): void { $this->mockIndexerMethods(); $this->storeMock->expects($this->once()) ->method('dataHasChangedFor') ->with('group_id') ->willReturn(true); - $this->model->beforeSave($this->subject, $this->storeMock); - $this->assertSame($this->subject, $this->model->afterSave($this->subject, $this->subject, $this->storeMock)); + + $this->assertSame( + $this->subjectMock, + $this->model->afterSave($this->subjectMock, $this->subjectMock, $this->storeMock) + ); } - public function testAroundSaveNoNeed() + public function testAfterSaveNoNeed(): void { $this->storeMock->expects($this->once()) ->method('dataHasChangedFor') ->with('group_id') ->willReturn(false); - $this->model->beforeSave($this->subject, $this->storeMock); - $this->assertSame($this->subject, $this->model->afterSave($this->subject, $this->subject, $this->storeMock)); + + $this->assertSame( + $this->subjectMock, + $this->model->afterSave($this->subjectMock, $this->subjectMock, $this->storeMock) + ); } - private function mockIndexerMethods() + private function mockIndexerMethods(): void { $this->indexerMock->expects($this->once())->method('invalidate'); $this->indexerRegistryMock->expects($this->once()) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Plugin/StoreViewTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Plugin/StoreViewTest.php index 0d5a3bb93a6bd..4b2c803c66744 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Plugin/StoreViewTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Plugin/StoreViewTest.php @@ -11,50 +11,81 @@ use Magento\Catalog\Model\Indexer\Product\Eav\Processor; use Magento\Framework\Model\AbstractModel; use Magento\Store\Model\ResourceModel\Store; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class StoreViewTest extends TestCase { /** - * @param array $data - * @dataProvider beforeSaveDataProvider + * @var Processor|MockObject + */ + private $eavProcessorMock; + /** + * @var Store|MockObject */ - public function testBeforeSave(array $data) + private $subjectMock; + /** + * @var AbstractModel|MockObject + */ + private $objectMock; + + /** + * @var StoreView + */ + private $storeViewPlugin; + + protected function setUp(): void { - $eavProcessorMock = $this->getMockBuilder(Processor::class) + $this->eavProcessorMock = $this->getMockBuilder(Processor::class) ->disableOriginalConstructor() ->getMock(); - $matcher = $data['matcher']; - $eavProcessorMock->expects($this->$matcher()) - ->method('markIndexerAsInvalid'); - $subjectMock = $this->getMockBuilder(Store::class) + $this->subjectMock = $this->getMockBuilder(Store::class) ->disableOriginalConstructor() ->getMock(); - $objectMock = $this->getMockBuilder(AbstractModel::class) + $this->objectMock = $this->getMockBuilder(AbstractModel::class) ->disableOriginalConstructor() ->setMethods(['getId', 'dataHasChangedFor', 'getIsActive']) ->getMock(); - $objectMock->expects($this->any()) + + $this->storeViewPlugin = new StoreView($this->eavProcessorMock); + } + + /** + * @param array $data + * @dataProvider beforeSaveDataProvider + */ + public function testAfterSave(array $data): void + { + $matcher = $data['matcher']; + + $this->eavProcessorMock->expects($this->$matcher()) + ->method('markIndexerAsInvalid'); + + $this->objectMock->expects($this->any()) ->method('getId') ->willReturn($data['object_id']); - $objectMock->expects($this->any()) + + $this->objectMock->expects($this->any()) ->method('dataHasChangedFor') ->with('group_id') ->willReturn($data['has_group_id_changed']); - $objectMock->expects($this->any()) + + $this->objectMock->expects($this->any()) ->method('getIsActive') ->willReturn($data['is_active']); - $model = new StoreView($eavProcessorMock); - $model->beforeSave($subjectMock, $objectMock); + $this->assertSame( + $this->subjectMock, + $this->storeViewPlugin->afterSave($this->subjectMock, $this->subjectMock, $this->objectMock) + ); } /** * @return array */ - public function beforeSaveDataProvider() + public function beforeSaveDataProvider(): array { return [ [ diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Plugin/StoreGroupTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Plugin/StoreGroupTest.php index 5500081d5e11d..adabfab1560dd 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Plugin/StoreGroupTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Plugin/StoreGroupTest.php @@ -9,6 +9,7 @@ use Magento\Catalog\Model\Indexer\Product\Flat\Plugin\StoreGroup; use Magento\Catalog\Model\Indexer\Product\Flat\Processor; +use Magento\Store\Model\Group as StoreGroupModel; use Magento\Store\Model\ResourceModel\Group; use Magento\Store\Model\Store; use PHPUnit\Framework\MockObject\MockObject; @@ -19,17 +20,22 @@ class StoreGroupTest extends TestCase /** * @var Processor|MockObject */ - protected $processorMock; + private $processorMock; /** * @var Store|MockObject */ - protected $storeGroupMock; + private $storeGroupMock; /** * @var MockObject */ - protected $subjectMock; + private $subjectMock; + + /** + * @var StoreGroup + */ + private $storeGroupPlugin; protected function setUp(): void { @@ -40,9 +46,11 @@ protected function setUp(): void $this->subjectMock = $this->createMock(Group::class); $this->storeGroupMock = $this->createPartialMock( - \Magento\Store\Model\Group::class, + StoreGroupModel::class, ['getId', 'dataHasChangedFor'] ); + + $this->storeGroupPlugin = new StoreGroup($this->processorMock); } /** @@ -50,14 +58,16 @@ protected function setUp(): void * @param int|null $storeId * @dataProvider storeGroupDataProvider */ - public function testBeforeSave($matcherMethod, $storeId) + public function testAfterSave(string $matcherMethod, ?int $storeId): void { $this->processorMock->expects($this->{$matcherMethod}())->method('markIndexerAsInvalid'); $this->storeGroupMock->expects($this->once())->method('getId')->willReturn($storeId); - $model = new StoreGroup($this->processorMock); - $model->beforeSave($this->subjectMock, $this->storeGroupMock); + $this->assertSame( + $this->subjectMock, + $this->storeGroupPlugin->afterSave($this->subjectMock, $this->subjectMock, $this->storeGroupMock) + ); } /** @@ -65,30 +75,25 @@ public function testBeforeSave($matcherMethod, $storeId) * @param bool $websiteChanged * @dataProvider storeGroupWebsiteDataProvider */ - public function testChangedWebsiteBeforeSave($matcherMethod, $websiteChanged) + public function testAfterSaveChangedWebsite(string $matcherMethod, bool $websiteChanged): void { $this->processorMock->expects($this->{$matcherMethod}())->method('markIndexerAsInvalid'); $this->storeGroupMock->expects($this->once())->method('getId')->willReturn(1); - $this->storeGroupMock->expects( - $this->once() - )->method( - 'dataHasChangedFor' - )->with( - 'root_category_id' - )->willReturn( - $websiteChanged - ); + $this->storeGroupMock->expects($this->once())->method('dataHasChangedFor') + ->with('root_category_id')->willReturn($websiteChanged); - $model = new StoreGroup($this->processorMock); - $model->beforeSave($this->subjectMock, $this->storeGroupMock); + $this->assertSame( + $this->subjectMock, + $this->storeGroupPlugin->afterSave($this->subjectMock, $this->subjectMock, $this->storeGroupMock) + ); } /** * @return array */ - public function storeGroupWebsiteDataProvider() + public function storeGroupWebsiteDataProvider(): array { return [['once', true], ['never', false]]; } @@ -96,7 +101,7 @@ public function storeGroupWebsiteDataProvider() /** * @return array */ - public function storeGroupDataProvider() + public function storeGroupDataProvider(): array { return [['once', null], ['never', 1]]; } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Plugin/StoreTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Plugin/StoreTest.php index 1b74039fa944c..219149a57d361 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Plugin/StoreTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Plugin/StoreTest.php @@ -7,7 +7,9 @@ namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Flat\Plugin; +use Magento\Catalog\Model\Indexer\Product\Flat\Plugin\Store as StorePlugin; use Magento\Catalog\Model\Indexer\Product\Flat\Processor; +use Magento\Store\Model\ResourceModel\Store as StoreResourceModel; use Magento\Store\Model\Store; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -17,17 +19,22 @@ class StoreTest extends TestCase /** * @var Processor|MockObject */ - protected $processorMock; + private $processorMock; /** * @var Store|MockObject */ - protected $storeMock; + private $storeMock; /** * @var MockObject */ - protected $subjectMock; + private $subjectMock; + + /** + * @var StorePlugin + */ + private $storePlugin; protected function setUp(): void { @@ -36,11 +43,13 @@ protected function setUp(): void ['markIndexerAsInvalid'] ); - $this->subjectMock = $this->createMock(\Magento\Store\Model\ResourceModel\Store::class); + $this->subjectMock = $this->createMock(StoreResourceModel::class); $this->storeMock = $this->createPartialMock( Store::class, ['getId', 'dataHasChangedFor'] ); + + $this->storePlugin = new StorePlugin($this->processorMock); } /** @@ -48,14 +57,16 @@ protected function setUp(): void * @param int|null $storeId * @dataProvider storeDataProvider */ - public function testBeforeSave($matcherMethod, $storeId) + public function testAfterSave(string $matcherMethod, ?int $storeId): void { $this->processorMock->expects($this->{$matcherMethod}())->method('markIndexerAsInvalid'); $this->storeMock->expects($this->once())->method('getId')->willReturn($storeId); - $model = new \Magento\Catalog\Model\Indexer\Product\Flat\Plugin\Store($this->processorMock); - $model->beforeSave($this->subjectMock, $this->storeMock); + $this->assertSame( + $this->subjectMock, + $this->storePlugin->afterSave($this->subjectMock, $this->subjectMock, $this->storeMock) + ); } /** @@ -63,30 +74,25 @@ public function testBeforeSave($matcherMethod, $storeId) * @param bool $storeGroupChanged * @dataProvider storeGroupDataProvider */ - public function testBeforeSaveSwitchStoreGroup($matcherMethod, $storeGroupChanged) + public function testAfterSaveSwitchStoreGroup(string $matcherMethod, bool $storeGroupChanged): void { $this->processorMock->expects($this->{$matcherMethod}())->method('markIndexerAsInvalid'); $this->storeMock->expects($this->once())->method('getId')->willReturn(1); - $this->storeMock->expects( - $this->once() - )->method( - 'dataHasChangedFor' - )->with( - 'group_id' - )->willReturn( - $storeGroupChanged - ); + $this->storeMock->expects($this->once())->method('dataHasChangedFor') + ->with('group_id')->willReturn($storeGroupChanged); - $model = new \Magento\Catalog\Model\Indexer\Product\Flat\Plugin\Store($this->processorMock); - $model->beforeSave($this->subjectMock, $this->storeMock); + $this->assertSame( + $this->subjectMock, + $this->storePlugin->afterSave($this->subjectMock, $this->subjectMock, $this->storeMock) + ); } /** * @return array */ - public function storeGroupDataProvider() + public function storeGroupDataProvider(): array { return [['once', true], ['never', false]]; } @@ -94,7 +100,7 @@ public function storeGroupDataProvider() /** * @return array */ - public function storeDataProvider() + public function storeDataProvider(): array { return [['once', null], ['never', 1]]; } diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Plugin/StoreGroup.php b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Plugin/StoreGroup.php index c171e9bda2612..29a8b1e5404fa 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Plugin/StoreGroup.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Plugin/StoreGroup.php @@ -3,19 +3,24 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\CatalogInventory\Model\Indexer\Stock\Plugin; +use Magento\CatalogInventory\Model\Indexer\Stock\Processor; +use Magento\Framework\Model\AbstractModel; +use Magento\Store\Model\ResourceModel\Group; + class StoreGroup { /** - * @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor + * @var Processor */ protected $_indexerProcessor; /** - * @param \Magento\CatalogInventory\Model\Indexer\Stock\Processor $indexerProcessor + * @param Processor $indexerProcessor */ - public function __construct(\Magento\CatalogInventory\Model\Indexer\Stock\Processor $indexerProcessor) + public function __construct(Processor $indexerProcessor) { $this->_indexerProcessor = $indexerProcessor; } @@ -23,18 +28,19 @@ public function __construct(\Magento\CatalogInventory\Model\Indexer\Stock\Proces /** * Before save handler * - * @param \Magento\Store\Model\ResourceModel\Group $subject - * @param \Magento\Framework\Model\AbstractModel $object + * @param Group $subject + * @param Group $result + * @param AbstractModel $object * - * @return void + * @return Group * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function beforeSave( - \Magento\Store\Model\ResourceModel\Group $subject, - \Magento\Framework\Model\AbstractModel $object - ) { - if (!$object->getId() || $object->dataHasChangedFor('website_id')) { + public function afterSave(Group $subject, Group $result, AbstractModel $object) + { + if ($object->isObjectNew() || $object->dataHasChangedFor('website_id')) { $this->_indexerProcessor->markIndexerAsInvalid(); } + + return $result; } } diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Plugin/StoreGroupTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Plugin/StoreGroupTest.php index 9e2b7f29ce0fa..0e2b6b2f329c1 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Plugin/StoreGroupTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Plugin/StoreGroupTest.php @@ -12,7 +12,6 @@ use Magento\CatalogInventory\Model\Indexer\Stock\Plugin\StoreGroup; use Magento\CatalogInventory\Model\Indexer\Stock\Processor; -use Magento\Framework\Indexer\IndexerInterface; use Magento\Framework\Model\AbstractModel; use Magento\Store\Model\ResourceModel\Group; use PHPUnit\Framework\MockObject\MockObject; @@ -23,24 +22,24 @@ class StoreGroupTest extends TestCase /** * @var StoreGroup */ - protected $_model; + private $model; /** - * @var IndexerInterface|MockObject + * @var Processor|MockObject */ - protected $_indexerMock; + private $indexerProcessorMock; protected function setUp(): void { - $this->_indexerMock = $this->createMock(Processor::class); - $this->_model = new StoreGroup($this->_indexerMock); + $this->indexerProcessorMock = $this->createMock(Processor::class); + $this->model = new StoreGroup($this->indexerProcessorMock); } /** * @param array $data - * @dataProvider beforeSaveDataProvider + * @dataProvider afterSaveDataProvider */ - public function testBeforeSave(array $data) + public function testAfterSave(array $data): void { $subjectMock = $this->createMock(Group::class); $objectMock = $this->createPartialMock( @@ -55,16 +54,19 @@ public function testBeforeSave(array $data) ->with('website_id') ->willReturn($data['has_website_id_changed']); - $this->_indexerMock->expects($this->once()) + $this->indexerProcessorMock->expects($this->once()) ->method('markIndexerAsInvalid'); - $this->_model->beforeSave($subjectMock, $objectMock); + $this->assertSame( + $subjectMock, + $this->model->afterSave($subjectMock, $subjectMock, $objectMock) + ); } /** * @return array */ - public function beforeSaveDataProvider() + public function afterSaveDataProvider(): array { return [ [ diff --git a/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Plugin/Store/Group.php b/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Plugin/Store/Group.php index 73a79f7c87239..e7bbf72bdd7e3 100644 --- a/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Plugin/Store/Group.php +++ b/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Plugin/Store/Group.php @@ -5,47 +5,29 @@ */ namespace Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Store; +use Magento\CatalogSearch\Model\Indexer\Fulltext as FulltextIndexer; use Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\AbstractPlugin as AbstractIndexerPlugin; -use Magento\Store\Model\ResourceModel\Group as StoreGroupResourceModel; use Magento\Framework\Model\AbstractModel; -use Magento\CatalogSearch\Model\Indexer\Fulltext as FulltextIndexer; +use Magento\Store\Model\ResourceModel\Group as StoreGroupResourceModel; /** * Plugin for Magento\Store\Model\ResourceModel\Group */ class Group extends AbstractIndexerPlugin { - /** - * @var bool - */ - private $needInvalidation; - - /** - * Check if indexer requires invalidation after store group save - * - * @param StoreGroupResourceModel $subject - * @param AbstractModel $group - * @return void - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function beforeSave(StoreGroupResourceModel $subject, AbstractModel $group) - { - $this->needInvalidation = !$group->isObjectNew() && $group->dataHasChangedFor('website_id'); - } - /** * Invalidate indexer on store group save * * @param StoreGroupResourceModel $subject * @param StoreGroupResourceModel $result + * @param AbstractModel $group * @return StoreGroupResourceModel * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterSave(StoreGroupResourceModel $subject, StoreGroupResourceModel $result) + public function afterSave(StoreGroupResourceModel $subject, StoreGroupResourceModel $result, AbstractModel $group) { - if ($this->needInvalidation) { + if (!$group->isObjectNew() && $group->dataHasChangedFor('website_id')) { $this->indexerRegistry->get(FulltextIndexer::INDEXER_ID)->invalidate(); } diff --git a/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Plugin/Store/View.php b/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Plugin/Store/View.php index 7f0c5fdae6d42..242a4f3f0c36b 100644 --- a/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Plugin/Store/View.php +++ b/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Plugin/Store/View.php @@ -5,47 +5,29 @@ */ namespace Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Store; +use Magento\CatalogSearch\Model\Indexer\Fulltext as FulltextIndexer; use Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\AbstractPlugin as AbstractIndexerPlugin; -use Magento\Store\Model\ResourceModel\Store as StoreResourceModel; use Magento\Framework\Model\AbstractModel; -use Magento\CatalogSearch\Model\Indexer\Fulltext as FulltextIndexer; +use Magento\Store\Model\ResourceModel\Store as StoreResourceModel; /** * Plugin for Magento\Store\Model\ResourceModel\Store */ class View extends AbstractIndexerPlugin { - /** - * @var bool - */ - private $needInvalidation; - - /** - * Check if indexer requires invalidation after store view save - * - * @param StoreResourceModel $subject - * @param AbstractModel $store - * @return void - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function beforeSave(StoreResourceModel $subject, AbstractModel $store) - { - $this->needInvalidation = $store->isObjectNew(); - } - /** * Invalidate indexer on store view save * * @param StoreResourceModel $subject * @param StoreResourceModel $result + * @param AbstractModel $store * @return StoreResourceModel * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterSave(StoreResourceModel $subject, StoreResourceModel $result) + public function afterSave(StoreResourceModel $subject, StoreResourceModel $result, AbstractModel $store) { - if ($this->needInvalidation) { + if ($store->isObjectNew()) { $this->indexerRegistry->get(FulltextIndexer::INDEXER_ID)->invalidate(); } diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/Fulltext/Plugin/Store/GroupTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/Fulltext/Plugin/Store/GroupTest.php index b4a27a4350131..302dd0f1e2684 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/Fulltext/Plugin/Store/GroupTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/Fulltext/Plugin/Store/GroupTest.php @@ -11,7 +11,6 @@ use Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Store\Group as StoreGroupIndexerPlugin; use Magento\Framework\Indexer\IndexerInterface; use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Store\Model\Group as StoreGroup; use Magento\Store\Model\ResourceModel\Group as StoreGroupResourceModel; use PHPUnit\Framework\MockObject\MockObject; @@ -24,11 +23,6 @@ class GroupTest extends TestCase */ private $plugin; - /** - * @var ObjectManagerHelper - */ - private $objectManagerHelper; - /** * @var IndexerRegistry|MockObject */ @@ -64,11 +58,7 @@ protected function setUp(): void ->setMethods(['dataHasChangedFor', 'isObjectNew']) ->getMock(); - $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->plugin = $this->objectManagerHelper->getObject( - StoreGroupIndexerPlugin::class, - ['indexerRegistry' => $this->indexerRegistryMock] - ); + $this->plugin = new StoreGroupIndexerPlugin($this->indexerRegistryMock); } /** @@ -76,9 +66,9 @@ protected function setUp(): void * @param bool $websiteChanged * @param int $invalidateCounter * @return void - * @dataProvider beforeAfterSaveDataProvider + * @dataProvider afterSaveDataProvider */ - public function testBeforeAfterSave($isObjectNew, $websiteChanged, $invalidateCounter) + public function testAfterSave(bool $isObjectNew, bool $websiteChanged, int $invalidateCounter): void { $this->prepareIndexer($invalidateCounter); $this->storeGroupMock->expects(static::any()) @@ -91,14 +81,16 @@ public function testBeforeAfterSave($isObjectNew, $websiteChanged, $invalidateCo $this->indexerMock->expects(static::exactly($invalidateCounter)) ->method('invalidate'); - $this->plugin->beforeSave($this->subjectMock, $this->storeGroupMock); - $this->assertSame($this->subjectMock, $this->plugin->afterSave($this->subjectMock, $this->subjectMock)); + $this->assertSame( + $this->subjectMock, + $this->plugin->afterSave($this->subjectMock, $this->subjectMock, $this->storeGroupMock) + ); } /** * @return array */ - public function beforeAfterSaveDataProvider() + public function afterSaveDataProvider(): array { return [ [false, false, 0], @@ -108,13 +100,16 @@ public function beforeAfterSaveDataProvider() ]; } - public function testAfterDelete() + public function testAfterDelete(): void { $this->prepareIndexer(1); $this->indexerMock->expects(static::once()) ->method('invalidate'); - $this->assertSame($this->subjectMock, $this->plugin->afterDelete($this->subjectMock, $this->subjectMock)); + $this->assertSame( + $this->subjectMock, + $this->plugin->afterDelete($this->subjectMock, $this->subjectMock) + ); } /** @@ -123,7 +118,7 @@ public function testAfterDelete() * @param int $invalidateCounter * @return void */ - private function prepareIndexer($invalidateCounter) + private function prepareIndexer(int $invalidateCounter): void { $this->indexerRegistryMock->expects(static::exactly($invalidateCounter)) ->method('get') diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/Fulltext/Plugin/Store/ViewTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/Fulltext/Plugin/Store/ViewTest.php index f778c9340cbd7..23e1c44c5f7c8 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/Fulltext/Plugin/Store/ViewTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/Fulltext/Plugin/Store/ViewTest.php @@ -11,7 +11,6 @@ use Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Store\View as StoreViewIndexerPlugin; use Magento\Framework\Indexer\IndexerInterface; use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Store\Model\ResourceModel\Store as StoreResourceModel; use Magento\Store\Model\Store; use PHPUnit\Framework\MockObject\MockObject; @@ -24,11 +23,6 @@ class ViewTest extends TestCase */ private $plugin; - /** - * @var ObjectManagerHelper - */ - private $objectManagerHelper; - /** * @var IndexerRegistry|MockObject */ @@ -64,20 +58,16 @@ protected function setUp(): void ->setMethods(['isObjectNew']) ->getMock(); - $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->plugin = $this->objectManagerHelper->getObject( - StoreViewIndexerPlugin::class, - ['indexerRegistry' => $this->indexerRegistryMock] - ); + $this->plugin = new StoreViewIndexerPlugin($this->indexerRegistryMock); } /** * @param bool $isObjectNew * @param int $invalidateCounter * - * @dataProvider beforeAfterSaveDataProvider + * @dataProvider afterSaveDataProvider */ - public function testBeforeAfterSave($isObjectNew, $invalidateCounter) + public function testAfterSave(bool $isObjectNew, int $invalidateCounter): void { $this->prepareIndexer($invalidateCounter); $this->storeMock->expects(static::once()) @@ -86,14 +76,16 @@ public function testBeforeAfterSave($isObjectNew, $invalidateCounter) $this->indexerMock->expects(static::exactly($invalidateCounter)) ->method('invalidate'); - $this->plugin->beforeSave($this->subjectMock, $this->storeMock); - $this->assertSame($this->subjectMock, $this->plugin->afterSave($this->subjectMock, $this->subjectMock)); + $this->assertSame( + $this->subjectMock, + $this->plugin->afterSave($this->subjectMock, $this->subjectMock, $this->storeMock) + ); } /** * @return array */ - public function beforeAfterSaveDataProvider() + public function afterSaveDataProvider(): array { return [ [false, 0], @@ -101,7 +93,7 @@ public function beforeAfterSaveDataProvider() ]; } - public function testAfterDelete() + public function testAfterDelete(): void { $this->prepareIndexer(1); $this->indexerMock->expects(static::once()) @@ -116,7 +108,7 @@ public function testAfterDelete() * @param int $invalidateCounter * @return void */ - private function prepareIndexer($invalidateCounter) + private function prepareIndexer(int $invalidateCounter): void { $this->indexerRegistryMock->expects(static::exactly($invalidateCounter)) ->method('get') diff --git a/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php b/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php index 4c84ea5ae764f..16450ec6ff2c2 100644 --- a/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php +++ b/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php @@ -351,9 +351,6 @@ private function getBillingAddressComponent($paymentCode, $elements) ], ], 'telephone' => [ - 'validation' => [ - 'validate-phoneStrict' => 0, - ], 'config' => [ 'tooltip' => [ 'description' => __('For delivery questions.'), diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml index 916b4d7bdad84..5a0610f5c5b0a 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml @@ -120,8 +120,7 @@ - - + diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontOnePageCheckoutPhoneValidationTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontOnePageCheckoutPhoneValidationTest.xml deleted file mode 100644 index b001128fee906..0000000000000 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontOnePageCheckoutPhoneValidationTest.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - <description value="Validate phone field on checkout page, field must not contain alphabetical symbols"/> - <severity value="MAJOR" /> - <testCaseId value="MC-35292"/> - </annotations> - <before> - <createData entity="_defaultCategory" stepKey="createCategory"/> - <createData entity="ApiSimpleProduct" stepKey="createProduct"> - <requiredEntity createDataKey="createCategory"/> - </createData> - </before> - <after> - <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> - <deleteData createDataKey="createProduct" stepKey="deleteProduct"/> - </after> - - <actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="openCategoryPageOnFrontend"> - <argument name="category" value="$createCategory$"/> - </actionGroup> - - <actionGroup ref="StorefrontAddSimpleProductToCartActionGroup" stepKey="addToCartFromStorefrontProductPage"> - <argument name="product" value="$$createProduct$$"/> - </actionGroup> - - <actionGroup ref="StorefrontOpenCheckoutPageActionGroup" stepKey="guestGoToCheckout"/> - - <fillField userInput="Sample text" selector="{{CheckoutShippingSection.telephone}}" stepKey="enterAlphabeticalSymbols"/> - <see userInput="Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890." selector="{{CheckoutShippingSection.addressFieldValidationError}}" stepKey="checkPhoneFieldValidationIsPassed"/> - </test> -</tests> diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml index ab058110fe66f..192f20653f8c3 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml @@ -223,9 +223,6 @@ </item> </item> <item name="telephone" xsi:type="array"> - <item name="validation" xsi:type="array"> - <item name="validate-phoneStrict" xsi:type="number">0</item> - </item> <item name="config" xsi:type="array"> <item name="tooltip" xsi:type="array"> <item name="description" xsi:type="string" translate="true">For delivery questions.</item> diff --git a/app/code/Magento/Config/Model/Config/Source/Email/Template.php b/app/code/Magento/Config/Model/Config/Source/Email/Template.php index ac168f16ca182..182faa53e5288 100644 --- a/app/code/Magento/Config/Model/Config/Source/Email/Template.php +++ b/app/code/Magento/Config/Model/Config/Source/Email/Template.php @@ -60,10 +60,12 @@ public function toOptionArray() $this->_coreRegistry->register('config_system_email_template', $collection); } $options = $collection->toOptionArray(); - $templateId = str_replace('/', '_', $this->getPath()); - $templateLabel = $this->_emailConfig->getTemplateLabel($templateId); - $templateLabel = __('%1 (Default)', $templateLabel); - array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]); + if (!empty($this->getPath())) { + $templateId = str_replace('/', '_', $this->getPath()); + $templateLabel = $this->_emailConfig->getTemplateLabel($templateId); + $templateLabel = __('%1 (Default)', $templateLabel); + array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]); + } return $options; } } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php index 356d1133aca81..9b531280f66c6 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php @@ -102,4 +102,53 @@ public function testToOptionArray() $this->_model->setPath('template/new'); $this->assertEquals($expectedResult, $this->_model->toOptionArray()); } + + public function testToOptionArrayWithoutPath() + { + $collection = $this->createMock(Collection::class); + $collection->expects( + $this->once() + )->method( + 'toOptionArray' + )->willReturn( + [ + ['value' => 'template_one', 'label' => 'Template One'], + ['value' => 'template_two', 'label' => 'Template Two'], + ] + ); + + $this->_coreRegistry->expects( + $this->once() + )->method( + 'registry' + )->with( + 'config_system_email_template' + )->willReturn( + $collection + ); + + $this->_emailConfig->expects( + $this->never() + )->method( + 'getTemplateLabel' + )->with( + '' + ) + ->willThrowException( + new \UnexpectedValueException("Email template '' is not defined.") + ); + + $expectedResult = [ + [ + 'value' => 'template_one', + 'label' => 'Template One', + ], + [ + 'value' => 'template_two', + 'label' => 'Template Two', + ], + ]; + + $this->assertEquals($expectedResult, $this->_model->toOptionArray()); + } } diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/NoOptionAvailableToConfigureDisabledProductTest.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/NoOptionAvailableToConfigureDisabledProductTest.xml index 902787ac58e8c..b87ddf612be19 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/NoOptionAvailableToConfigureDisabledProductTest.xml +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/NoOptionAvailableToConfigureDisabledProductTest.xml @@ -176,7 +176,7 @@ <waitForPageLoad stepKey="waitForShippingMethods"/> <click selector="{{AdminInvoicePaymentShippingSection.shippingMethod}}" stepKey="chooseShippingMethod"/> <waitForPageLoad stepKey="waitForShippingMethodLoad"/> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="clickSubmitOrder" /> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="checkOrderSuccessfullyCreated"/> </test> </tests> diff --git a/app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml b/app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml index 695fc138e592b..e31be78185aaf 100644 --- a/app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml +++ b/app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml @@ -19,7 +19,7 @@ <item>Bld D</item> </array> <data key="company">Magento</data> - <data key="telephone">123-456-7890</data> + <data key="telephone">1234568910</data> <data key="fax">1234568910</data> <data key="postcode">78729</data> <data key="city">Austin</data> @@ -172,7 +172,7 @@ <data key="city">London</data> <data key="postcode">SE1 7RW</data> <data key="country_id">GB</data> - <data key="telephone">444-444-4444</data> + <data key="telephone">444-44-444-44</data> </entity> <entity name="US_Address_Utah" type="address"> <data key="firstname">John</data> @@ -227,7 +227,7 @@ <data key="firstname">John</data> <data key="lastname">Doe</data> <data key="company">Magento</data> - <data key="telephone">888-777-7890</data> + <data key="telephone">0123456789-02134567</data> <array key="street"> <item>172, Westminster Bridge Rd</item> <item>7700 xyz street</item> @@ -305,7 +305,7 @@ <data key="firstname">Jane</data> <data key="lastname">Miller</data> <data key="company">Magento</data> - <data key="telephone">123-456-7899</data> + <data key="telephone">44 20 7123 1234</data> <array key="street"> <item>1 London Bridge Street</item> </array> diff --git a/app/code/Magento/Customer/view/frontend/web/js/validation.js b/app/code/Magento/Customer/view/frontend/web/js/validation.js index 1f7f24d5ac031..9ffc8137135da 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/validation.js +++ b/app/code/Magento/Customer/view/frontend/web/js/validation.js @@ -8,6 +8,20 @@ define([ ], function ($, moment, utils) { 'use strict'; + $.validator.addMethod( + 'validate-date', + function (value, element, params) { + var dateFormat = utils.convertToMomentFormat(params.dateFormat); + + if (value === '') { + return true; + } + + return moment(value, dateFormat, true).isValid(); + }, + $.mage.__('Invalid date') + ); + $.validator.addMethod( 'validate-dob', function (value, element, params) { diff --git a/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/ActionGroup/AdminEditCategoryInGridPageActionGroup.xml b/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/ActionGroup/AdminEditCategoryInGridPageActionGroup.xml index ccdebccab4e65..50ee9e890ad20 100644 --- a/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/ActionGroup/AdminEditCategoryInGridPageActionGroup.xml +++ b/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/ActionGroup/AdminEditCategoryInGridPageActionGroup.xml @@ -11,7 +11,12 @@ <annotations> <description>Clicks the Edit action from the Media Gallery Category Grid</description> </annotations> - <click selector="{{AdminMediaGalleryCatalogUiCategoryGridSection.edit('2', 'Edit')}}" stepKey="clickOnCategoryRow"/> + + <arguments> + <argument name="categoryName" type="string"/> + </arguments> + + <click selector="{{AdminMediaGalleryCatalogUiCategoryGridSection.edit(categoryName, 'Edit')}}" stepKey="clickOnCategoryRow"/> <waitForPageLoad time="30" stepKey="waitForCategoryDetailsPageLoad"/> </actionGroup> </actionGroups> diff --git a/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Section/AdminMediaGalleryCatalogUiCategoryGridSection.xml b/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Section/AdminMediaGalleryCatalogUiCategoryGridSection.xml index ffd3c14c297c3..b787f6feaf61e 100644 --- a/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Section/AdminMediaGalleryCatalogUiCategoryGridSection.xml +++ b/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Section/AdminMediaGalleryCatalogUiCategoryGridSection.xml @@ -15,8 +15,8 @@ <element name="name" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Name')]/preceding-sibling::th) +1 ]//*[text()='{{categoryName}}']" parameterized="true"/> <element name="displayMode" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Display Mode')]/preceding-sibling::th) +1 ]//*[text()='{{productsText}}']" parameterized="true"/> <element name="products" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Products')]/preceding-sibling::th) +1 ]//*[text()='{{productsQty}}']" parameterized="true"/> + <element name="edit" type="button" selector="//tr[td//text()[contains(., '{{categoryName}}')]]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Action')]/preceding-sibling::th) +1 ]//*[text()='{{actionButton}}']" parameterized="true"/> <element name="inMenu" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'In Menu')]/preceding-sibling::th) +1 ]//*[text()='{{inMenuValue}}']" parameterized="true"/> <element name="enabled" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Enabled')]/preceding-sibling::th) +1 ]//*[text()='{{enabledValue}}']" parameterized="true"/> - <element name="edit" type="button" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Action')]/preceding-sibling::th) +1 ]//*[text()='{{edit}}']" parameterized="true"/> </section> </sections> diff --git a/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Test/AdminMediaGalleryCatalogUiEditCategoryGridPageTest.xml b/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Test/AdminMediaGalleryCatalogUiEditCategoryGridPageTest.xml index b20f63a005279..2a606d8ab6a9e 100644 --- a/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Test/AdminMediaGalleryCatalogUiEditCategoryGridPageTest.xml +++ b/app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Test/AdminMediaGalleryCatalogUiEditCategoryGridPageTest.xml @@ -26,7 +26,9 @@ <deleteData createDataKey="category" stepKey="deleteCategory"/> </after> <actionGroup ref="AdminOpenCategoryGridPageActionGroup" stepKey="openCategoryPage"/> - <actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItem"/> + <actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItem"> + <argument name="categoryName" value="$$category.name$$"/> + </actionGroup> <actionGroup ref="AdminAssertCategoryPageTitleActionGroup" stepKey="assertCategoryByName"/> </test> </tests> diff --git a/app/code/Magento/Quote/Model/ChangeQuoteControl.php b/app/code/Magento/Quote/Model/ChangeQuoteControl.php index b88898a816d66..92e25ca6c7d3a 100644 --- a/app/code/Magento/Quote/Model/ChangeQuoteControl.php +++ b/app/code/Magento/Quote/Model/ChangeQuoteControl.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Quote\Model; @@ -12,13 +11,10 @@ use Magento\Quote\Api\ChangeQuoteControlInterface; use Magento\Quote\Api\Data\CartInterface; -/** - * {@inheritdoc} - */ class ChangeQuoteControl implements ChangeQuoteControlInterface { /** - * @var UserContextInterface $userContext + * @var UserContextInterface */ private $userContext; @@ -31,25 +27,20 @@ public function __construct(UserContextInterface $userContext) } /** - * {@inheritdoc} + * @inheritdoc */ public function isAllowed(CartInterface $quote): bool { switch ($this->userContext->getUserType()) { case UserContextInterface::USER_TYPE_CUSTOMER: - $isAllowed = ($quote->getCustomerId() == $this->userContext->getUserId()); - break; + return ($quote->getCustomerId() == $this->userContext->getUserId()); case UserContextInterface::USER_TYPE_GUEST: - $isAllowed = ($quote->getCustomerId() === null); - break; + return ($quote->getCustomerId() === null); case UserContextInterface::USER_TYPE_ADMIN: case UserContextInterface::USER_TYPE_INTEGRATION: - $isAllowed = true; - break; - default: - $isAllowed = false; + return true; } - return $isAllowed; + return false; } } diff --git a/app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php b/app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php index 79b518fc54534..eda0e9638cc0d 100644 --- a/app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php +++ b/app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Quote\Model\QuoteRepository\Plugin; @@ -32,16 +33,17 @@ public function __construct(ChangeQuoteControlInterface $changeQuoteControl) /** * Checks if change quote's customer id is allowed for current user. * + * A StateException is thrown if Guest's or Customer's customer_id not match user_id or unknown user type + * * @param CartRepositoryInterface $subject * @param CartInterface $quote - * @throws StateException if Guest has customer_id or Customer's customer_id not much with user_id - * or unknown user's type * @return void + * @throws StateException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function beforeSave(CartRepositoryInterface $subject, CartInterface $quote) + public function beforeSave(CartRepositoryInterface $subject, CartInterface $quote): void { - if (! $this->changeQuoteControl->isAllowed($quote)) { + if (!$this->changeQuoteControl->isAllowed($quote)) { throw new StateException(__("Invalid state change requested")); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/ChangeQuoteControlTest.php b/app/code/Magento/Quote/Test/Unit/Model/ChangeQuoteControlTest.php index f302372344c11..a467f3e25d698 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/ChangeQuoteControlTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/ChangeQuoteControlTest.php @@ -16,130 +16,94 @@ /** * Unit test for \Magento\Quote\Model\ChangeQuoteControl - * - * Class \Magento\Quote\Test\Unit\Model\ChangeQuoteControlTest */ class ChangeQuoteControlTest extends TestCase { - /** - * @var ObjectManager - */ - protected $objectManager; - /** * @var ChangeQuoteControl */ protected $model; /** - * @var MockObject + * @var MockObject|UserContextInterface */ protected $userContextMock; /** - * @var MockObject + * @var MockObject|CartInterface */ protected $quoteMock; protected function setUp(): void { - $this->objectManager = new ObjectManager($this); $this->userContextMock = $this->getMockForAbstractClass(UserContextInterface::class); - $this->model = $this->objectManager->getObject( - ChangeQuoteControl::class, - [ - 'userContext' => $this->userContextMock - ] - ); - - $this->quoteMock = $this->getMockForAbstractClass( - CartInterface::class, - [], - '', - false, - true, - true, - ['getCustomerId'] - ); + $this->model = new ChangeQuoteControl($this->userContextMock); + + $this->quoteMock = $this->getMockBuilder(CartInterface::class) + ->disableOriginalConstructor() + ->addMethods(['getCustomerId']) + ->getMockForAbstractClass(); } - /** - * Test if the quote is belonged to customer - */ public function testIsAllowedIfTheQuoteIsBelongedToCustomer() { $quoteCustomerId = 1; - $this->quoteMock->expects($this->any())->method('getCustomerId') + $this->quoteMock->method('getCustomerId') ->willReturn($quoteCustomerId); - $this->userContextMock->expects($this->any())->method('getUserType') + $this->userContextMock->method('getUserType') ->willReturn(UserContextInterface::USER_TYPE_CUSTOMER); - $this->userContextMock->expects($this->any())->method('getUserId') + $this->userContextMock->method('getUserId') ->willReturn($quoteCustomerId); $this->assertTrue($this->model->isAllowed($this->quoteMock)); } - /** - * Test if the quote is not belonged to customer - */ public function testIsAllowedIfTheQuoteIsNotBelongedToCustomer() { $currentCustomerId = 1; $quoteCustomerId = 2; - $this->quoteMock->expects($this->any())->method('getCustomerId') + $this->quoteMock->method('getCustomerId') ->willReturn($quoteCustomerId); - $this->userContextMock->expects($this->any())->method('getUserType') + $this->userContextMock->method('getUserType') ->willReturn(UserContextInterface::USER_TYPE_CUSTOMER); - $this->userContextMock->expects($this->any())->method('getUserId') + $this->userContextMock->method('getUserId') ->willReturn($currentCustomerId); $this->assertFalse($this->model->isAllowed($this->quoteMock)); } - /** - * Test if the quote is belonged to guest and the context is guest - */ public function testIsAllowedIfQuoteIsBelongedToGuestAndContextIsGuest() { $quoteCustomerId = null; - $this->quoteMock->expects($this->any())->method('getCustomerId') + $this->quoteMock->method('getCustomerId') ->willReturn($quoteCustomerId); - $this->userContextMock->expects($this->any())->method('getUserType') + $this->userContextMock->method('getUserType') ->willReturn(UserContextInterface::USER_TYPE_GUEST); $this->assertTrue($this->model->isAllowed($this->quoteMock)); } - /** - * Test if the quote is belonged to customer and the context is guest - */ public function testIsAllowedIfQuoteIsBelongedToCustomerAndContextIsGuest() { $quoteCustomerId = 1; - $this->quoteMock->expects($this->any())->method('getCustomerId') + $this->quoteMock->method('getCustomerId') ->willReturn($quoteCustomerId); - $this->userContextMock->expects($this->any())->method('getUserType') + $this->userContextMock->method('getUserType') ->willReturn(UserContextInterface::USER_TYPE_GUEST); $this->assertFalse($this->model->isAllowed($this->quoteMock)); } - /** - * Test if the context is admin - */ public function testIsAllowedIfContextIsAdmin() { - $this->userContextMock->expects($this->any())->method('getUserType') + $this->userContextMock->method('getUserType') ->willReturn(UserContextInterface::USER_TYPE_ADMIN); $this->assertTrue($this->model->isAllowed($this->quoteMock)); } - /** - * Test if the context is integration - */ public function testIsAllowedIfContextIsIntegration() { - $this->userContextMock->expects($this->any())->method('getUserType') + $this->userContextMock->method('getUserType') ->willReturn(UserContextInterface::USER_TYPE_INTEGRATION); $this->assertTrue($this->model->isAllowed($this->quoteMock)); } diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteRepository/Plugin/AccessChangeQuoteControlTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteRepository/Plugin/AccessChangeQuoteControlTest.php index 85098d2f23448..199ddfd9b9120 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteRepository/Plugin/AccessChangeQuoteControlTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteRepository/Plugin/AccessChangeQuoteControlTest.php @@ -8,6 +8,7 @@ namespace Magento\Quote\Test\Unit\Model\QuoteRepository\Plugin; use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\Exception\StateException; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Quote\Model\ChangeQuoteControl; use Magento\Quote\Model\Quote; @@ -52,7 +53,7 @@ protected function setUp(): void $this->quoteMock = $this->getMockBuilder(Quote::class) ->disableOriginalConstructor() - ->setMethods(['getCustomerId']) + ->addMethods(['getCustomerId']) ->getMock(); $this->quoteRepositoryMock = $this->getMockBuilder(QuoteRepository::class) @@ -63,17 +64,10 @@ protected function setUp(): void ->disableOriginalConstructor() ->getMock(); - $objectManagerHelper = new ObjectManager($this); - $this->accessChangeQuoteControl = $objectManagerHelper->getObject( - AccessChangeQuoteControl::class, - ['changeQuoteControl' => $this->changeQuoteControlMock] - ); + $this->accessChangeQuoteControl = new AccessChangeQuoteControl($this->changeQuoteControlMock); } - /** - * User with role Customer and customer_id matches context user_id. - */ - public function testBeforeSaveForCustomer() + public function testBeforeSaveForCustomerWithCustomerIdMatchinQuoteUserIdIsAllowed() { $this->quoteMock->method('getCustomerId') ->willReturn(1); @@ -84,17 +78,12 @@ public function testBeforeSaveForCustomer() $this->changeQuoteControlMock->method('isAllowed') ->willReturn(true); - $result = $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock); - - $this->assertNull($result); + $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock); } - /** - * The user_id and customer_id from the quote are different. - */ - public function testBeforeSaveException() + public function testBeforeSaveThrowsExceptionForCustomerWithCustomerIdNotMatchingQuoteUserId() { - $this->expectException('Magento\Framework\Exception\StateException'); + $this->expectException(StateException::class); $this->expectExceptionMessage('Invalid state change requested'); $this->quoteMock->method('getCustomerId') ->willReturn(2); @@ -108,10 +97,7 @@ public function testBeforeSaveException() $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock); } - /** - * User with role Admin and customer_id not much with user_id. - */ - public function testBeforeSaveForAdmin() + public function testBeforeSaveForAdminUserRoleIsAllowed() { $this->quoteMock->method('getCustomerId') ->willReturn(2); @@ -122,15 +108,10 @@ public function testBeforeSaveForAdmin() $this->changeQuoteControlMock->method('isAllowed') ->willReturn(true); - $result = $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock); - - $this->assertNull($result); + $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock); } - /** - * User with role Guest and customer_id === null. - */ - public function testBeforeSaveForGuest() + public function testBeforeSaveForGuestIsAllowed() { $this->quoteMock->method('getCustomerId') ->willReturn(null); @@ -141,17 +122,12 @@ public function testBeforeSaveForGuest() $this->changeQuoteControlMock->method('isAllowed') ->willReturn(true); - $result = $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock); - - $this->assertNull($result); + $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock); } - /** - * User with role Guest and customer_id !== null. - */ - public function testBeforeSaveForGuestException() + public function testBeforeSaveThrowsExceptionForGuestDoesNotEquals() { - $this->expectException('Magento\Framework\Exception\StateException'); + $this->expectException(StateException::class); $this->expectExceptionMessage('Invalid state change requested'); $this->quoteMock->method('getCustomerId') ->willReturn(1); @@ -165,12 +141,9 @@ public function testBeforeSaveForGuestException() $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock); } - /** - * User with unknown role. - */ - public function testBeforeSaveForUnknownUserTypeException() + public function testBeforeSaveThrowsExceptionForUnknownUserType() { - $this->expectException('Magento\Framework\Exception\StateException'); + $this->expectException(StateException::class); $this->expectExceptionMessage('Invalid state change requested'); $this->quoteMock->method('getCustomerId') ->willReturn(2); diff --git a/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php index d219aefe81d45..16df2d30db40d 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Reports\Model\ResourceModel\Quote\Item; @@ -17,6 +18,8 @@ */ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection { + private const PREPARED_FLAG_NAME = 'reports_collection_prepared'; + /** * Join fields * @@ -99,6 +102,11 @@ protected function _construct() public function prepareActiveCartItems() { $quoteItemsSelect = $this->getSelect(); + + if ($this->getFlag(self::PREPARED_FLAG_NAME)) { + return $quoteItemsSelect; + } + $quoteItemsSelect->reset() ->from(['main_table' => $this->getTable('quote_item')], '') ->columns('main_table.product_id') @@ -114,6 +122,7 @@ public function prepareActiveCartItems() )->group( 'main_table.product_id' ); + $this->setFlag(self::PREPARED_FLAG_NAME, true); return $quoteItemsSelect; } diff --git a/app/code/Magento/Reports/Test/Mftf/Test/AdminReportsOrderedGroupedBySkuTest.xml b/app/code/Magento/Reports/Test/Mftf/Test/AdminReportsOrderedGroupedBySkuTest.xml index a96e74c8ad166..beb1471bd6c4d 100644 --- a/app/code/Magento/Reports/Test/Mftf/Test/AdminReportsOrderedGroupedBySkuTest.xml +++ b/app/code/Magento/Reports/Test/Mftf/Test/AdminReportsOrderedGroupedBySkuTest.xml @@ -45,7 +45,7 @@ <argument name="attribute" value="colorProductAttribute"/> <argument name="option" value="colorProductAttribute1"/> </actionGroup> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitFirstOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitFirstOrder" /> <!--Add second configurable product to order--> <actionGroup ref="NavigateToNewOrderPageExistingCustomerActionGroup" stepKey="navigateToSecondOrderWithExistingCustomer"> @@ -56,7 +56,7 @@ <argument name="attribute" value="colorProductAttribute"/> <argument name="option" value="colorProductAttribute2"/> </actionGroup> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitSecondOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitSecondOrder" /> <!-- Get date --> <generateDate stepKey="generateStartDate" date="-1 minute" format="m/d/Y"/> diff --git a/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php index ea8fcfbb77132..6e7d5bdce16f5 100644 --- a/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php +++ b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php @@ -15,6 +15,7 @@ use Magento\Framework\Event\ManagerInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Quote\Model\ResourceModel\Quote; +use Magento\Reports\Model\ResourceModel\Quote\Collection; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -42,7 +43,7 @@ protected function setUp(): void public function testGetSelectCountSql() { /** @var MockObject $collection */ - $collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Collection::class) + $collection = $this->getMockBuilder(Collection::class) ->setMethods(['getSelect']) ->disableOriginalConstructor() ->getMock(); @@ -62,12 +63,12 @@ public function testPrepareActiveCartItems() $constructArgs = $this->objectManager ->getConstructArguments(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class); $collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class) - ->setMethods(['getSelect', 'getTable']) + ->setMethods(['getSelect', 'getTable', 'getFlag', 'setFlag']) ->disableOriginalConstructor() ->setConstructorArgs($constructArgs) ->getMock(); - $collection->expects($this->once())->method('getSelect')->willReturn($this->selectMock); + $collection->expects($this->exactly(2))->method('getSelect')->willReturn($this->selectMock); $this->selectMock->expects($this->once())->method('reset')->willReturnSelf(); $this->selectMock->expects($this->once())->method('from')->willReturnSelf(); $this->selectMock->expects($this->atLeastOnce())->method('columns')->willReturnSelf(); @@ -75,7 +76,12 @@ public function testPrepareActiveCartItems() $this->selectMock->expects($this->once())->method('where')->willReturnSelf(); $this->selectMock->expects($this->once())->method('group')->willReturnSelf(); $collection->expects($this->exactly(2))->method('getTable')->willReturn('table'); + $collection->expects($this->once())->method('setFlag') + ->with('reports_collection_prepared')->willReturnSelf(); $collection->prepareActiveCartItems(); + $collection->method('getFlag') + ->with('reports_collection_prepared')->willReturn(true); + $this->assertEquals($this->selectMock, $collection->prepareActiveCartItems()); } public function testLoadWithFilter() diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php index de15a627583ff..47395b17afee8 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php @@ -9,7 +9,7 @@ use Magento\Sales\Model\Order; /** - * Class State + * Checking order status and adjusting order status before saving */ class State { @@ -34,6 +34,7 @@ public function check(Order $order) if (in_array($currentState, [Order::STATE_PROCESSING, Order::STATE_COMPLETE]) && !$order->canCreditmemo() && !$order->canShip() + && $order->getIsNotVirtual() ) { $order->setState(Order::STATE_CLOSED) ->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_CLOSED)); diff --git a/app/code/Magento/Sales/Test/Mftf/ActionGroup/AdminOrderClickSubmitOrderActionGroup.xml b/app/code/Magento/Sales/Test/Mftf/ActionGroup/AdminOrderClickSubmitOrderActionGroup.xml new file mode 100644 index 0000000000000..cf64806cda084 --- /dev/null +++ b/app/code/Magento/Sales/Test/Mftf/ActionGroup/AdminOrderClickSubmitOrderActionGroup.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminOrderClickSubmitOrderActionGroup"> + <annotations> + <description>Click "Submit Order" button for order.</description> + </annotations> + + <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder"/> + <waitForPageLoad stepKey="waitForOrderPageToLoad"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminAvailabilityCreditMemoWithNoPaymentTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminAvailabilityCreditMemoWithNoPaymentTest.xml index 0eb8d71223276..182549a6fe301 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminAvailabilityCreditMemoWithNoPaymentTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminAvailabilityCreditMemoWithNoPaymentTest.xml @@ -72,9 +72,7 @@ <!-- Select Free shipping --> <actionGroup ref="OrderSelectFreeShippingActionGroup" stepKey="selectFreeShippingOption"/> - - <!--Click *Submit Order* button--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="clickSubmitOrder" /> <!--Click *Invoice* button--> <actionGroup ref="StartCreateInvoiceFromOrderPageActionGroup" stepKey="startCreateInvoice"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithBankTransferPaymentMethodTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithBankTransferPaymentMethodTest.xml index bb1940357a7f4..80336ea29e9d5 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithBankTransferPaymentMethodTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithBankTransferPaymentMethodTest.xml @@ -59,9 +59,7 @@ <!-- Select bank Transfer payment method --> <waitForElementVisible selector="{{AdminOrderFormPaymentSection.paymentBlock}}" stepKey="waitForPaymentOptions"/> <conditionalClick selector="{{AdminOrderFormPaymentSection.bankTransferOption}}" dependentSelector="{{AdminOrderFormPaymentSection.bankTransferOption}}" visible="true" stepKey="checkBankTransferOption"/> - - <!-- Submit order --> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!-- Verify order information --> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithCashOnDeliveryPaymentMethodTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithCashOnDeliveryPaymentMethodTest.xml index dafd00ff60b29..5f454152de20c 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithCashOnDeliveryPaymentMethodTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithCashOnDeliveryPaymentMethodTest.xml @@ -59,9 +59,7 @@ <!-- Select Cash On Delivery payment method --> <waitForElementVisible selector="{{AdminOrderFormPaymentSection.paymentBlock}}" stepKey="waitForPaymentOptions"/> <checkOption selector="{{AdminOrderFormPaymentSection.cashOnDeliveryOption}}" stepKey="selectCashOnDeliveryPaymentOption"/> - - <!-- Submit order --> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!--Verify order information--> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithCheckMoneyOrderPaymentMethodTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithCheckMoneyOrderPaymentMethodTest.xml index 4e750c2cc24b3..7d6e2048c9432 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithCheckMoneyOrderPaymentMethodTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithCheckMoneyOrderPaymentMethodTest.xml @@ -149,7 +149,7 @@ <actionGroup ref="AdminSelectFlatRateShippingMethodActionGroup" stepKey="selectFlatRateShippingMethod"/> <!-- Submit order --> <comment userInput="Submit order" stepKey="submitOrderComment"/> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!-- Verify order information --> <comment userInput="Verify order information" stepKey="verifyOrderInformationComment"/> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithProductQtyWithoutStockDecreaseTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithProductQtyWithoutStockDecreaseTest.xml index 62425cefb20db..f47513bcadedd 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithProductQtyWithoutStockDecreaseTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithProductQtyWithoutStockDecreaseTest.xml @@ -58,9 +58,7 @@ <!--Select FlatRate shipping method--> <actionGroup ref="AdminSelectFlatRateShippingMethodActionGroup" stepKey="selectFlatRateShippingMethod"/> - - <!--Submit order--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!--Verify order information--> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> @@ -109,7 +107,7 @@ <!-- Reorder the product --> <click selector="{{AdminOrderDetailsMainActionsSection.reorder}}" stepKey="clickOnReorderButton"/> <waitForPageLoad stepKey="waitForReorderFormToLoad"/> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder1"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder1" /> <!-- Assert Simple Product Quantity in backend after Reorder --> <actionGroup ref="FilterAndSelectProductActionGroup" stepKey="filterAndSelectTheProduct2"> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithPurchaseOrderPaymentMethodTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithPurchaseOrderPaymentMethodTest.xml index 0b873de34e279..9f09a59fa8d5e 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithPurchaseOrderPaymentMethodTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithPurchaseOrderPaymentMethodTest.xml @@ -69,9 +69,7 @@ <fillField selector="{{AdminOrderFormPaymentSection.purchaseOrderNumber}}" userInput="{{PurchaseOrderNumber.number}}" stepKey="fillPurchaseOrderNumber"/> <click selector="{{AdminOrderFormActionSection.pageHeader}}" stepKey="clickOnHeader"/> <waitForPageLoad stepKey="waitForPageToLoad"/> - - <!--Submit order--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!--Verify order information--> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithZeroSubtotalCheckoutTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithZeroSubtotalCheckoutTest.xml index d22e11bca3d0e..6ce9909d06be5 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithZeroSubtotalCheckoutTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminCancelTheCreatedOrderWithZeroSubtotalCheckoutTest.xml @@ -60,9 +60,7 @@ <!--Select FlatRate shipping method--> <actionGroup ref="AdminSelectFlatRateShippingMethodActionGroup" stepKey="selectFlatRateShippingMethod"/> - - <!--Submit order--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!--Verify order information--> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateCreditMemoWithPurchaseOrderTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateCreditMemoWithPurchaseOrderTest.xml index 7818a1f3d9345..56399401b205e 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateCreditMemoWithPurchaseOrderTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateCreditMemoWithPurchaseOrderTest.xml @@ -61,8 +61,7 @@ <fillField selector="{{AdminOrderFormPaymentSection.fieldPurchaseOrderNumber}}" userInput="123456" stepKey="fillPONumber"/> <click selector="{{AdminOrderFormPaymentSection.blockPayment}}" stepKey="unfocus"/> <waitForPageLoad stepKey="waitForJavascriptToFinish"/> - <click selector="{{AdminOrderFormActionSection.submitOrder}}" stepKey="submitOrder"/> - <waitForPageLoad stepKey="waitForSubmitOrderPage"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <see stepKey="seeSuccessMessageForOrder" selector="{{AdminIndexManagementSection.successMessage}}" userInput="You created the order."/> <!-- Create Invoice --> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateOrderWithBundleProductTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateOrderWithBundleProductTest.xml index 1401930131b13..5c49d29ddf22e 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateOrderWithBundleProductTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateOrderWithBundleProductTest.xml @@ -93,9 +93,7 @@ <!--Select FlatRate shipping method--> <actionGroup ref="OrderSelectFlatRateShippingActionGroup" stepKey="orderSelectFlatRateShippingMethod"/> - - <!--Submit order--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!--Verify order information--> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateOrderWithMinimumAmountEnabledTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateOrderWithMinimumAmountEnabledTest.xml index 1f6d7c40be99b..b5c9e9443d1f9 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateOrderWithMinimumAmountEnabledTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminCreateOrderWithMinimumAmountEnabledTest.xml @@ -63,9 +63,7 @@ <see selector="{{AdminOrderFormTotalSection.total('Subtotal')}}" userInput="${{AdminOrderSimpleProduct.subtotal}}" stepKey="seeOrderSubTotal"/> <see selector="{{AdminOrderFormTotalSection.total('Shipping')}}" userInput="${{AdminOrderSimpleProduct.shipping}}" stepKey="seeOrderShipping"/> <see selector="{{AdminOrderFormTotalSection.grandTotal}}" userInput="${{AdminOrderSimpleProduct.grandTotal}}" stepKey="seeCorrectGrandTotal"/> - - <!--Submit Order and verify information--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="clickSubmitOrder" /> <seeInCurrentUrl url="{{AdminOrderDetailsPage.url}}" stepKey="seeViewOrderPage"/> <see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="You created the order." stepKey="seeSuccessMessage"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminFreeShippingNotAvailableIfMinimumOrderAmountNotMatchOrderTotalTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminFreeShippingNotAvailableIfMinimumOrderAmountNotMatchOrderTotalTest.xml index f6196c3a911ef..bf8e7e1868184 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminFreeShippingNotAvailableIfMinimumOrderAmountNotMatchOrderTotalTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminFreeShippingNotAvailableIfMinimumOrderAmountNotMatchOrderTotalTest.xml @@ -58,8 +58,7 @@ <!--Click *Get shipping methods and rates* and see that Free Shipping is absent--> <click selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="clickGetShippingMehods"/> <dontSeeElement selector="{{AdminOrderFormPaymentSection.freeShippingOption}}" stepKey="seeAbsentFreeShipping"/> - <!--Submit Order and verify that Order isn't placed--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="clickSubmitOrder" /> <dontSeeElement selector="{{AdminOrderFormMessagesSection.success}}" stepKey="seeSuccessMessage"/> <seeElement selector="{{AdminOrderFormMessagesSection.error}}" stepKey="seeErrorMessage"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminHoldCreatedOrderTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminHoldCreatedOrderTest.xml index 8d328beab1adc..a73e64cfbca10 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminHoldCreatedOrderTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminHoldCreatedOrderTest.xml @@ -60,9 +60,7 @@ <!--Select FlatRate shipping method--> <actionGroup ref="AdminSelectFlatRateShippingMethodActionGroup" stepKey="selectFlatRateShippingMethod"/> - - <!-- Submit order --> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!-- Verify order information --> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/AdminSubmitConfigurableProductOrderTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/AdminSubmitConfigurableProductOrderTest.xml index 54ae549967a3b..beaf098eee246 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/AdminSubmitConfigurableProductOrderTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/AdminSubmitConfigurableProductOrderTest.xml @@ -114,9 +114,7 @@ <!-- Checkout select Check/Money Order payment --> <actionGroup ref="SelectCheckMoneyPaymentMethodActionGroup" stepKey="selectCheckMoneyPayment"/> - - <!--Submit order--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!--Verify order information--> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/CheckXSSVulnerabilityDuringOrderCreationTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/CheckXSSVulnerabilityDuringOrderCreationTest.xml index df6a797372e62..528b6b61f4842 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/CheckXSSVulnerabilityDuringOrderCreationTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/CheckXSSVulnerabilityDuringOrderCreationTest.xml @@ -54,7 +54,7 @@ <!-- Try to create order in admin with provided email --> <actionGroup ref="NavigateToNewOrderPageNewCustomerSingleStoreActionGroup" stepKey="navigateToNewOrderPage"/> <fillField selector="{{AdminOrderFormAccountSection.email}}" userInput="{{Simple_US_Customer_Incorrect_Email.email}}" stepKey="fillEmailAddressAdminPanel"/> - <click selector="{{AdminOrderFormActionSection.submitOrder}}" stepKey="clickSubmitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="clickSubmitOrder" /> <!-- Order can not be created --> <actionGroup ref="AssertAdminEmailValidationMessageOnCheckoutActionGroup" stepKey="assertErrorMessageAdminPanel"/> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/CreateOrderFromEditCustomerPageTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/CreateOrderFromEditCustomerPageTest.xml index 842faeb32cc33..ca705405809bd 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/CreateOrderFromEditCustomerPageTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/CreateOrderFromEditCustomerPageTest.xml @@ -186,10 +186,7 @@ <waitForPageLoad stepKey="waitForShippingMethods"/> <click selector="{{AdminOrderFormPaymentSection.freeShippingOption}}" stepKey="chooseShippingMethod"/> <waitForPageLoad stepKey="waitForPageToLoad"/> - - <!-- Submit order --> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/> - <waitForPageLoad stepKey="waitForAdminOrderFormLoad"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="submitOrder" /> <!-- Verify order information --> <actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/> diff --git a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php index ea655bb32f05f..a48f0702f5a4b 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php @@ -41,7 +41,8 @@ protected function setUp(): void 'getBaseGrandTotal', 'canCreditmemo', 'getTotalRefunded', - 'getConfig' + 'getConfig', + 'getIsNotVirtual' ] ) ->disableOriginalConstructor() @@ -49,24 +50,21 @@ protected function setUp(): void $this->orderMock->expects($this->any()) ->method('getConfig') ->willReturnSelf(); - $this->addressMock = $this->createMock(Address::class); - $this->addressCollectionMock = $this->createMock( - Collection::class - ); $this->state = new State(); } /** - * @param bool $isCanceled - * @param bool $canUnhold - * @param bool $canInvoice - * @param bool $canShip - * @param int $callCanSkipNum * @param bool $canCreditmemo * @param int $callCanCreditmemoNum + * @param bool $canShip + * @param int $callCanSkipNum * @param string $currentState * @param string $expectedState - * @param int $callSetStateNum + * @param bool $isInProcess + * @param int $callGetIsInProcessNum + * @param bool $isCanceled + * @param bool $canUnhold + * @param bool $isNotVirtual * @dataProvider stateCheckDataProvider * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -76,12 +74,12 @@ public function testCheck( bool $canShip, int $callCanSkipNum, string $currentState, - string $expectedState = '', - bool $isInProcess = false, - int $callGetIsInProcessNum = 0, - bool $isCanceled = false, - bool $canUnhold = false, - bool $canInvoice = false + string $expectedState, + bool $isInProcess, + int $callGetIsInProcessNum, + bool $isCanceled, + bool $canUnhold, + bool $isNotVirtual ) { $this->orderMock->setState($currentState); $this->orderMock->expects($this->any()) @@ -92,7 +90,7 @@ public function testCheck( ->willReturn($canUnhold); $this->orderMock->expects($this->any()) ->method('canInvoice') - ->willReturn($canInvoice); + ->willReturn(false); $this->orderMock->expects($this->exactly($callCanSkipNum)) ->method('canShip') ->willReturn($canShip); @@ -102,11 +100,16 @@ public function testCheck( $this->orderMock->expects($this->exactly($callGetIsInProcessNum)) ->method('getIsInProcess') ->willReturn($isInProcess); + $this->orderMock->method('getIsNotVirtual') + ->willReturn($isNotVirtual); $this->state->check($this->orderMock); $this->assertEquals($expectedState, $this->orderMock->getState()); } /** + * Data provider for testCheck + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @return array */ public function stateCheckDataProvider() @@ -118,7 +121,12 @@ public function stateCheckDataProvider() 'can_ship' => false, 'call_can_skip_num' => 1, 'current_state' => Order::STATE_PROCESSING, - 'expected_state' => Order::STATE_CLOSED + 'expected_state' => Order::STATE_CLOSED, + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'complete - !canCreditmemo,!canShip -> closed' => [ 'can_credit_memo' => false, @@ -126,7 +134,12 @@ public function stateCheckDataProvider() 'can_ship' => false, 'call_can_skip_num' => 1, 'current_state' => Order::STATE_COMPLETE, - 'expected_state' => Order::STATE_CLOSED + 'expected_state' => Order::STATE_CLOSED, + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'processing - !canCreditmemo,canShip -> processing' => [ 'can_credit_memo' => false, @@ -134,7 +147,12 @@ public function stateCheckDataProvider() 'can_ship' => true, 'call_can_skip_num' => 2, 'current_state' => Order::STATE_PROCESSING, - 'expected_state' => Order::STATE_PROCESSING + 'expected_state' => Order::STATE_PROCESSING, + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'complete - !canCreditmemo,canShip -> complete' => [ 'can_credit_memo' => false, @@ -142,7 +160,12 @@ public function stateCheckDataProvider() 'can_ship' => true, 'call_can_skip_num' => 1, 'current_state' => Order::STATE_COMPLETE, - 'expected_state' => Order::STATE_COMPLETE + 'expected_state' => Order::STATE_COMPLETE, + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'processing - canCreditmemo,!canShip -> complete' => [ 'can_credit_memo' => true, @@ -150,7 +173,12 @@ public function stateCheckDataProvider() 'can_ship' => false, 'call_can_skip_num' => 1, 'current_state' => Order::STATE_PROCESSING, - 'expected_state' => Order::STATE_COMPLETE + 'expected_state' => Order::STATE_COMPLETE, + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'complete - canCreditmemo,!canShip -> complete' => [ 'can_credit_memo' => true, @@ -158,7 +186,12 @@ public function stateCheckDataProvider() 'can_ship' => false, 'call_can_skip_num' => 0, 'current_state' => Order::STATE_COMPLETE, - 'expected_state' => Order::STATE_COMPLETE + 'expected_state' => Order::STATE_COMPLETE, + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'processing - canCreditmemo, canShip -> processing' => [ 'can_credit_memo' => true, @@ -166,7 +199,12 @@ public function stateCheckDataProvider() 'can_ship' => true, 'call_can_skip_num' => 1, 'current_state' => Order::STATE_PROCESSING, - 'expected_state' => Order::STATE_PROCESSING + 'expected_state' => Order::STATE_PROCESSING, + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'complete - canCreditmemo, canShip -> complete' => [ 'can_credit_memo' => true, @@ -174,7 +212,12 @@ public function stateCheckDataProvider() 'can_ship' => true, 'call_can_skip_num' => 0, 'current_state' => Order::STATE_COMPLETE, - 'expected_state' => Order::STATE_COMPLETE + 'expected_state' => Order::STATE_COMPLETE, + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'new - canCreditmemo, canShip, IsInProcess -> processing' => [ 'can_credit_memo' => true, @@ -183,8 +226,11 @@ public function stateCheckDataProvider() 'call_can_skip_num' => 1, 'current_state' => Order::STATE_NEW, 'expected_state' => Order::STATE_PROCESSING, - true, - 1 + 'is_in_process' => true, + 'get_is_in_process_invoke_count' => 1, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'new - canCreditmemo, !canShip, IsInProcess -> processing' => [ 'can_credit_memo' => true, @@ -193,8 +239,11 @@ public function stateCheckDataProvider() 'call_can_skip_num' => 1, 'current_state' => Order::STATE_NEW, 'expected_state' => Order::STATE_COMPLETE, - true, - 1 + 'is_in_process' => true, + 'get_is_in_process_invoke_count' => 1, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'new - canCreditmemo, canShip, !IsInProcess -> new' => [ 'can_credit_memo' => true, @@ -203,8 +252,11 @@ public function stateCheckDataProvider() 'call_can_skip_num' => 0, 'current_state' => Order::STATE_NEW, 'expected_state' => Order::STATE_NEW, - false, - 1 + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 1, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => true ], 'hold - canUnhold -> hold' => [ 'can_credit_memo' => true, @@ -213,10 +265,11 @@ public function stateCheckDataProvider() 'call_can_skip_num' => 0, 'current_state' => Order::STATE_HOLDED, 'expected_state' => Order::STATE_HOLDED, - false, - 0, - false, - true + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => true, + 'is_not_virtual' => true ], 'payment_review - canUnhold -> payment_review' => [ 'can_credit_memo' => true, @@ -225,10 +278,11 @@ public function stateCheckDataProvider() 'call_can_skip_num' => 0, 'current_state' => Order::STATE_PAYMENT_REVIEW, 'expected_state' => Order::STATE_PAYMENT_REVIEW, - false, - 0, - false, - true + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => true, + 'is_not_virtual' => true ], 'pending_payment - canUnhold -> pending_payment' => [ 'can_credit_memo' => true, @@ -237,10 +291,11 @@ public function stateCheckDataProvider() 'call_can_skip_num' => 0, 'current_state' => Order::STATE_PENDING_PAYMENT, 'expected_state' => Order::STATE_PENDING_PAYMENT, - false, - 0, - false, - true + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => true, + 'is_not_virtual' => true ], 'cancelled - isCanceled -> cancelled' => [ 'can_credit_memo' => true, @@ -249,9 +304,24 @@ public function stateCheckDataProvider() 'call_can_skip_num' => 0, 'current_state' => Order::STATE_HOLDED, 'expected_state' => Order::STATE_HOLDED, - false, - 0, - true + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => true, + 'can_unhold' => false, + 'is_not_virtual' => true + ], + 'processing - !canCreditmemo!canShip -> complete(virtual product)' => [ + 'can_credit_memo' => false, + 'can_credit_memo_invoke_count' => 1, + 'can_ship' => false, + 'call_can_skip_num' => 2, + 'current_state' => Order::STATE_PROCESSING, + 'expected_state' => Order::STATE_COMPLETE, + 'is_in_process' => false, + 'get_is_in_process_invoke_count' => 0, + 'is_canceled' => false, + 'can_unhold' => false, + 'is_not_virtual' => false ], ]; } diff --git a/app/code/Magento/Shipping/Test/Mftf/Test/AdminCreatePartialShipmentEntityTest.xml b/app/code/Magento/Shipping/Test/Mftf/Test/AdminCreatePartialShipmentEntityTest.xml index 9d501e4b34ef7..b1fb2aad54272 100644 --- a/app/code/Magento/Shipping/Test/Mftf/Test/AdminCreatePartialShipmentEntityTest.xml +++ b/app/code/Magento/Shipping/Test/Mftf/Test/AdminCreatePartialShipmentEntityTest.xml @@ -51,8 +51,7 @@ </actionGroup> <!-- Select Free shipping --> <actionGroup ref="OrderSelectFreeShippingActionGroup" stepKey="selectFreeShippingOption"/> - <!--Click *Submit Order* button--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="clickSubmitOrder" /> <!-- Create Partial Shipment --> <actionGroup ref="AdminCreateShipmentFromOrderPage" stepKey="createNewShipment"> <argument name="Qty" value="1"/> diff --git a/app/code/Magento/Shipping/Test/Mftf/Test/AdminCreateShipmentEntityTest.xml b/app/code/Magento/Shipping/Test/Mftf/Test/AdminCreateShipmentEntityTest.xml index a900a73fc36bc..5d46ef0a76263 100644 --- a/app/code/Magento/Shipping/Test/Mftf/Test/AdminCreateShipmentEntityTest.xml +++ b/app/code/Magento/Shipping/Test/Mftf/Test/AdminCreateShipmentEntityTest.xml @@ -51,8 +51,7 @@ </actionGroup> <!-- Select Free shipping --> <actionGroup ref="OrderSelectFreeShippingActionGroup" stepKey="selectFreeShippingOption"/> - <!--Click *Submit Order* button--> - <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder"/> + <actionGroup ref="AdminOrderClickSubmitOrderActionGroup" stepKey="clickSubmitOrder" /> <!-- Create Shipment --> <actionGroup ref="AdminCreateShipmentFromOrderPage" stepKey="createNewShipment"> <argument name="Title" value="Title"/> diff --git a/app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickAddTaxRuleButtonActionGroup.xml b/app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickAddTaxRuleButtonActionGroup.xml new file mode 100644 index 0000000000000..ea5c4cb74d19e --- /dev/null +++ b/app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickAddTaxRuleButtonActionGroup.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminClickAddTaxRuleButtonActionGroup"> + <annotations> + <description>Click button for creating new tax rule.</description> + </annotations> + <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> + <waitForPageLoad stepKey="waitForTaxRuleGridLoad"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml index 07968c281c68b..5e7ce53a3a3fc 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml @@ -30,8 +30,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with defaults --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> <fillField selector="{{AdminTaxRuleFormSection.taxRateSearch}}" userInput="$$initialTaxRate.code$$" stepKey="fillTaxRateSearch"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml index c8e4defc40c9f..89cfdd0eb9943 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml @@ -59,7 +59,7 @@ <!-- Verify we see expected values on the tax rule form page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAdd"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAdd"/> <see selector="{{AdminTaxRulesSection.taxRateMultiSelectItems}}" userInput="{{SimpleTaxRate.code}}" stepKey="seeTaxRateOnNewTaxRulePage"/> </test> </tests> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml index c6a5a6c69e788..a3386cada436f 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml @@ -58,7 +58,7 @@ <!-- Verify we see expected values on the tax rule form page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAdd"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAdd"/> <see selector="{{AdminTaxRulesSection.taxRateMultiSelectItems}}" userInput="{{SimpleTaxRate.code}}" stepKey="seeTaxRateOnNewTaxRulePage"/> </test> </tests> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml index ef9b66041893d..6ceeae953139c 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml @@ -60,7 +60,7 @@ <!-- Verify we see expected values on the tax rule form page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAdd"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAdd"/> <see selector="{{AdminTaxRulesSection.taxRateMultiSelectItems}}" userInput="{{SimpleTaxRate.code}}" stepKey="seeTaxRateOnNewTaxRulePage"/> </test> </tests> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml index 23c4ffd78a88d..4f9e876fed696 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml @@ -62,7 +62,7 @@ <!-- Verify we see expected values on the tax rule form page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAdd"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAdd"/> <see selector="{{AdminTaxRulesSection.taxRateMultiSelectItems}}" userInput="{{SimpleTaxRate.code}}" stepKey="seeTaxRateOnNewTaxRulePage"/> </test> </tests> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml index ba0834da7c0e7..f1a48af741cd6 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml @@ -40,8 +40,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with customer and product class --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml index ae37bc8a8930a..de7a0fb2d9144 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml @@ -41,8 +41,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with new and existing tax rate, customer tax class, product tax class --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml index 2a008991c2dc8..4798ec60ab898 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml @@ -41,8 +41,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with new tax classes and tax rate --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml index de55453fcabc4..a08c878ba2063 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml @@ -41,8 +41,7 @@ </after> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex1"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex2"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAddNewTaxRuleButton"/> <!-- Create a tax rule with new tax classes and tax rate --> <fillField selector="{{AdminTaxRuleFormSection.code}}" userInput="{{SimpleTaxRule.code}}" stepKey="fillTaxRuleCode1"/> diff --git a/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml index 881e09e5e35f4..eb774297b8322 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml @@ -44,8 +44,7 @@ <!-- Confirm Deleted TaxIdentifier on the tax rule grid page --> <actionGroup ref="AdminTaxRuleGridOpenPageActionGroup" stepKey="goToTaxRuleIndex3"/> - <click selector="{{AdminTaxRuleGridSection.add}}" stepKey="clickAddNewTaxRuleButton"/> - <waitForPageLoad stepKey="waitForTaxRuleIndex1"/> + <actionGroup ref="AdminClickAddTaxRuleButtonActionGroup" stepKey="clickAddNewTaxRuleButton"/> <fillField selector="{{AdminTaxRuleFormSection.taxRateSearch}}" userInput="$$initialTaxRate.code$$" stepKey="fillTaxRateSearch"/> <wait stepKey="waitForSearch" time="5" /> <dontSee selector="{{AdminTaxRuleFormSection.fieldTaxRate}}" userInput="$$initialTaxRate.code$$" stepKey="dontSeeInTaxRuleForm"/> diff --git a/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Store.php b/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Store.php index ca4a238fd1ff4..18ce1be2e68d1 100644 --- a/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Store.php +++ b/app/code/Magento/Theme/Model/Indexer/Design/Config/Plugin/Store.php @@ -6,7 +6,7 @@ namespace Magento\Theme\Model\Indexer\Design\Config\Plugin; use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Store\Model\Store as StoreStore; +use Magento\Store\Model\Store as StoreModel; use Magento\Theme\Model\Data\Design\Config; class Store @@ -19,42 +19,41 @@ class Store /** * @param IndexerRegistry $indexerRegistry */ - public function __construct( - IndexerRegistry $indexerRegistry - ) { + public function __construct(IndexerRegistry $indexerRegistry) + { $this->indexerRegistry = $indexerRegistry; } /** * Invalidate design config grid indexer on store creation * - * @param StoreStore $subject - * @param \Closure $proceed - * @return StoreStore + * @param StoreModel $subject + * @param StoreModel $result + * @return StoreModel * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function aroundSave(StoreStore $subject, \Closure $proceed) + public function afterSave(StoreModel $subject, StoreModel $result) { - $isObjectNew = $subject->getId() == 0; - $result = $proceed(); - if ($isObjectNew) { + if ($result->isObjectNew()) { $this->indexerRegistry->get(Config::DESIGN_CONFIG_GRID_INDEXER_ID)->invalidate(); } + return $result; } /** * Invalidate design config grid indexer on store removal * - * @param StoreStore $subject - * @param StoreStore $result - * @return StoreStore + * @param StoreModel $subject + * @param StoreModel $result + * @return StoreModel * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterDelete(StoreStore $subject, $result) + public function afterDelete(StoreModel $subject, $result) { $this->indexerRegistry->get(Config::DESIGN_CONFIG_GRID_INDEXER_ID)->invalidate(); + return $result; } } diff --git a/app/code/Magento/Theme/Test/Unit/Model/Indexer/Design/Config/Plugin/StoreTest.php b/app/code/Magento/Theme/Test/Unit/Model/Indexer/Design/Config/Plugin/StoreTest.php index b61246cc7583f..1d48c0fe04e7a 100644 --- a/app/code/Magento/Theme/Test/Unit/Model/Indexer/Design/Config/Plugin/StoreTest.php +++ b/app/code/Magento/Theme/Test/Unit/Model/Indexer/Design/Config/Plugin/StoreTest.php @@ -9,6 +9,7 @@ use Magento\Framework\Indexer\IndexerInterface; use Magento\Framework\Indexer\IndexerRegistry; +use Magento\Store\Model\Store as StoreModel; use Magento\Theme\Model\Data\Design\Config; use Magento\Theme\Model\Indexer\Design\Config\Plugin\Store; use PHPUnit\Framework\MockObject\MockObject; @@ -17,10 +18,10 @@ class StoreTest extends TestCase { /** @var Store */ - protected $model; + private $model; /** @var IndexerRegistry|MockObject */ - protected $indexerRegistryMock; + private $indexerRegistryMock; protected function setUp(): void { @@ -31,21 +32,15 @@ protected function setUp(): void $this->model = new Store($this->indexerRegistryMock); } - public function testAroundSave() + public function testAfterSave(): void { - $subjectId = 0; - - /** @var \Magento\Store\Model\Store|MockObject $subjectMock */ - $subjectMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) + /** @var StoreModel|MockObject $subjectMock */ + $subjectMock = $this->getMockBuilder(StoreModel::class) ->disableOriginalConstructor() ->getMock(); $subjectMock->expects($this->once()) - ->method('getId') - ->willReturn($subjectId); - - $closureMock = function () use ($subjectMock) { - return $subjectMock; - }; + ->method('isObjectNew') + ->willReturn(true); /** @var IndexerInterface|MockObject $indexerMock */ $indexerMock = $this->getMockBuilder(IndexerInterface::class) @@ -58,35 +53,29 @@ public function testAroundSave() ->with(Config::DESIGN_CONFIG_GRID_INDEXER_ID) ->willReturn($indexerMock); - $this->assertEquals($subjectMock, $this->model->aroundSave($subjectMock, $closureMock)); + $this->assertSame($subjectMock, $this->model->afterSave($subjectMock, $subjectMock)); } - public function testAroundSaveWithExistentSubject() + public function testAfterSaveWithExistentSubject(): void { - $subjectId = 1; - - /** @var \Magento\Store\Model\Store|MockObject $subjectMock */ - $subjectMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) + /** @var StoreModel|MockObject $subjectMock */ + $subjectMock = $this->getMockBuilder(StoreModel::class) ->disableOriginalConstructor() ->getMock(); $subjectMock->expects($this->once()) - ->method('getId') - ->willReturn($subjectId); - - $closureMock = function () use ($subjectMock) { - return $subjectMock; - }; + ->method('isObjectNew') + ->willReturn(false); $this->indexerRegistryMock->expects($this->never()) ->method('get'); - $this->assertEquals($subjectMock, $this->model->aroundSave($subjectMock, $closureMock)); + $this->assertSame($subjectMock, $this->model->afterSave($subjectMock, $subjectMock)); } - public function testAfterDelete() + public function testAfterDelete(): void { - /** @var \Magento\Store\Model\Store|MockObject $subjectMock */ - $subjectMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) + /** @var StoreModel|MockObject $subjectMock */ + $subjectMock = $this->getMockBuilder(StoreModel::class) ->disableOriginalConstructor() ->getMock(); @@ -101,6 +90,6 @@ public function testAfterDelete() ->with(Config::DESIGN_CONFIG_GRID_INDEXER_ID) ->willReturn($indexerMock); - $this->assertEquals($subjectMock, $this->model->afterDelete($subjectMock, $subjectMock)); + $this->assertSame($subjectMock, $this->model->afterDelete($subjectMock, $subjectMock)); } } diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php index c2e55029cab13..5527a39ce0507 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php @@ -22,15 +22,17 @@ use Magento\Store\Model\StoreManager; use Magento\Store\Model\StoreManagerInterface; use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\Helper\Xpath; use Magento\TestFramework\Mail\Template\TransportBuilderMock; use Magento\TestFramework\Request; +use Magento\TestFramework\TestCase\AbstractController; use Magento\Theme\Controller\Result\MessagePlugin; use PHPUnit\Framework\Constraint\StringContains; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class AccountTest extends \Magento\TestFramework\TestCase\AbstractController +class AccountTest extends AbstractController { /** * @var TransportBuilderMock @@ -54,9 +56,8 @@ protected function setUp(): void */ protected function login($customerId) { - /** @var \Magento\Customer\Model\Session $session */ - $session = Bootstrap::getObjectManager() - ->get(\Magento\Customer\Model\Session::class); + /** @var Session $session */ + $session = Bootstrap::getObjectManager()->get(Session::class); $session->loginById($customerId); } @@ -148,8 +149,8 @@ public function testCreatepasswordActionWithSession() $customer->setData('confirmation', 'confirmation'); $customer->save(); - /** @var \Magento\Customer\Model\Session $customer */ - $session = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Session::class); + /** @var Session $customer */ + $session = Bootstrap::getObjectManager()->get(Session::class); $session->setRpToken($token); $session->setRpCustomerId($customer->getId()); @@ -404,18 +405,16 @@ public function testEditAction() $this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body); $this->assertStringContainsString('<div class="field field-name-firstname required">', $body); // Verify the password check box is not checked - $expectedString = <<<EXPECTED_HTML -<input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" - title="Change Password" - class="checkbox" /> -EXPECTED_HTML; - $this->assertStringContainsString($expectedString, $body); + $checkboxXpath = '//input[@type="checkbox"][@name="change_password"][@id="change-password"][not (@checked)]' . + '[@data-role="change-password"][@value="1"][@title="Change Password"][@class="checkbox"]'; + + $this->assertEquals(1, Xpath::getElementsCountForXpath($checkboxXpath, $body)); } /** * @magentoDataFixture Magento/Customer/_files/customer.php */ - public function testChangePasswordEditAction() + public function testChangePasswordEditAction(): void { $this->login(1); @@ -425,12 +424,11 @@ public function testChangePasswordEditAction() $this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body); $this->assertStringContainsString('<div class="field field-name-firstname required">', $body); // Verify the password check box is checked - $expectedString = <<<EXPECTED_HTML -<input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" - title="Change Password" - checked="checked" class="checkbox" /> -EXPECTED_HTML; - $this->assertStringContainsString($expectedString, $body); + $checkboxXpath = '//input[@type="checkbox"][@name="change_password"][@id="change-password"]' . + '[@data-role="change-password"][@value="1"][@title="Change Password"][@checked="checked"]' . + '[@class="checkbox"]'; + + $this->assertEquals(1, Xpath::getElementsCountForXpath($checkboxXpath, $body)); } /** diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php new file mode 100644 index 0000000000000..4afeda3a035eb --- /dev/null +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\TestFramework\Utility; + +/** + * Helper class to add list of added new files. + */ +class AddedFiles +{ + /** + * Provide list of new files. + * + * @param string $changedFilesBaseDir + * + * @return string[] + */ + public static function getAddedFilesList(string $changedFilesBaseDir): array + { + return FilesSearch::getFilesFromListFile( + $changedFilesBaseDir, + 'changed_files*.added.*', + function () { + // if no list files, probably, this is the dev environment + // phpcs:ignore Generic.PHP.NoSilencedErrors,Magento2.Security.InsecureFunction + @exec('git diff --cached --name-only --diff-filter=A', $addedFiles); + return $addedFiles; + } + ); + } +} diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php new file mode 100644 index 0000000000000..53db8ca8d0b08 --- /dev/null +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php @@ -0,0 +1,56 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\TestFramework\Utility; + +/** + * Search for children classes in list of files. + */ +class ChildrenClassesSearch +{ + /** + * @var ClassNameExtractor + */ + private $classNameExtractor; + + /** + * ChildrenClassesSearch constructor. + */ + public function __construct() + { + $this->classNameExtractor = new ClassNameExtractor(); + } + + /** + * Get list of classes name which are subclasses of mentioned class. + * + * @param array $fileList + * @param string $parent + * @param bool $asDataSet + * + * @return array + * @throws \ReflectionException + */ + public function getClassesWhichAreChildrenOf(array $fileList, string $parent, bool $asDataSet = true): array + { + $found = []; + + foreach ($fileList as $file) { + $name = $asDataSet ? $file[0] : $file; + $class = $this->classNameExtractor->getNameWithNamespace(file_get_contents($name)); + + if ($class) { + $classReflection = new \ReflectionClass($class); + if ($classReflection->isSubclassOf($parent)) { + $found[] = $class; + } + } + } + + return $found; + } +} diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php b/dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php new file mode 100644 index 0000000000000..0ec8124496d1d --- /dev/null +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\TestFramework\Utility; + +/** + * Helper class to search files by provided directory and file pattern. + */ +class FilesSearch +{ + /** + * Read files from generated lists. + * + * @param string $listsBaseDir + * @param string $listFilePattern + * @param callable $noListCallback + * @return string[] + */ + public static function getFilesFromListFile( + string $listsBaseDir, + string $listFilePattern, + callable $noListCallback + ): array { + $filesDefinedInList = []; + $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); + if (!empty($listFiles)) { + foreach ($listFiles as $listFile) { + $filesDefinedInList[] = file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + } + $filesDefinedInList = array_merge([], ...$filesDefinedInList); + } else { + $filesDefinedInList = call_user_func($noListCallback); + } + array_walk( + $filesDefinedInList, + function (&$file) { + $file = BP . '/' . $file; + } + ); + $filesDefinedInList = array_values(array_unique($filesDefinedInList)); + + return $filesDefinedInList; + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/A.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/A.php new file mode 100644 index 0000000000000..3369df1edd54f --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/A.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class A +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/B.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/B.php new file mode 100644 index 0000000000000..8873af3e4f9b7 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/B.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class B extends A +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php new file mode 100644 index 0000000000000..e50735fcbb46c --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class C implements ZInterface +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/D.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/D.php new file mode 100644 index 0000000000000..8dc2cc0b9269e --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/D.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class D +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/E.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/E.php new file mode 100644 index 0000000000000..563135ff36d3c --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/E.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class E extends B +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php new file mode 100644 index 0000000000000..6976ed26a0d84 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +class F extends E implements ZInterface +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/ZInterface.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/ZInterface.php new file mode 100644 index 0000000000000..be1b6d222519c --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/ZInterface.php @@ -0,0 +1,10 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\TestFramework\Utility\ChildrenClassesSearch; + +interface ZInterface +{ +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php new file mode 100644 index 0000000000000..5b7fd47042347 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\TestFramework\Utility; + +use Magento\TestFramework\Utility\ChildrenClassesSearch\A; +use Magento\TestFramework\Utility\ChildrenClassesSearch\B; +use Magento\TestFramework\Utility\ChildrenClassesSearch\E; +use Magento\TestFramework\Utility\ChildrenClassesSearch\F; +use PHPUnit\Framework\TestCase; + +class ChildrenClassesSearchTest extends TestCase +{ + /** + * @var ChildrenClassesSearch + */ + private $childrenClassesSearch; + + protected function setUp(): void + { + $this->childrenClassesSearch = new ChildrenClassesSearch(); + } + + public function testChildrenSearch(): void + { + $files = [ + __DIR__ . '/ChildrenClassesSearch/A.php', + __DIR__ . '/ChildrenClassesSearch/B.php', + __DIR__ . '/ChildrenClassesSearch/C.php', + __DIR__ . '/ChildrenClassesSearch/D.php', + __DIR__ . '/ChildrenClassesSearch/E.php', + __DIR__ . '/ChildrenClassesSearch/F.php', + __DIR__ . '/ChildrenClassesSearch/ZInterface.php', + ]; + + $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf( + $files, + A::class, + false + ); + + $expected = [ + B::class, + E::class, + F::class + ]; + + $this->assertSame($expected, $found); + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php new file mode 100644 index 0000000000000..7b27dde3b0bf4 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php @@ -0,0 +1,53 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\TestFramework\Utility; + +use PHPUnit\Framework\TestCase; + +class FilesSearchTest extends TestCase +{ + /** + * Test files list extraction from file. + */ + public function testGetFiles(): void + { + $pattern = 'changed_files*.txt'; + + $files = FilesSearch::getFilesFromListFile(__DIR__, $pattern, function () { + return []; + }); + + $expected = [ + BP . '/app/code/Magento/Cms/Block/Block.php', + BP . '/app/code/Magento/Cms/Api/BlockRepositoryInterface.php', + BP . '/app/code/Magento/Cms/Observer/NoCookiesObserver.php' + ]; + + $this->assertSame($files, $expected); + } + + /** + * Test callblack function in case when files with lists did not found. + */ + public function testGetEmptyList(): void + { + $pattern = 'zzz.txt'; + + $files = FilesSearch::getFilesFromListFile(__DIR__, $pattern, function () { + return ['1', '2', '3']; + }); + + $expected = [ + BP . '/1', + BP . '/2', + BP . '/3' + ]; + + $this->assertSame($files, $expected); + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt new file mode 100644 index 0000000000000..816f4b32c9361 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt @@ -0,0 +1,3 @@ +app/code/Magento/Cms/Block/Block.php +app/code/Magento/Cms/Api/BlockRepositoryInterface.php +app/code/Magento/Cms/Observer/NoCookiesObserver.php diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php new file mode 100644 index 0000000000000..69050c3c51895 --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php @@ -0,0 +1,85 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Test\Legacy\Magento\Framework\App\Action; + +use Magento\Framework\App\Action\AbstractAction; +use Magento\Framework\App\ActionInterface; +use Magento\Framework\App\Utility\Files; +use Magento\Framework\Exception\LocalizedException; +use Magento\TestFramework\Utility\AddedFiles; +use Magento\TestFramework\Utility\ChildrenClassesSearch; +use PHPUnit\Framework\TestCase; + +/** + * Test newly created controllers must do not extend AbstractAction. + */ +class AbstractActionTest extends TestCase +{ + /** + * @var ChildrenClassesSearch + */ + private $childrenClassesSearch; + + /** + * @var Files + */ + private $fileUtilities; + + /** + * @throws LocalizedException + */ + protected function setUp(): void + { + $this->childrenClassesSearch = new ChildrenClassesSearch(); + $this->fileUtilities = Files::init(); + } + + /** + * Test newly created controllers do not extend deprecated AbstractAction. + * + * @throws \ReflectionException + */ + public function testNewControllersDoNotExtendAbstractAction(): void + { + $files = $this->getTestFiles(); + + $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf($files, AbstractAction::class); + + $this->assertEmpty( + $found, + "The following new controller(s) extend " . AbstractAction::class . "\r\n" + . "All new controller classes must implement " . ActionInterface::class . " instead.\r\n" + . print_r($found, true) + ); + } + + /** + * Provide files for test. + * + * @return array + */ + private function getTestFiles(): array + { + $phpFiles = AddedFiles::getAddedFilesList($this->getChangedFilesBaseDir()); + + $phpFiles = Files::composeDataSets($phpFiles); + $fileTypes = Files::INCLUDE_APP_CODE | Files::INCLUDE_LIBS | Files::AS_DATA_SET; + return array_intersect_key($phpFiles, $this->fileUtilities->getPhpFiles($fileTypes)); + } + + /** + * Returns base directory for generated lists. + * + * @return string + */ + private function getChangedFilesBaseDir(): string + { + return BP . DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'static' . + DIRECTORY_SEPARATOR . 'testsuite' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR . 'Test'; + } +} diff --git a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php index 324753b4bd4ec..ad91025448579 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php @@ -14,6 +14,8 @@ use Magento\TestFramework\CodingStandard\Tool\CopyPasteDetector; use Magento\TestFramework\CodingStandard\Tool\PhpCompatibility; use Magento\TestFramework\CodingStandard\Tool\PhpStan; +use Magento\TestFramework\Utility\AddedFiles; +use Magento\TestFramework\Utility\FilesSearch; use PHPMD\TextUI\Command; /** @@ -113,8 +115,8 @@ public static function getWhitelist( */ private static function getChangedFilesList($changedFilesBaseDir) { - return self::getFilesFromListFile( - $changedFilesBaseDir, + return FilesSearch::getFilesFromListFile( + $changedFilesBaseDir ?: self::getChangedFilesBaseDir(), 'changed_files*', function () { // if no list files, probably, this is the dev environment @@ -128,65 +130,6 @@ function () { ); } - /** - * This method loads list of added files. - * - * @param string $changedFilesBaseDir - * @return string[] - */ - private static function getAddedFilesList($changedFilesBaseDir) - { - return self::getFilesFromListFile( - $changedFilesBaseDir, - 'changed_files*.added.*', - function () { - // if no list files, probably, this is the dev environment - // phpcs:ignore Generic.PHP.NoSilencedErrors,Magento2.Security.InsecureFunction - @exec('git diff --cached --name-only --diff-filter=A', $addedFiles); - return $addedFiles; - } - ); - } - - /** - * Read files from generated lists. - * - * @param string $listsBaseDir - * @param string $listFilePattern - * @param callable $noListCallback - * @return string[] - */ - private static function getFilesFromListFile($listsBaseDir, $listFilePattern, $noListCallback) - { - $filesDefinedInList = []; - - $globFilesListPattern = ($listsBaseDir ?: self::getChangedFilesBaseDir()) - . '/_files/' . $listFilePattern; - $listFiles = glob($globFilesListPattern); - if (!empty($listFiles)) { - foreach ($listFiles as $listFile) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge - $filesDefinedInList = array_merge( - $filesDefinedInList, - file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) - ); - } - } else { - $filesDefinedInList = call_user_func($noListCallback); - } - - array_walk( - $filesDefinedInList, - function (&$file) { - $file = BP . '/' . $file; - } - ); - - $filesDefinedInList = array_values(array_unique($filesDefinedInList)); - - return $filesDefinedInList; - } - /** * Filter list of files. * @@ -427,7 +370,7 @@ public function testCopyPaste() */ public function testStrictTypes() { - $changedFiles = self::getAddedFilesList(''); + $changedFiles = AddedFiles::getAddedFilesList(self::getChangedFilesBaseDir()); try { $blackList = Files::init()->readLists( diff --git a/lib/internal/Magento/Framework/App/ResourceConnection.php b/lib/internal/Magento/Framework/App/ResourceConnection.php index 00dc88dcd7b17..3ba50fb396a4c 100644 --- a/lib/internal/Magento/Framework/App/ResourceConnection.php +++ b/lib/internal/Magento/Framework/App/ResourceConnection.php @@ -178,7 +178,7 @@ public function getTableName($modelEntity, $connectionName = self::DEFAULT_CONNE list($modelEntity, $tableSuffix) = $modelEntity; } - $tableName = $modelEntity; + $tableName = (string)$modelEntity; $mappedTableName = $this->getMappedTableName($tableName); if ($mappedTableName) { diff --git a/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php b/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php index 1b12d68e683a3..67d5e303c6896 100644 --- a/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php @@ -84,7 +84,7 @@ public function testGetTablePrefixWithInjectedPrefix() public function testGetTablePrefix() { - $this->deploymentConfigMock->expects(self::once()) + $this->deploymentConfigMock->expects($this->once()) ->method('get') ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_PREFIX) ->willReturn('pref_'); @@ -93,10 +93,10 @@ public function testGetTablePrefix() public function testGetConnectionByName() { - $this->deploymentConfigMock->expects(self::once())->method('get') + $this->deploymentConfigMock->expects($this->once())->method('get') ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS . '/default') ->willReturn(['config']); - $this->connectionFactoryMock->expects(self::once())->method('create') + $this->connectionFactoryMock->expects($this->once())->method('create') ->with(['config']) ->willReturn('connection'); @@ -112,15 +112,38 @@ public function testGetExistingConnectionByName() 'connections' => ['default_process_' . getmypid() => 'existing_connection'] ] ); - $this->deploymentConfigMock->expects(self::never())->method('get'); + $this->deploymentConfigMock->expects($this->never())->method('get'); self::assertEquals('existing_connection', $unit->getConnectionByName('default')); } public function testCloseConnection() { - $this->configMock->expects(self::once())->method('getConnectionName')->with('default'); + $this->configMock->expects($this->once())->method('getConnectionName')->with('default'); $this->unit->closeConnection('default'); } + + public function testGetTableNameWithBoolParam() + { + $this->deploymentConfigMock->expects($this->at(0)) + ->method('get') + ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_PREFIX) + ->willReturn('pref_'); + $this->deploymentConfigMock->expects($this->at(1))->method('get') + ->with('db/connection/default') + ->willReturn(['config']); + $this->configMock->expects($this->atLeastOnce()) + ->method('getConnectionName') + ->with('default') + ->willReturn('default'); + + $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)->getMock(); + $connection->expects($this->once())->method('getTableName')->with('pref_1'); + $this->connectionFactoryMock->expects($this->once())->method('create') + ->with(['config']) + ->willReturn($connection); + + $this->unit->getTableName(true); + } } diff --git a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php index 0a8db80cae349..cdbce9d102a89 100644 --- a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php +++ b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Framework\View\Template\Html; @@ -140,7 +141,7 @@ function ($match) use (&$heredocs) { . '(?:<(?>textarea|pre|script)\b|\z))#', ' ', preg_replace( - '#(?<!:|\\\\|\'|")//(?!\s*\<\!\[)(?!\s*]]\>)[^\n\r]*#', + '#(?<!:|\\\\|\'|"|/)//(?!/)(?!\s*\<\!\[)(?!\s*]]\>)[^\n\r]*#', '', preg_replace( '#(?<!:|\'|")//[^\n\r]*(\?\>)#', diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php index 6aafa5a46cf63..3b13a2f723617 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\View\Test\Unit\Template\Html; use PHPUnit\Framework\TestCase; @@ -139,6 +141,7 @@ public function testMinify() <img src="test.png" alt="some text" /> <?php echo \$block->someMethod(); ?> <div style="width: 800px" class="<?php echo \$block->getClass() ?>" /> + <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-component="main-image"> <script> var i = 1;// comment var j = 1;// <?php echo 'hi' ?> @@ -179,7 +182,7 @@ public function testMinify() TEXT; $expectedContent = <<<TEXT -<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ ?> <?php ?> <html><head><title>Test titleText Link some textsomeMethod(); ?>