Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Browse files Browse the repository at this point in the history
Accepted Community Pull Requests:
 - #27369: Fixed issue 27051: Saving an attribute with backend_type static (by @jiten-patel)


Fixed GitHub Issues:
 - #27051: Saving an attribute with backend_type 'static' will remove the content of the 'frontend_class' field. (reported by @MLucaciu) has been fixed in #27369 by @jiten-patel in 2.4-develop branch
   Related commits:
     1. b06db1f
     2. aaa7054
     3. fa154cd
     4. 7d8b893
     5. 054bf5d
     6. 2160c37
     7. 83545c0
     8. c1a01fc
     9. eeb7433
     10. 7d2d0d3
     11. eb34341
  • Loading branch information
magento-engcom-team authored Jun 25, 2020
2 parents 5d3d5c7 + 1e68561 commit 86ec99b
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ public function execute()
unset($data['apply_to']);
}

if ($model->getBackendType() == 'static' && !$model->getIsUserDefined()) {
$data['frontend_class'] = $model->getFrontendClass();
}

$model->addData($data);

if (!$attributeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

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\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;
Expand All @@ -31,63 +33,64 @@

/**
* @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
Expand All @@ -104,19 +107,34 @@ class SaveTest extends AttributeTest
*/
private $attributeCodeValidatorMock;

/**
* @var Presentation|MockObject
*/
private $presentationMock;

/**
* @var Session|MockObject
*/

private $sessionMock;

protected 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()
Expand All @@ -129,32 +147,23 @@ 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()
->getMockForAbstractClass();
$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);
Expand All @@ -167,7 +176,7 @@ protected function setUp(): void
}

/**
* {@inheritdoc}
* @inheritdoc
*/
protected function getModel()
{
Expand All @@ -184,7 +193,9 @@ protected function getModel()
'groupCollectionFactory' => $this->groupCollectionFactoryMock,
'layoutFactory' => $this->layoutFactoryMock,
'formDataSerializer' => $this->formDataSerializerMock,
'attributeCodeValidator' => $this->attributeCodeValidatorMock
'attributeCodeValidator' => $this->attributeCodeValidatorMock,
'presentation' => $this->presentationMock,
'_session' => $this->sessionMock
]);
}

Expand Down Expand Up @@ -214,6 +225,67 @@ public function testExecuteWithEmptyData()
$this->assertInstanceOf(ResultRedirect::class, $this->getModel()->execute());
}

public function testExecuteSaveFrontendClass()
{
$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());
}

public function testExecute()
{
$data = [
Expand Down

0 comments on commit 86ec99b

Please sign in to comment.