Skip to content

Commit 8e4b237

Browse files
committed
MAGETWO-85682: Default option for 'Status' attribute not being set
1 parent 0a52f88 commit 8e4b237

File tree

10 files changed

+236
-14
lines changed

10 files changed

+236
-14
lines changed

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

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
77

8-
use Magento\Catalog\Model\Product\Type;
8+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
99
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\General;
10+
use Magento\Eav\Api\AttributeRepositoryInterface;
11+
use Magento\Eav\Api\Data\AttributeInterface;
12+
use Magento\Framework\Stdlib\ArrayManager;
1013

1114
/**
1215
* Class GeneralTest
@@ -15,6 +18,38 @@
1518
*/
1619
class GeneralTest extends AbstractModifierTest
1720
{
21+
/**
22+
* @var AttributeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $attributeRepositoryMock;
25+
26+
/**
27+
* @var General
28+
*/
29+
private $generalModifier;
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
protected function setUp()
35+
{
36+
parent::setUp();
37+
38+
$this->attributeRepositoryMock = $this->getMockBuilder(AttributeRepositoryInterface::class)
39+
->getMockForAbstractClass();
40+
41+
$arrayManager = $this->objectManager->getObject(ArrayManager::class);
42+
43+
$this->generalModifier = $this->objectManager->getObject(
44+
General::class,
45+
[
46+
'attributeRepository' => $this->attributeRepositoryMock,
47+
'locator' => $this->locatorMock,
48+
'arrayManager' => $arrayManager,
49+
]
50+
);
51+
}
52+
1853
/**
1954
* {@inheritdoc}
2055
*/
@@ -40,4 +75,59 @@ public function testModifyMeta()
4075
]
4176
]));
4277
}
78+
79+
/**
80+
* @param array $data
81+
* @param int $defaultStatusValue
82+
* @param array $expectedResult
83+
* @dataProvider modifyDataDataProvider
84+
* @return void
85+
*/
86+
public function testModifyDataNewProduct(array $data, int $defaultStatusValue, array $expectedResult)
87+
{
88+
$attributeMock = $this->getMockBuilder(AttributeInterface::class)
89+
->getMockForAbstractClass();
90+
$attributeMock
91+
->method('getDefaultValue')
92+
->willReturn($defaultStatusValue);
93+
$this->attributeRepositoryMock
94+
->method('get')
95+
->with(
96+
ProductAttributeInterface::ENTITY_TYPE_CODE,
97+
ProductAttributeInterface::CODE_STATUS
98+
)
99+
->willReturn($attributeMock);
100+
$this->assertSame($expectedResult, $this->generalModifier->modifyData($data));
101+
}
102+
103+
/**
104+
* @return array
105+
*/
106+
public function modifyDataDataProvider(): array
107+
{
108+
return [
109+
'With default status value' => [
110+
'data' => [],
111+
'defaultStatusAttributeValue' => 5,
112+
'expectedResult' => [
113+
null => [
114+
General::DATA_SOURCE_DEFAULT => [
115+
ProductAttributeInterface::CODE_STATUS => 5,
116+
],
117+
],
118+
],
119+
],
120+
'Without default status value' => [
121+
'data' => [],
122+
'defaultStatusAttributeValue' => 0,
123+
'expectedResult' => [
124+
null => [
125+
General::DATA_SOURCE_DEFAULT => [
126+
ProductAttributeInterface::CODE_STATUS => 1,
127+
],
128+
],
129+
],
130+
],
131+
];
132+
}
43133
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\Data\ProductAttributeInterface;
99
use Magento\Catalog\Model\Locator\LocatorInterface;
10+
use Magento\Eav\Api\AttributeRepositoryInterface;
1011
use Magento\Ui\Component\Form;
1112
use Magento\Framework\Stdlib\ArrayManager;
1213

@@ -35,16 +36,25 @@ class General extends AbstractModifier
3536
*/
3637
private $localeCurrency;
3738

39+
/**
40+
* @var AttributeRepositoryInterface
41+
*/
42+
private $attributeRepository;
43+
3844
/**
3945
* @param LocatorInterface $locator
4046
* @param ArrayManager $arrayManager
47+
* @param AttributeRepositoryInterface|null $attributeRepository
4148
*/
4249
public function __construct(
4350
LocatorInterface $locator,
44-
ArrayManager $arrayManager
51+
ArrayManager $arrayManager,
52+
AttributeRepositoryInterface $attributeRepository = null
4553
) {
4654
$this->locator = $locator;
4755
$this->arrayManager = $arrayManager;
56+
$this->attributeRepository = $attributeRepository
57+
?: \Magento\Framework\App\ObjectManager::getInstance()->get(AttributeRepositoryInterface::class);
4858
}
4959

