Skip to content

Commit

Permalink
Merge pull request magento#2649 from magento-arcticfoxes/MAGETWO-91434
Browse files Browse the repository at this point in the history
[arcticfoxes] MAGETWO-91434: Default option for 'Status' attribute not being set
  • Loading branch information
cpartica authored Jun 5, 2018
2 parents 0ad656d + addd4af commit 6110fdd
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
*/
namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Model\Product\Type;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\General;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Eav\Api\Data\AttributeInterface;
use Magento\Framework\Stdlib\ArrayManager;

/**
* Class GeneralTest
Expand All @@ -15,6 +18,35 @@
*/
class GeneralTest extends AbstractModifierTest
{
/**
* @var AttributeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $attributeRepositoryMock;

/**
* @var General
*/
private $generalModifier;

protected function setUp()
{
parent::setUp();

$this->attributeRepositoryMock = $this->getMockBuilder(AttributeRepositoryInterface::class)
->getMockForAbstractClass();

$arrayManager = $this->objectManager->getObject(ArrayManager::class);

$this->generalModifier = $this->objectManager->getObject(
General::class,
[
'attributeRepository' => $this->attributeRepositoryMock,
'locator' => $this->locatorMock,
'arrayManager' => $arrayManager,
]
);
}

/**
* {@inheritdoc}
*/
Expand All @@ -40,4 +72,59 @@ public function testModifyMeta()
]
]));
}

/**
* @param array $data
* @param int $defaultStatusValue
* @param array $expectedResult
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @dataProvider modifyDataDataProvider
*/
public function testModifyDataNewProduct(array $data, int $defaultStatusValue, array $expectedResult)
{
$attributeMock = $this->getMockBuilder(AttributeInterface::class)
->getMockForAbstractClass();
$attributeMock
->method('getDefaultValue')
->willReturn($defaultStatusValue);
$this->attributeRepositoryMock
->method('get')
->with(
ProductAttributeInterface::ENTITY_TYPE_CODE,
ProductAttributeInterface::CODE_STATUS
)
->willReturn($attributeMock);
$this->assertSame($expectedResult, $this->generalModifier->modifyData($data));
}

