From b06db1f34b6799255a1cc7f596e21190ebaec7f2 Mon Sep 17 00:00:00 2001 From: Jiten Patel Date: Fri, 20 Mar 2020 11:07:11 +0530 Subject: [PATCH 01/13] Fixed issue 27051: Saving an attribute with backend_type static --- .../Catalog/Controller/Adminhtml/Product/Attribute/Save.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index 853cc65270306..0fcad1177dd85 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -258,6 +258,10 @@ public function execute() unset($data['apply_to']); } + if ($model->getBackendType() == 'static' && !$model->getIsUserDefined()) { + $data['frontend_class'] = $model->getFrontendClass(); + } + $model->addData($data); if (!$attributeId) { From c1a01fc4c797e037c760285b9434df52c4a38373 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Mon, 27 Apr 2020 23:21:06 +0300 Subject: [PATCH 02/13] coverage --- .../Adminhtml/Product/Attribute/SaveTest.php | 213 +++++++++++++----- 1 file changed, 153 insertions(+), 60 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php index 30d3503e4640e..7613131a9e8fe 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php @@ -3,116 +3,142 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Attribute; +use Magento\Backend\Model\Session; +use Magento\Backend\Model\View\Result\Redirect as ResultRedirect; use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Save; -use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator; -use Magento\Framework\Serialize\Serializer\FormData; -use Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\AttributeTest; -use Magento\Catalog\Model\Product\AttributeSet\BuildFactory; +use Magento\Catalog\Helper\Product as ProductHelper; +use Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation; use Magento\Catalog\Model\Product\AttributeSet\Build; +use Magento\Catalog\Model\Product\AttributeSet\BuildFactory; use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory; +use Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\AttributeTest; use Magento\Eav\Api\Data\AttributeSetInterface; +use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator as InputTypeValidator; use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory; use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory; +use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\Filter\FilterManager; -use Magento\Catalog\Helper\Product as ProductHelper; +use Magento\Framework\Serialize\Serializer\FormData; use Magento\Framework\View\Element\Messages; use Magento\Framework\View\LayoutFactory; -use Magento\Backend\Model\View\Result\Redirect as ResultRedirect; -use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator as InputTypeValidator; use Magento\Framework\View\LayoutInterface; +use PHPUnit\Framework\MockObject\MockObject; /** + * Test product attribute controller + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class SaveTest extends AttributeTest { /** - * @var BuildFactory|\PHPUnit_Framework_MockObject_MockObject + * @var BuildFactory|MockObject */ protected $buildFactoryMock; /** - * @var FilterManager|\PHPUnit_Framework_MockObject_MockObject + * @var FilterManager|MockObject */ protected $filterManagerMock; /** - * @var ProductHelper|\PHPUnit_Framework_MockObject_MockObject + * @var ProductHelper|MockObject */ protected $productHelperMock; /** - * @var AttributeFactory|\PHPUnit_Framework_MockObject_MockObject + * @var AttributeFactory|MockObject */ protected $attributeFactoryMock; /** - * @var ValidatorFactory|\PHPUnit_Framework_MockObject_MockObject + * @var ValidatorFactory|MockObject */ protected $validatorFactoryMock; /** - * @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject + * @var CollectionFactory|MockObject */ protected $groupCollectionFactoryMock; /** - * @var LayoutFactory|\PHPUnit_Framework_MockObject_MockObject + * @var LayoutFactory|MockObject */ protected $layoutFactoryMock; /** - * @var ResultRedirect|\PHPUnit_Framework_MockObject_MockObject + * @var ResultRedirect|MockObject */ protected $redirectMock; /** - * @var AttributeSet|\PHPUnit_Framework_MockObject_MockObject + * @var AttributeSet|MockObject */ protected $attributeSetMock; /** - * @var Build|\PHPUnit_Framework_MockObject_MockObject + * @var Build|MockObject */ protected $builderMock; /** - * @var InputTypeValidator|\PHPUnit_Framework_MockObject_MockObject + * @var InputTypeValidator|MockObject */ protected $inputTypeValidatorMock; /** - * @var FormData|\PHPUnit_Framework_MockObject_MockObject + * @var FormData|MockObject + */ + protected $formDataSerializerMock; + + /** + * @var ProductAttributeInterface|MockObject + */ + protected $productAttributeMock; + + /** + * @var Presentation|MockObject */ - private $formDataSerializerMock; + protected $presentationMock; /** - * @var ProductAttributeInterface|\PHPUnit_Framework_MockObject_MockObject + * @var Session|MockObject */ - private $productAttributeMock; + protected $sessionMock; /** - * @var AttributeCodeValidator|\PHPUnit_Framework_MockObject_MockObject + * @var AttributeCodeValidator|MockObject */ - private $attributeCodeValidatorMock; + protected $attributeCodeValidatorMock; - protected function setUp() + /** + * @inheritDoc + */ + public function setUp(): void { parent::setUp(); + $this->filterManagerMock = $this->createMock(FilterManager::class); + $this->productHelperMock = $this->createMock(ProductHelper::class); + $this->attributeSetMock = $this->createMock(AttributeSetInterface::class); + $this->builderMock = $this->createMock(Build::class); + $this->inputTypeValidatorMock = $this->createMock(InputTypeValidator::class); + $this->formDataSerializerMock = $this->createMock(FormData::class); + $this->attributeCodeValidatorMock = $this->createMock(AttributeCodeValidator::class); + $this->presentationMock = $this->createMock(Presentation::class); + $this->sessionMock = $this->createMock(Session::class); + $this->layoutFactoryMock = $this->createMock(LayoutFactory::class); $this->buildFactoryMock = $this->getMockBuilder(BuildFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $this->filterManagerMock = $this->getMockBuilder(FilterManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->productHelperMock = $this->getMockBuilder(ProductHelper::class) - ->disableOriginalConstructor() - ->getMock(); $this->attributeFactoryMock = $this->getMockBuilder(AttributeFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() @@ -125,32 +151,23 @@ protected function setUp() ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $this->layoutFactoryMock = $this->getMockBuilder(LayoutFactory::class) - ->disableOriginalConstructor() - ->getMock(); $this->redirectMock = $this->getMockBuilder(ResultRedirect::class) ->setMethods(['setData', 'setPath']) ->disableOriginalConstructor() ->getMock(); - $this->attributeSetMock = $this->getMockBuilder(AttributeSetInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->builderMock = $this->getMockBuilder(Build::class) - ->disableOriginalConstructor() - ->getMock(); - $this->inputTypeValidatorMock = $this->getMockBuilder(InputTypeValidator::class) - ->disableOriginalConstructor() - ->getMock(); - $this->formDataSerializerMock = $this->getMockBuilder(FormData::class) - ->disableOriginalConstructor() - ->getMock(); - $this->attributeCodeValidatorMock = $this->getMockBuilder(AttributeCodeValidator::class) - ->disableOriginalConstructor() - ->getMock(); $this->productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class) - ->setMethods(['getId', 'get']) - ->getMockForAbstractClass(); - + ->setMethods( + [ + 'getId', + 'get', + 'getBackendTypeByInput', + 'getDefaultValueByInput', + 'getBackendType', + 'getFrontendClass', + 'addData', + 'save' + ] + )->getMockForAbstractClass(); $this->buildFactoryMock->expects($this->any()) ->method('create') ->willReturn($this->builderMock); @@ -163,7 +180,7 @@ protected function setUp() } /** - * {@inheritdoc} + * @inheritdoc */ protected function getModel() { @@ -180,11 +197,17 @@ protected function getModel() 'groupCollectionFactory' => $this->groupCollectionFactoryMock, 'layoutFactory' => $this->layoutFactoryMock, 'formDataSerializer' => $this->formDataSerializerMock, - 'attributeCodeValidator' => $this->attributeCodeValidatorMock + 'attributeCodeValidator' => $this->attributeCodeValidatorMock, + 'presentation' => $this->presentationMock, + '_session' => $this->sessionMock ]); } - public function testExecuteWithEmptyData() + /** + * @return void + * @throws NotFoundException + */ + public function testExecuteWithEmptyData(): void { $this->requestMock->expects($this->any()) ->method('getParam') @@ -210,7 +233,76 @@ public function testExecuteWithEmptyData() $this->assertInstanceOf(ResultRedirect::class, $this->getModel()->execute()); } - public function testExecute() + /** + * @return void + * @throws NotFoundException + */ + public function testExecuteSaveFrontendClass(): void + { + $data = [ + 'frontend_input' => 'test_frontend_input', + ]; + + $this->requestMock->expects($this->any()) + ->method('getParam') + ->willReturnMap([ + ['isAjax', null, null], + ['serialized_options', '[]', ''], + ['set', null, 1], + ['attribute_code', null, 'test_attribute_code'], + ]); + $this->formDataSerializerMock + ->expects($this->once()) + ->method('unserialize') + ->with('') + ->willReturn([]); + $this->requestMock->expects($this->once()) + ->method('getPostValue') + ->willReturn($data); + $this->inputTypeValidatorMock->expects($this->any()) + ->method('isValid') + ->with($data['frontend_input']) + ->willReturn(true); + $this->presentationMock->expects($this->once()) + ->method('convertPresentationDataToInputType') + ->willReturn($data); + $this->productHelperMock->expects($this->once()) + ->method('getAttributeSourceModelByInputType') + ->with($data['frontend_input']) + ->willReturn(null); + $this->productHelperMock->expects($this->once()) + ->method('getAttributeBackendModelByInputType') + ->with($data['frontend_input']) + ->willReturn(null); + $this->productAttributeMock->expects($this->once()) + ->method('getBackendTypeByInput') + ->with($data['frontend_input']) + ->willReturnSelf('test_backend_type'); + $this->productAttributeMock->expects($this->once()) + ->method('getDefaultValueByInput') + ->with($data['frontend_input']) + ->willReturn(null); + $this->productAttributeMock->expects($this->once()) + ->method('getBackendType') + ->willReturn('static'); + $this->productAttributeMock->expects($this->once()) + ->method('getFrontendClass') + ->willReturn('static'); + $this->resultFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->redirectMock); + $this->redirectMock->expects($this->any()) + ->method('setPath') + ->willReturnSelf(); + + $this->assertInstanceOf(ResultRedirect::class, $this->getModel()->execute()); + } + + /** + * @return void + * @throws NotFoundException + */ + public function testExecute(): void { $data = [ 'new_attribute_set_name' => 'Test attribute set name', @@ -273,9 +365,10 @@ public function testExecute() } /** - * @throws \Magento\Framework\Exception\NotFoundException + * @return void + * @throws NotFoundException */ - public function testExecuteWithOptionsDataError() + public function testExecuteWithOptionsDataError(): void { $serializedOptions = '{"key":"value"}'; $message = "The attribute couldn't be saved due to an error. Verify your information and try again. " @@ -305,10 +398,10 @@ public function testExecuteWithOptionsDataError() * @param string $path * @param array $params * @param array $response - * @return mixed + * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - private function addReturnResultConditions(string $path = '', array $params = [], array $response = []) + private function addReturnResultConditions(string $path = '', array $params = [], array $response = []): void { $layoutMock = $this->getMockBuilder(LayoutInterface::class) ->setMethods(['initMessages', 'getMessagesBlock']) From eb343417c7fbe5b0692646686457e150d7d52fae Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Mon, 18 May 2020 12:45:16 +0300 Subject: [PATCH 03/13] resolved conflict --- .../Adminhtml/Product/Attribute/SaveTest.php | 84 ++++++++----------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php index afd9b8ae8d0f2..681cef8489796 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php @@ -7,110 +7,116 @@ namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Attribute; +use Magento\Backend\Model\Session; +use Magento\Backend\Model\View\Result\Redirect as ResultRedirect; use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Save; -use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator; -use Magento\Framework\Serialize\Serializer\FormData; -use Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\AttributeTest; -use Magento\Catalog\Model\Product\AttributeSet\BuildFactory; +use Magento\Catalog\Helper\Product as ProductHelper; +use Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation; use Magento\Catalog\Model\Product\AttributeSet\Build; +use Magento\Catalog\Model\Product\AttributeSet\BuildFactory; use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory; +use Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\AttributeTest; use Magento\Eav\Api\Data\AttributeSetInterface; +use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator as InputTypeValidator; use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory; use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory; +use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\Filter\FilterManager; -use Magento\Catalog\Helper\Product as ProductHelper; +use Magento\Framework\Serialize\Serializer\FormData; use Magento\Framework\View\Element\Messages; use Magento\Framework\View\LayoutFactory; -use Magento\Backend\Model\View\Result\Redirect as ResultRedirect; -use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator as InputTypeValidator; use Magento\Framework\View\LayoutInterface; +use PHPUnit\Framework\MockObject\MockObject; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class SaveTest extends AttributeTest { /** * @var BuildFactory|MockObject */ - protected $buildFactoryMock; + private $buildFactoryMock; /** * @var FilterManager|MockObject */ - protected $filterManagerMock; + private $filterManagerMock; /** * @var ProductHelper|MockObject */ - protected $productHelperMock; + private $productHelperMock; /** * @var AttributeFactory|MockObject */ - protected $attributeFactoryMock; + private $attributeFactoryMock; /** * @var ValidatorFactory|MockObject */ - protected $validatorFactoryMock; + private $validatorFactoryMock; /** * @var CollectionFactory|MockObject */ - protected $groupCollectionFactoryMock; + private $groupCollectionFactoryMock; /** * @var LayoutFactory|MockObject */ - protected $layoutFactoryMock; + private $layoutFactoryMock; /** * @var ResultRedirect|MockObject */ - protected $redirectMock; + private $redirectMock; /** - * @var AttributeSet|MockObject + * @var AttributeSetInterface|MockObject */ - protected $attributeSetMock; + private $attributeSetMock; /** * @var Build|MockObject */ - protected $builderMock; + private $builderMock; /** * @var InputTypeValidator|MockObject */ - protected $inputTypeValidatorMock; + private $inputTypeValidatorMock; /** * @var FormData|MockObject */ - protected $formDataSerializerMock; + private $formDataSerializerMock; /** * @var ProductAttributeInterface|MockObject */ - protected $productAttributeMock; + private $productAttributeMock; /** - * @var Presentation|MockObject + * @var AttributeCodeValidator|MockObject */ - private $formDataSerializerMock; + private $attributeCodeValidatorMock; /** - * @var ProductAttributeInterface|\PHPUnit_Framework_MockObject_MockObject + * @var Presentation|MockObject */ - private $productAttributeMock; + private $presentationMock; /** - * @var AttributeCodeValidator|MockObject + * @var Session|MockObject */ - private $attributeCodeValidatorMock; + + private $sessionMock; protected function setUp(): void { @@ -129,12 +135,6 @@ protected function setUp(): void ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $this->filterManagerMock = $this->getMockBuilder(FilterManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->productHelperMock = $this->getMockBuilder(ProductHelper::class) - ->disableOriginalConstructor() - ->getMock(); $this->attributeFactoryMock = $this->getMockBuilder(AttributeFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() @@ -147,28 +147,10 @@ protected function setUp(): void ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $this->layoutFactoryMock = $this->getMockBuilder(LayoutFactory::class) - ->disableOriginalConstructor() - ->getMock(); $this->redirectMock = $this->getMockBuilder(ResultRedirect::class) ->setMethods(['setData', 'setPath']) ->disableOriginalConstructor() ->getMock(); - $this->attributeSetMock = $this->getMockBuilder(AttributeSetInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->builderMock = $this->getMockBuilder(Build::class) - ->disableOriginalConstructor() - ->getMock(); - $this->inputTypeValidatorMock = $this->getMockBuilder(InputTypeValidator::class) - ->disableOriginalConstructor() - ->getMock(); - $this->formDataSerializerMock = $this->getMockBuilder(FormData::class) - ->disableOriginalConstructor() - ->getMock(); - $this->attributeCodeValidatorMock = $this->getMockBuilder(AttributeCodeValidator::class) - ->disableOriginalConstructor() - ->getMock(); $this->productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class) ->setMethods( [ From 75a7d850627c9fb134b264cff30d6e99e1cd74d3 Mon Sep 17 00:00:00 2001 From: Kate Kyzyma Date: Thu, 28 May 2020 12:00:11 +0300 Subject: [PATCH 04/13] Refactoring AdminGenerateUrlRewritesForProductInCategoriesSwitchOffTest --- ...archUrlRewriteByRequestPathActionGroup.xml | 23 +++++++++++ ...RequestPathInUrlRewriteGrigActionGroup.xml | 21 ++++++++++ ...hIsNotFoundInUrlRewriteGrigActionGroup.xml | 21 ++++++++++ ...tesForProductInCategoriesSwitchOffTest.xml | 41 +++++++++---------- 4 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AdminSearchUrlRewriteByRequestPathActionGroup.xml create mode 100644 app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminRequestPathInUrlRewriteGrigActionGroup.xml create mode 100644 app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminRequestPathIsNotFoundInUrlRewriteGrigActionGroup.xml diff --git a/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AdminSearchUrlRewriteByRequestPathActionGroup.xml b/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AdminSearchUrlRewriteByRequestPathActionGroup.xml new file mode 100644 index 0000000000000..dfdc840e0dc9f --- /dev/null +++ b/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AdminSearchUrlRewriteByRequestPathActionGroup.xml @@ -0,0 +1,23 @@ + + + + + + + EXTENDS: SearchAndSelectUrlRewrite. Removes 'clickOnRowSelectButton' and 'clickOnEditButton'. + + + + + + + + + + diff --git a/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminRequestPathInUrlRewriteGrigActionGroup.xml b/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminRequestPathInUrlRewriteGrigActionGroup.xml new file mode 100644 index 0000000000000..ee5aeb0bab459 --- /dev/null +++ b/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminRequestPathInUrlRewriteGrigActionGroup.xml @@ -0,0 +1,21 @@ + + + + + + + Assert the requested path is shown in the URL Rewrite grid. + + + + + + + + diff --git a/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminRequestPathIsNotFoundInUrlRewriteGrigActionGroup.xml b/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminRequestPathIsNotFoundInUrlRewriteGrigActionGroup.xml new file mode 100644 index 0000000000000..7761a631a1c1f --- /dev/null +++ b/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminRequestPathIsNotFoundInUrlRewriteGrigActionGroup.xml @@ -0,0 +1,21 @@ + + + + + + + Assert the requested path is not shown in the URL Rewrite grid. + + + + + + + + diff --git a/app/code/Magento/UrlRewrite/Test/Mftf/Test/AdminGenerateUrlRewritesForProductInCategoriesSwitchOffTest.xml b/app/code/Magento/UrlRewrite/Test/Mftf/Test/AdminGenerateUrlRewritesForProductInCategoriesSwitchOffTest.xml index 9d6b267055f70..a1adb918d0e8d 100644 --- a/app/code/Magento/UrlRewrite/Test/Mftf/Test/AdminGenerateUrlRewritesForProductInCategoriesSwitchOffTest.xml +++ b/app/code/Magento/UrlRewrite/Test/Mftf/Test/AdminGenerateUrlRewritesForProductInCategoriesSwitchOffTest.xml @@ -44,34 +44,31 @@ - - - - - - - + + + + + + + + + - - - - - - - - + - - - - - - - + + + + + + + + + From a922551cedec33ab3f831590fa5c5a97ff90d470 Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Wed, 3 Jun 2020 10:35:49 +0300 Subject: [PATCH 05/13] fix --- .../Sales/Model/Order/ItemRepository.php | 20 ++++- .../Sales/Service/V1/OrderHoldTest.php | 76 ++++++++++++++++--- 2 files changed, 83 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/ItemRepository.php b/app/code/Magento/Sales/Model/Order/ItemRepository.php index 6e029ac468370..5e36cc3683d6e 100644 --- a/app/code/Magento/Sales/Model/Order/ItemRepository.php +++ b/app/code/Magento/Sales/Model/Order/ItemRepository.php @@ -167,10 +167,7 @@ public function deleteById($id) public function save(OrderItemInterface $entity) { if ($entity->getProductOption()) { - $request = $this->getBuyRequest($entity); - $productOptions = $entity->getProductOptions(); - $productOptions['info_buyRequest'] = $request->toArray(); - $entity->setProductOptions($productOptions); + $entity->setProductOptions($this->getItemProductOptions($entity)); } $this->metadata->getMapper()->save($entity); @@ -178,6 +175,21 @@ public function save(OrderItemInterface $entity) return $this->registry[$entity->getEntityId()]; } + /** + * Return product options + * + * @param OrderItemInterface $entity + * @return array + */ + private function getItemProductOptions(OrderItemInterface $entity): array + { + $request = $this->getBuyRequest($entity); + $productOptions = $entity->getProductOptions(); + $productOptions['info_buyRequest'] = array_merge($productOptions['info_buyRequest'], $request->toArray()); + + return $productOptions; + } + /** * Set parent item. * diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderHoldTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderHoldTest.php index e5df8c18cda0c..e7ee1acda7982 100644 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderHoldTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderHoldTest.php @@ -4,27 +4,64 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Sales\Service\V1; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\Webapi\Rest\Request; +use Magento\Sales\Api\Data\OrderInterface; +use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Sales\Model\Order; +use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\WebapiAbstract; +/** + * Test for hold order. + */ class OrderHoldTest extends WebapiAbstract { - const SERVICE_VERSION = 'V1'; + private const SERVICE_VERSION = 'V1'; - const SERVICE_NAME = 'salesOrderManagementV1'; + private const SERVICE_NAME = 'salesOrderManagementV1'; + + /** + * @var ObjectManagerInterface + */ + private $objectManager; + + /** + * @var OrderRepositoryInterface + */ + private $orderRepository; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + $this->objectManager = Bootstrap::getObjectManager(); + $this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class); + } /** - * @magentoApiDataFixture Magento/Sales/_files/order.php + * Test hold order and check order items product options after. + * + * @magentoApiDataFixture Magento/Sales/_files/order_with_two_configurable_variations.php + * + * @return void */ - public function testOrderHold() + public function testOrderHold(): void { - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $order = $objectManager->get(\Magento\Sales\Model\Order::class)->loadByIncrementId('100000001'); + $order = $this->objectManager->get(Order::class) + ->loadByIncrementId('100000001'); + $orderId = $order->getId(); + $orderItemsProductOptions = $this->getOrderItemsProductOptions($order); + $serviceInfo = [ 'rest' => [ - 'resourcePath' => '/V1/orders/' . $order->getId() . '/hold', - 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + 'resourcePath' => '/V1/orders/' . $orderId . '/hold', + 'httpMethod' => Request::HTTP_METHOD_POST, ], 'soap' => [ 'service' => self::SERVICE_NAME, @@ -32,8 +69,29 @@ public function testOrderHold() 'operation' => self::SERVICE_NAME . 'hold', ], ]; - $requestData = ['id' => $order->getId()]; + $requestData = ['id' => $orderId]; $result = $this->_webApiCall($serviceInfo, $requestData); $this->assertTrue($result); + + $this->assertEquals( + $orderItemsProductOptions, + $this->getOrderItemsProductOptions($this->orderRepository->get($orderId)) + ); + } + + /** + * Return order items product options + * + * @param OrderInterface $order + * @return array + */ + private function getOrderItemsProductOptions(OrderInterface $order): array + { + $result = []; + foreach ($order->getItems() as $orderItem) { + $result[] = $orderItem->getProductOptions(); + } + + return $result; } } From beb41d03ca35b6a423f546f31149df57124475bb Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Wed, 3 Jun 2020 14:27:28 +0300 Subject: [PATCH 06/13] fix webapi --- app/code/Magento/Sales/Model/Order/ItemRepository.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/ItemRepository.php b/app/code/Magento/Sales/Model/Order/ItemRepository.php index 5e36cc3683d6e..dcb669055964b 100644 --- a/app/code/Magento/Sales/Model/Order/ItemRepository.php +++ b/app/code/Magento/Sales/Model/Order/ItemRepository.php @@ -185,7 +185,9 @@ private function getItemProductOptions(OrderItemInterface $entity): array { $request = $this->getBuyRequest($entity); $productOptions = $entity->getProductOptions(); - $productOptions['info_buyRequest'] = array_merge($productOptions['info_buyRequest'], $request->toArray()); + $productOptions['info_buyRequest'] = $productOptions + ? array_merge($productOptions['info_buyRequest'], $request->toArray()) + : $request->toArray(); return $productOptions; } From 3115fe9aca02e3de26163921493bf7a103ea62fe Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Wed, 3 Jun 2020 19:56:56 +0300 Subject: [PATCH 07/13] impr --- app/code/Magento/Sales/Model/Order/ItemRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/ItemRepository.php b/app/code/Magento/Sales/Model/Order/ItemRepository.php index dcb669055964b..345fffc414fbc 100644 --- a/app/code/Magento/Sales/Model/Order/ItemRepository.php +++ b/app/code/Magento/Sales/Model/Order/ItemRepository.php @@ -185,7 +185,7 @@ private function getItemProductOptions(OrderItemInterface $entity): array { $request = $this->getBuyRequest($entity); $productOptions = $entity->getProductOptions(); - $productOptions['info_buyRequest'] = $productOptions + $productOptions['info_buyRequest'] = $productOptions && !empty($productOptions['info_buyRequest']) ? array_merge($productOptions['info_buyRequest'], $request->toArray()) : $request->toArray(); From c503af964a85aa5d57f2fe7cf26cf06074f7362c Mon Sep 17 00:00:00 2001 From: Kate Kyzyma Date: Thu, 11 Jun 2020 08:28:03 +0300 Subject: [PATCH 08/13] Refactoring the test --- ...rtCategoryNameIsShownInMenuActionGroup.xml | 22 +++++++++ .../StorefrontSwitchStoreActionGroup.xml | 21 ++++++++ ...eateCategoryWithCustomRootCategoryTest.xml | 49 ++++++++----------- 3 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml new file mode 100644 index 0000000000000..c56a18b4895a4 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + + Validate that the Category is present in menu on Frontend. + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml new file mode 100644 index 0000000000000..4a403364a91e3 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml @@ -0,0 +1,21 @@ + + + + + + + Switch the Storefront to the provided Store. + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithCustomRootCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithCustomRootCategoryTest.xml index 4b0774d2307dd..4ce4105044e96 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithCustomRootCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithCustomRootCategoryTest.xml @@ -21,8 +21,6 @@ - - @@ -37,39 +35,32 @@ - - - + + + + - - - - - - - + + + + + - - - - - - - - - - - + + + + - - + - - - - + + + + + + From b1849f6d4ff6ee1289e3065e1bddbba54b3f0471 Mon Sep 17 00:00:00 2001 From: Kate Kyzyma Date: Thu, 11 Jun 2020 15:16:27 +0300 Subject: [PATCH 09/13] Refactoring AdminDeleteRootCategoryTest and AdminDeleteRootSubCategoryTest --- ...oryIsListedInCategoriesTreeActionGroup.xml | 17 +++++ ...IsNotListedInCategoriesTreeActionGroup.xml | 17 +++++ ...ategoryNameIsNotShownInMenuActionGroup.xml | 22 +++++++ ...rtCategoryNameIsShownInMenuActionGroup.xml | 22 +++++++ .../StorefrontSwitchStoreActionGroup.xml | 21 ++++++ .../Mftf/Test/AdminDeleteRootCategoryTest.xml | 13 ++-- .../Test/AdminDeleteRootSubCategoryTest.xml | 65 ++++++++----------- 7 files changed, 134 insertions(+), 43 deletions(-) create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsListedInCategoriesTreeActionGroup.xml create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsNotListedInCategoriesTreeActionGroup.xml create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsNotShownInMenuActionGroup.xml create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsListedInCategoriesTreeActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsListedInCategoriesTreeActionGroup.xml new file mode 100644 index 0000000000000..3a75b0a3cd361 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsListedInCategoriesTreeActionGroup.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsNotListedInCategoriesTreeActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsNotListedInCategoriesTreeActionGroup.xml new file mode 100644 index 0000000000000..e0a98a8932d4d --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategoryIsNotListedInCategoriesTreeActionGroup.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsNotShownInMenuActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsNotShownInMenuActionGroup.xml new file mode 100644 index 0000000000000..cead98091d268 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsNotShownInMenuActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + + Validate that the Category is not present in menu on Frontend. + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml new file mode 100644 index 0000000000000..e4af4a46c733e --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + + Validate that the Category is present in menu on Frontend. + + + + + + + + \ No newline at end of file diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml new file mode 100644 index 0000000000000..4a403364a91e3 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml @@ -0,0 +1,21 @@ + + + + + + + Switch the Storefront to the provided Store. + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminDeleteRootCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminDeleteRootCategoryTest.xml index 40bd3bdcfea20..4979b06a1051e 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminDeleteRootCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminDeleteRootCategoryTest.xml @@ -27,16 +27,19 @@ - - - + + + + - - + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminDeleteRootSubCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminDeleteRootSubCategoryTest.xml index fe07360d6b9ca..4310c6f06219a 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminDeleteRootSubCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminDeleteRootSubCategoryTest.xml @@ -33,59 +33,48 @@ - - - - - - - - + + + + + - - - - - - - - - - - - + + + + - - + - - - - + + + + + + - - + + + + - - - + + + + - - - - - - - + + + From f09c981cd4c086e9981ee3810392a824f8cdf0ad Mon Sep 17 00:00:00 2001 From: Dmytro Cheshun Date: Fri, 12 Jun 2020 17:09:20 +0300 Subject: [PATCH 10/13] Minor code style fix --- .../StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml index e4af4a46c733e..c56a18b4895a4 100644 --- a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml @@ -19,4 +19,4 @@ - \ No newline at end of file + From 834959491135ec26a4d7cb2f4b9d3602f063481d Mon Sep 17 00:00:00 2001 From: Kate Kyzyma Date: Mon, 15 Jun 2020 15:50:30 +0300 Subject: [PATCH 11/13] Refactoring AdminCheckSubCategoryIsNotVisibleInNavigationMenuTest --- ...tegoryIsNotVisibleInNavigationMenuTest.xml | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCheckSubCategoryIsNotVisibleInNavigationMenuTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCheckSubCategoryIsNotVisibleInNavigationMenuTest.xml index 192bab7c6d126..2cdec1405e9f9 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCheckSubCategoryIsNotVisibleInNavigationMenuTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCheckSubCategoryIsNotVisibleInNavigationMenuTest.xml @@ -31,21 +31,19 @@ - - - - - - - - - - - + + + + + + - - - - + + + + + + + From 7a6e6465495684a9a08bb5a5c03afb5b6515143e Mon Sep 17 00:00:00 2001 From: Kate Kyzyma Date: Mon, 15 Jun 2020 15:50:56 +0300 Subject: [PATCH 12/13] Refactoring ProductAvailableAfterEnablingSubCategoriesTest --- .../AdminEnableCategoryActionGroup.xml | 17 +++++++++++ ...vailableAfterEnablingSubCategoriesTest.xml | 29 ++++++++++--------- 2 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminEnableCategoryActionGroup.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminEnableCategoryActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminEnableCategoryActionGroup.xml new file mode 100644 index 0000000000000..bd7eb664819dd --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminEnableCategoryActionGroup.xml @@ -0,0 +1,17 @@ + + + + + + + Enable the category + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/ProductAvailableAfterEnablingSubCategoriesTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/ProductAvailableAfterEnablingSubCategoriesTest.xml index 9b5fa25085e1a..48e6245b011ba 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/ProductAvailableAfterEnablingSubCategoriesTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/ProductAvailableAfterEnablingSubCategoriesTest.xml @@ -37,23 +37,26 @@ - - - - - - - - - - + + + + + + + + + - - - + + + + + + + From f4341f8477b1f02a92e412172b31a0d0e9fe30e4 Mon Sep 17 00:00:00 2001 From: Kate Kyzyma Date: Thu, 18 Jun 2020 14:14:02 +0300 Subject: [PATCH 13/13] Updating the test --- .../AdminCreateCategoryWithCustomRootCategoryTest.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithCustomRootCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithCustomRootCategoryTest.xml index 4ce4105044e96..e66984dda4427 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithCustomRootCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithCustomRootCategoryTest.xml @@ -22,7 +22,7 @@ - + @@ -45,19 +45,19 @@ - + - + - +