5060
/**
@@ -58,7 +68,12 @@ public function modifyData(array $data)
5868
$modelId = $this->locator->getProduct()->getId();
5969

6070
if (!isset($data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS])) {
61-
$data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS] = '1';
71+
$attributeStatus = $this->attributeRepository->get(
72+
ProductAttributeInterface::ENTITY_TYPE_CODE,
73+
ProductAttributeInterface::CODE_STATUS
74+
);
75+
$data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS] =
76+
$attributeStatus->getDefaultValue() ?: 1;
6277
}
6378

6479
return $data;

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Page/AdminProductAttributeFormPage.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
-->
88
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd">
10-
<page name="ProductAttributePage" url="catalog/product_attribute/new/" area="admin" module="Catalog">
11-
<section name="AdminCreateProductAttributeSection"/>
10+
<page name="ProductAttributePage" url="catalog/product_attribute/new/" area="admin" module="Magento_Catalog">
11+
<section name="AttributePropertiesSection"/>
12+
<section name="StorefrontPropertiesSection"/>
1213
</page>
1314
</pages>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminProductAttributeGridSection.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
-->
88

99
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10-
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
10+
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
1111
<section name="AdminProductAttributeGridSection">
12-
<element name="GridFilterFrontEndLabel" type="input" selector="#attributeGrid_filter_frontend_label"/>
13-
<element name="Search" type="button" selector="button[data-action=grid-filter-apply]" timeout="30"/>
14-
<element name="ResetFilter" type="button" selector="button[data-action='grid-filter-reset']" timeout="30"/>
15-
<element name="FirstRow" type="button" selector="//*[@id='attributeGrid_table']/tbody/tr[1]"/>
12+
<element name="attributeCode" type="text" selector="//td[contains(text(),'{{var1}}')]" parameterized="true"/>
13+
<element name="createNewAttributeBtn" type="button" selector="#add"/>
14+
<element name="gridFilterFrontEndLabel" type="input" selector="#attributeGrid_filter_frontend_label"/>
15+
<element name="search" type="button" selector="button[data-action=grid-filter-apply]" timeout="30"/>
16+
<element name="resetFilter" type="button" selector="button[data-action='grid-filter-reset']" timeout="30"/>
17+
<element name="firstRow" type="button" selector="//*[@id='attributeGrid_table']/tbody/tr[1]"/>
1618
</section>
1719
</sections>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminProductFormSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<section name="AdminProductFormSection">
1212
<element name="productName" type="input" selector=".admin__field[data-index=name] input"/>
1313
<element name="productSku" type="input" selector=".admin__field[data-index=sku] input"/>
14+
<element name="productStatus" type="checkbox" selector="input[name='product[status]']"/>
1415
<element name="productPrice" type="input" selector=".admin__field[data-index=price] input"/>
1516
<element name="categoriesDropdown" type="multiselect" selector="div[data-index='category_ids']"/>
1617
<element name="productQuantity" type="input" selector=".admin__field[data-index=qty] input"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
11+
<section name="AttributePropertiesSection">
12+
<element name="defaultLabel" type="input" selector="#attribute_label"/>
13+
<element name="inputType" type="select" selector="#frontend_input"/>
14+
<element name="valueRequired" type="select" selector="#is_required"/>
15+
<element name="advancedProperties" type="button" selector="#advanced_fieldset-wrapper"/>
16+
<element name="defaultValue" type="input" selector="#default_value_text"/>
17+
<element name="save" type="button" selector="#save"/>
18+
<element name="saveAndEdit" type="button" selector="#save_and_edit_button"/>
19+
<element name="checkIfTabOpen" selector="//div[@id='advanced_fieldset-wrapper' and not(contains(@class,'opened'))]" type="button"/>
20+
</section>
21+
</sections>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Test/AdminProductGridFilteringByDateAttributeTest.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
</after>
2727
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttribute"/>
2828
<waitForPageLoad stepKey="wait1"/>
29-
<click selector="{{AdminProductAttributeGridSection.ResetFilter}}" stepKey="resetFiltersOnGrid"/>
30-
<fillField selector="{{AdminProductAttributeGridSection.GridFilterFrontEndLabel}}" userInput="Set Product as New from Date" stepKey="setAttributeLabel"/>
31-
<click selector="{{AdminProductAttributeGridSection.Search}}" stepKey="searchForAttributeFromGrid"/>
32-
<click selector="{{AdminProductAttributeGridSection.FirstRow}}" stepKey="clickOnAttributeRow"/>
29+
<click selector="{{AdminProductAttributeGridSection.resetFilter}}" stepKey="resetFiltersOnGrid"/>
30+
<fillField selector="{{AdminProductAttributeGridSection.gridFilterFrontEndLabel}}" userInput="Set Product as New from Date" stepKey="setAttributeLabel"/>
31+
<click selector="{{AdminProductAttributeGridSection.search}}" stepKey="searchForAttributeFromGrid"/>
32+
<click selector="{{AdminProductAttributeGridSection.firstRow}}" stepKey="clickOnAttributeRow"/>
3333
<waitForPageLoad stepKey="wait2"/>
3434
<click selector="{{AttributePropertiesSection.AdvancedProperties}}" stepKey="openAdvancedPropertiesTab"/>
3535
<selectOption selector="#is_filterable_in_grid" userInput="Yes" stepKey="isFilterableInGrid"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
11+
<test name="AdminProductStatusAttributeDisabledByDefaultTest">
12+
<annotations>
13+
<title value="Verify the default option value for product Status attribute is set correctly during product creation"/>
14+
<description value="The default option value for product Status attribute is set correctly during product creation"/>
15+
<severity value="MAJOR"/>
16+
<testCaseId value="MAGETWO-92838"/>
17+
<group value="Catalog"/>
18+
</annotations>
19+
<before>
20+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
21+
</before>
22+
<after>
23+
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttribute"/>
24+
<waitForPageLoad stepKey="wait1"/>
25+
<click selector="{{AdminProductAttributeGridSection.resetFilter}}" stepKey="resetFiltersOnGrid1"/>
26+
<fillField selector="{{AdminProductAttributeGridSection.gridFilterFrontEndLabel}}" userInput="Enable Product" stepKey="setAttributeLabel1"/>
27+
<click selector="{{AdminProductAttributeGridSection.search}}" stepKey="searchForAttributeFromTheGrid1"/>
28+
<click selector="{{AdminProductAttributeGridSection.firstRow}}" stepKey="clickOnAttributeRow1"/>
29+
<waitForPageLoad stepKey="wait2"/>
30+
<click selector="{{AdminNewAttributePanelSection.isDefault('1')}}" stepKey="resetOptionForStatusAttribute"/>
31+
<click selector="{{AttributePropertiesSection.save}}" stepKey="saveAttribute1"/>
32+
<waitForPageLoad stepKey="waitForSaveAttribute1"/>
33+
<actionGroup ref="ClearCacheActionGroup" stepKey="clearCache1"/>
34+
<actionGroup ref="logout" stepKey="logoutOfAdmin"/>
35+
</after>
36+
37+
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttribute"/>
38+
<waitForPageLoad stepKey="wait1"/>
39+
<click selector="{{AdminProductAttributeGridSection.resetFilter}}" stepKey="resetFiltersOnGrid"/>
40+
<fillField selector="{{AdminProductAttributeGridSection.gridFilterFrontEndLabel}}" userInput="Enable Product" stepKey="setAttributeLabel"/>
41+
<click selector="{{AdminProductAttributeGridSection.search}}" stepKey="searchForAttributeFromTheGrid"/>
42+
<click selector="{{AdminProductAttributeGridSection.firstRow}}" stepKey="clickOnAttributeRow"/>
43+
<waitForPageLoad stepKey="wait2"/>
44+
<click selector="{{AdminNewAttributePanelSection.isDefault('2')}}" stepKey="chooseDisabledOptionForStatus"/>
45+
<click selector="{{AttributePropertiesSection.save}}" stepKey="saveAttribute"/>
46+
<waitForPageLoad stepKey="waitForAttributeToSave"/>
47+
<actionGroup ref="ClearCacheActionGroup" stepKey="clearCache"/>
48+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
49+
<waitForPageLoad time="30" stepKey="waitForProductGridPageToLoad"/>
50+
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickOnAddProductDropdown"/>
51+
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickOnAddSimpleProduct"/>
52+
<waitForPageLoad stepKey="waitForProductEditToLoad"/>
53+
<dontSeeCheckboxIsChecked selector="{{AdminProductFormSection.productStatus}}" stepKey="dontSeeCheckboxEnableProductIsChecked"/>
54+
</test>
55+
</tests>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd">
11+
<page name="AdminProductCreatePage" url="catalog/product/new/set/{{set}}/type/{{type}}/" area="admin" module="Magento_Catalog" parameterized="true">
12+
<section name="AdminNewAttributePanel"/>
13+
</page>
14+
</pages>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
11+
<section name="AdminNewAttributePanelSection">
12+
<element name="container" type="text" selector="#create_new_attribute"/>
13+
<element name="saveAttribute" type="button" selector="#save"/>
14+
<element name="newAttributeIFrame" type="iframe" selector="create_new_attribute_container"/>
15+
<element name="defaultLabel" type="input" selector="input[name='frontend_label[0]']"/>
16+
<element name="inputType" type="select" selector="select[name='frontend_input']"/>
17+
<element name="addOption" type="button" selector="#add_new_option_button"/>
18+
<element name="isDefault" type="radio" selector="[data-role='options-container'] tr:nth-of-type({{row}}) input[name='default[]']" parameterized="true"/>
19+
<element name="optionAdminValue" type="input" selector="[data-role='options-container'] input[name='option[value][option_{{row}}][0]']" parameterized="true"/>
20+
<element name="optionDefaultStoreValue" type="input" selector="[data-role='options-container'] input[name='option[value][option_{{row}}][1]']" parameterized="true"/>
21+
<element name="deleteOption" type="button" selector="#delete_button_option_{{row}}" parameterized="true"/>
22+
</section>
23+
</sections>

0 commit comments

Comments
 (0)