/**
* @return array
*/
public function modifyDataDataProvider(): array
{
return [
'With default status value' => [
'data' => [],
'defaultStatusAttributeValue' => 5,
'expectedResult' => [
null => [
General::DATA_SOURCE_DEFAULT => [
ProductAttributeInterface::CODE_STATUS => 5,
],
],
],
],
'Without default status value' => [
'data' => [],
'defaultStatusAttributeValue' => 0,
'expectedResult' => [
null => [
General::DATA_SOURCE_DEFAULT => [
ProductAttributeInterface::CODE_STATUS => 1,
],
],
],
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Ui\Component\Form;
use Magento\Framework\Stdlib\ArrayManager;

Expand Down Expand Up @@ -35,21 +36,31 @@ class General extends AbstractModifier
*/
private $localeCurrency;

/**
* @var AttributeRepositoryInterface
*/
private $attributeRepository;

/**
* @param LocatorInterface $locator
* @param ArrayManager $arrayManager
* @param AttributeRepositoryInterface|null $attributeRepository
*/
public function __construct(
LocatorInterface $locator,
ArrayManager $arrayManager
ArrayManager $arrayManager,
AttributeRepositoryInterface $attributeRepository = null
) {
$this->locator = $locator;
$this->arrayManager = $arrayManager;
$this->attributeRepository = $attributeRepository
?: \Magento\Framework\App\ObjectManager::getInstance()->get(AttributeRepositoryInterface::class);
}

/**
* {@inheritdoc}
* @since 101.0.0
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function modifyData(array $data)
{
Expand All @@ -58,7 +69,12 @@ public function modifyData(array $data)
$modelId = $this->locator->getProduct()->getId();

if (!isset($data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS])) {
$data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS] = '1';
$attributeStatus = $this->attributeRepository->get(
ProductAttributeInterface::ENTITY_TYPE_CODE,
ProductAttributeInterface::CODE_STATUS
);
$data[$modelId][static::DATA_SOURCE_DEFAULT][ProductAttributeInterface::CODE_STATUS] =
$attributeStatus->getDefaultValue() ?: 1;
}

return $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<section name="AdminProductFormSection">
<element name="productName" type="input" selector=".admin__field[data-index=name] input"/>
<element name="productSku" type="input" selector=".admin__field[data-index=sku] input"/>
<element name="productStatus" type="checkbox" selector="input[name='product[status]']"/>
<element name="productPrice" type="input" selector=".admin__field[data-index=price] input"/>
<element name="advancedPricingLink" type="button" selector="button[data-index='advanced_pricing_button']"/>
<element name="categoriesDropdown" type="multiselect" selector="div[data-index='category_ids']"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
<test name="AdminProductStatusAttributeDisabledByDefaultTest">
<annotations>
<title value="Verify the default option value for product Status attribute is set correctly during product creation"/>
<description value="The default option value for product Status attribute is set correctly during product creation"/>
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-92424"/>
<group value="Catalog"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>

</before>
<after>
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttribute"/>
<waitForPageLoad stepKey="wait1"/>
<click selector="{{AdminProductAttributeGridSection.ResetFilter}}" stepKey="resetFiltersOnGrid1"/>
<fillField selector="{{AdminProductAttributeGridSection.GridFilterFrontEndLabel}}" userInput="Enable Product" stepKey="setAttributeLabel1"/>
<click selector="{{AdminProductAttributeGridSection.Search}}" stepKey="searchForAttributeFromTheGrid1"/>
<click selector="{{AdminProductAttributeGridSection.FirstRow}}" stepKey="clickOnAttributeRow1"/>
<waitForPageLoad stepKey="wait2"/>
<click selector="{{AdminNewAttributePanel.isDefault('1')}}" stepKey="resetOptionForStatusAttribute"/>
<click selector="{{AttributePropertiesSection.Save}}" stepKey="saveAttribute1"/>
<waitForPageLoad stepKey="waitForSaveAttribute1"/>
<actionGroup ref="ClearCacheActionGroup" stepKey="clearCache1"/>

<actionGroup ref="logout" stepKey="logoutOfAdmin"/>
</after>
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttribute"/>
<waitForPageLoad stepKey="wait1"/>
<click selector="{{AdminProductAttributeGridSection.ResetFilter}}" stepKey="resetFiltersOnGrid"/>
<fillField selector="{{AdminProductAttributeGridSection.GridFilterFrontEndLabel}}" userInput="Enable Product" stepKey="setAttributeLabel"/>
<click selector="{{AdminProductAttributeGridSection.Search}}" stepKey="searchForAttributeFromTheGrid"/>
<click selector="{{AdminProductAttributeGridSection.FirstRow}}" stepKey="clickOnAttributeRow"/>
<waitForPageLoad stepKey="wait2"/>
<click selector="{{AdminNewAttributePanel.isDefault('2')}}" stepKey="chooseDisabledOptionForStatus"/>
<click selector="{{AttributePropertiesSection.Save}}" stepKey="saveAttribute"/>
<waitForPageLoad stepKey="waitForAttributeToSave"/>
<actionGroup ref="ClearCacheActionGroup" stepKey="clearCache"/>
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
<waitForPageLoad time="30" stepKey="waitForProductGridPageToLoad"/>
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickOnAddProductDropdown"/>
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickOnAddSimpleProduct"/>
<waitForPageLoad stepKey="waitForProductEditToLoad"/>
<dontSeeCheckboxIsChecked selector="{{AdminProductFormSection.productStatus}}" stepKey="dontSeeCheckboxEnableProductIsChecked"/>

</test>
</tests>

0 comments on commit 6110fdd

Please sign in to comment.