Skip to content

Commit c5319ae

Browse files
committed
MC-19398: Changing Attribute Set while editing disabled Product makes it enabled
- Fixing unit tests
1 parent 79cb787 commit c5319ae

File tree

4 files changed

+150
-29
lines changed

4 files changed

+150
-29
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="DisableProductLabelActionGroup">
12+
<annotations>
13+
<description>Disable Product Label and Change Attribute Set.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="createAttributeSet"/>
17+
</arguments>
18+
19+
<checkOption selector="{{AdminProductFormSection.enableProductLabel}}" stepKey="disableProduct"/>
20+
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickSaveButton"/>
21+
<waitForPageLoad time="30" stepKey="waitForChangeAttrSet"/>
22+
<click selector="{{AdminProductFormSection.attributeSet}}" stepKey="startEditAttrSet"/>
23+
<fillField selector="{{AdminProductFormSection.attributeSetFilter}}" userInput="{{createAttributeSet.attribute_set_name}}" stepKey="searchForAttrSet"/>
24+
<click selector="{{AdminProductFormSection.attributeSetFilterResult}}" stepKey="selectAttrSet"/>
25+
<dontSeeCheckboxIsChecked selector="{{AdminProductFormSection.productStatus}}" stepKey="dontSeeCheckboxEnableProductIsChecked"/>
26+
</actionGroup>
27+
</actionGroups>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminDisableProductOnChangingAttributeSetTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Disabled product is enabled when change attribute set"/>
14+
<title value="Verify product status while changing attribute set"/>
15+
<description value="Value set for enabled product has to be shown when attribute set is changed"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MC-19716"/>
18+
<group value="catalog"/>
19+
</annotations>
20+
<before>
21+
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
22+
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
23+
<requiredEntity createDataKey="createCategory"/>
24+
</createData>
25+
<createData entity="CatalogAttributeSet" stepKey="createAttributeSet"/>
26+
</before>
27+
<after>
28+
<deleteData createDataKey="createAttributeSet" stepKey="deleteAttributeSet"/>
29+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/>
30+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
31+
<actionGroup ref="ClearProductsFilterActionGroup" stepKey="clearProductsFilter"/>
32+
<actionGroup ref="logout" stepKey="logout"/>
33+
</after>
34+
<actionGroup ref="LoginAsAdmin" stepKey="login"/>
35+
<amOnPage url="{{AdminProductAttributeSetEditPage.url}}/$$createAttributeSet.attribute_set_id$$/" stepKey="onAttributeSetEdit"/>
36+
<actionGroup ref="SaveAttributeSet" stepKey="SaveAttributeSet"/>
37+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProduct">
38+
<argument name="product" value="$$createSimpleProduct$$"/>
39+
</actionGroup>
40+
41+
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct1">
42+
<argument name="product" value="$$createSimpleProduct$$"/>
43+
</actionGroup>
44+
<actionGroup ref="DisableProductLabelActionGroup" stepKey="disableWhileChangingAttributeSet" >
45+
<argument name="createAttributeSet" value="$$createAttributeSet$$"/>
46+
</actionGroup>
47+
48+
</test>
49+
</tests>

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -110,33 +110,26 @@ public function testModifyDataNewProduct(array $data, int $defaultStatusValue, a
110110
/**
111111
* Verify the product attribute status set owhen editing existing product
112112
*
113-
* @throws \Magento\Framework\Exception\NoSuchEntityException
113+
* @param array $data
114+
* @param string $modelId
115+
* @param int $defaultStatus
116+
* @param int $statusAttributeValue
117+
* @param array $expectedResult
118+
* @throws \Magento\Framework\Exception\NoSuchEntityException
119+
* @dataProvider modifyDataOfExistingProductDataProvider
114120
*/
115-
public function testModifyDataExistingProduct()
116-
{
117-
$data = [];
118-
$modelId = 1;
119-
$defaultStatusValue = 1;
120-
$expectedResult = [
121-
'enabledProductStatus' => [
122-
General::DATA_SOURCE_DEFAULT => [
123-
ProductAttributeInterface::CODE_STATUS => 1,
124-
],
125-
],
126-
'disabledProductStatus' => [
127-
General::DATA_SOURCE_DEFAULT => [
128-
ProductAttributeInterface::CODE_STATUS => 2,
129-
],
130-
],
131-
];
132-
$enabledProductStatus = 1;
133-
$disabledProductStatus = 2;
134-
$attributeMock = $this->getMockBuilder(AttributeInterface::class)
135-
->getMockForAbstractClass();
136-
$attributeMock
121+
public function testModifyDataOfExistingProduct(
122+
array $data,
123+
string $modelId,
124+
int $defaultStatus,
125+
int $statusAttributeValue,
126+
array $expectedResult
127+
) {
128+
$attributeMock = $this->getMockForAbstractClass(AttributeInterface::class);
129+
$attributeMock->expects($this->any())
137130
->method('getDefaultValue')
138-
->willReturn($defaultStatusValue);
139-
$this->attributeRepositoryMock
131+
->willReturn($defaultStatus);
132+
$this->attributeRepositoryMock->expects($this->any())
140133
->method('get')
141134
->with(
142135
ProductAttributeInterface::ENTITY_TYPE_CODE,
@@ -148,9 +141,61 @@ public function testModifyDataExistingProduct()
148141
->willReturn($modelId);
149142
$this->productMock->expects($this->any())
150143
->method('getStatus')
151-
->willReturnOnConsecutiveCalls($enabledProductStatus, $disabledProductStatus);
152-
$this->assertSame($expectedResult['enabledProductStatus'], current($this->generalModifier->modifyData($data)));
153-
$this->assertSame($expectedResult['disabledProductStatus'], current($this->generalModifier->modifyData($data)));
144+
->willReturn($statusAttributeValue);
145+
$this->assertSame($expectedResult, current($this->generalModifier->modifyData($data)));
146+
}
147+
148+
/**
149+
* @return array
150+
*/
151+
public function modifyDataOfExistingProductDataProvider(): array
152+
{
153+
return [
154+
'With enable status value' => [
155+
'data' => [],
156+
'modelId' => '1',
157+
'defaultStatus' => 1,
158+
'statusAttributeValue' => 1,
159+
'expectedResult' => [
160+
General::DATA_SOURCE_DEFAULT => [
161+
ProductAttributeInterface::CODE_STATUS => 1,
162+
],
163+
],
164+
],
165+
'Without disable status value' => [
166+
'data' => [],
167+
'modelId' => '1',
168+
'defaultStatus' => 1,
169+
'statusAttributeValue' => 2,
170+
'expectedResult' => [
171+
General::DATA_SOURCE_DEFAULT => [
172+
ProductAttributeInterface::CODE_STATUS => 2,
173+
],
174+
],
175+
],
176+
'With enable status value with empty modelId' => [
177+
'data' => [],
178+
'modelId' => '',
179+
'defaultStatus' => 1,
180+
'statusAttributeValue' => 1,
181+
'expectedResult' => [
182+
General::DATA_SOURCE_DEFAULT => [
183+
ProductAttributeInterface::CODE_STATUS => 1,
184+
],
185+
],
186+
],
187+
'Without disable status value with empty modelId' => [
188+
'data' => [],
189+
'modelId' => '',
190+
'defaultStatus' => 2,
191+
'statusAttributeValue' => 2,
192+
'expectedResult' => [
193+
General::DATA_SOURCE_DEFAULT => [
194+
ProductAttributeInterface::CODE_STATUS => 2,
195+
],
196+
],
197+
],
198+
];
154199
}
155200

156201
/**

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function modifyData(array $data)
7373
$modelId = $this->locator->getProduct()->getId();
7474

7575
$productStatus = $this->locator->getProduct()->getStatus();
76-
if ((isset($productStatus) && !empty($productStatus)) && (isset($modelId)) && !empty($modelId)) {
76+
if (!empty($productStatus) && !empty($modelId)) {
7777
$data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS] = $productStatus;
7878
} elseif (!isset($data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS])) {
7979
$attributeStatus = $this->attributeRepository->get(

0 commit comments

Comments
 (0)