Skip to content

Commit 6110fdd

Browse files
authored
Merge pull request #2649 from magento-arcticfoxes/MAGETWO-91434
[arcticfoxes] MAGETWO-91434: Default option for 'Status' attribute not being set
2 parents 0ad656d + addd4af commit 6110fdd

File tree

4 files changed

+164
-3
lines changed

4 files changed

+164
-3
lines changed

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

Lines changed: 88 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,35 @@
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+
protected function setUp()
32+
{
33+
parent::setUp();
34+
35+
$this->attributeRepositoryMock = $this->getMockBuilder(AttributeRepositoryInterface::class)
36+
->getMockForAbstractClass();
37+
38+
$arrayManager = $this->objectManager->getObject(ArrayManager::class);
39+
40+
$this->generalModifier = $this->objectManager->getObject(
41+
General::class,
42+
[
43+
'attributeRepository' => $this->attributeRepositoryMock,
44+
'locator' => $this->locatorMock,
45+
'arrayManager' => $arrayManager,
46+
]
47+
);
48+
}
49+
1850
/**
1951
* {@inheritdoc}
2052
*/
@@ -40,4 +72,59 @@ public function testModifyMeta()
4072
]
4173
]));
4274
}
75+
76+
/**
77+
* @param array $data
78+
* @param int $defaultStatusValue
79+
* @param array $expectedResult
80+
* @throws \Magento\Framework\Exception\NoSuchEntityException
81+
* @dataProvider modifyDataDataProvider
82+
*/
83+
public function testModifyDataNewProduct(array $data, int $defaultStatusValue, array $expectedResult)
84+
{
85+
$attributeMock = $this->getMockBuilder(AttributeInterface::class)
86+
->getMockForAbstractClass();
87+
$attributeMock
88+
->method('getDefaultValue')
89+
->willReturn($defaultStatusValue);
90+
$this->attributeRepositoryMock
91+
->method('get')
92+
->with(
93+
ProductAttributeInterface::ENTITY_TYPE_CODE,
94+
ProductAttributeInterface::CODE_STATUS
95+
)
96+
->willReturn($attributeMock);
97+
$this->assertSame($expectedResult, $this->generalModifier->modifyData($data));
98+
}
99+
100+
/**
101+
* @return array
102+
*/
103+
public function modifyDataDataProvider(): array
104+
{
105+
return [
106+
'With default status value' => [
107+
'data' => [],
108+
'defaultStatusAttributeValue' => 5,
109+
'expectedResult' => [
110+
null => [
111+
General::DATA_SOURCE_DEFAULT => [
112+
ProductAttributeInterface::CODE_STATUS => 5,
113+
],
114+
],
115+
],
116+
],
117+
'Without default status value' => [
118+
'data' => [],
119+
'defaultStatusAttributeValue' => 0,
120+
'expectedResult' => [
121+
null => [
122+
General::DATA_SOURCE_DEFAULT => [
123+
ProductAttributeInterface::CODE_STATUS => 1,
124+
],
125+
],
126+
],
127+
],
128+
];
129+
}
43130
}

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

Lines changed: 18 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,21 +36,31 @@ 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
/**
5161
* {@inheritdoc}
5262
* @since 101.0.0
63+
* @throws \Magento\Framework\Exception\NoSuchEntityException
5364
*/
5465
public function modifyData(array $data)
5566
{
@@ -58,7 +69,12 @@ public function modifyData(array $data)
5869
$modelId = $this->locator->getProduct()->getId();
5970

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

6480
return $data;

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
@@ -10,6 +10,7 @@
1010
<section name="AdminProductFormSection">
1111
<element name="productName" type="input" selector=".admin__field[data-index=name] input"/>
1212
<element name="productSku" type="input" selector=".admin__field[data-index=sku] input"/>
13+
<element name="productStatus" type="checkbox" selector="input[name='product[status]']"/>
1314
<element name="productPrice" type="input" selector=".admin__field[data-index=price] input"/>
1415
<element name="advancedPricingLink" type="button" selector="button[data-index='advanced_pricing_button']"/>
1516
<element name="categoriesDropdown" type="multiselect" selector="div[data-index='category_ids']"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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-92424"/>
17+
<group value="Catalog"/>
18+
</annotations>
19+
<before>
20+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
21+
22+
</before>
23+
<after>
24+
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttribute"/>
25+
<waitForPageLoad stepKey="wait1"/>
26+
<click selector="{{AdminProductAttributeGridSection.ResetFilter}}" stepKey="resetFiltersOnGrid1"/>
27+
<fillField selector="{{AdminProductAttributeGridSection.GridFilterFrontEndLabel}}" userInput="Enable Product" stepKey="setAttributeLabel1"/>
28+
<click selector="{{AdminProductAttributeGridSection.Search}}" stepKey="searchForAttributeFromTheGrid1"/>
29+
<click selector="{{AdminProductAttributeGridSection.FirstRow}}" stepKey="clickOnAttributeRow1"/>
30+
<waitForPageLoad stepKey="wait2"/>
31+
<click selector="{{AdminNewAttributePanel.isDefault('1')}}" stepKey="resetOptionForStatusAttribute"/>
32+
<click selector="{{AttributePropertiesSection.Save}}" stepKey="saveAttribute1"/>
33+
<waitForPageLoad stepKey="waitForSaveAttribute1"/>
34+
<actionGroup ref="ClearCacheActionGroup" stepKey="clearCache1"/>
35+
36+
<actionGroup ref="logout" stepKey="logoutOfAdmin"/>
37+
</after>
38+
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttribute"/>
39+
<waitForPageLoad stepKey="wait1"/>
40+
<click selector="{{AdminProductAttributeGridSection.ResetFilter}}" stepKey="resetFiltersOnGrid"/>
41+
<fillField selector="{{AdminProductAttributeGridSection.GridFilterFrontEndLabel}}" userInput="Enable Product" stepKey="setAttributeLabel"/>
42+
<click selector="{{AdminProductAttributeGridSection.Search}}" stepKey="searchForAttributeFromTheGrid"/>
43+
<click selector="{{AdminProductAttributeGridSection.FirstRow}}" stepKey="clickOnAttributeRow"/>
44+
<waitForPageLoad stepKey="wait2"/>
45+
<click selector="{{AdminNewAttributePanel.isDefault('2')}}" stepKey="chooseDisabledOptionForStatus"/>
46+
<click selector="{{AttributePropertiesSection.Save}}" stepKey="saveAttribute"/>
47+
<waitForPageLoad stepKey="waitForAttributeToSave"/>
48+
<actionGroup ref="ClearCacheActionGroup" stepKey="clearCache"/>
49+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
50+
<waitForPageLoad time="30" stepKey="waitForProductGridPageToLoad"/>
51+
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickOnAddProductDropdown"/>
52+
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickOnAddSimpleProduct"/>
53+
<waitForPageLoad stepKey="waitForProductEditToLoad"/>
54+
<dontSeeCheckboxIsChecked selector="{{AdminProductFormSection.productStatus}}" stepKey="dontSeeCheckboxEnableProductIsChecked"/>
55+
56+
</test>
57+
</tests>

0 commit comments

Comments
 (0)