Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.3-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #21834: Add argument to show filter text in URL rewrite grid after click on back button (by @vbmagento)
 - #21135: Fix eav form foreach error #21134 (by @wojtekn)
 - #18067: Fixes variables in configuration fields not being replaced with actual value� (by @hostep)
 - #21749: Sitemap Generation - Product URL check null fix (by @asim-vax)
 - #21511: SHQ18-1568 Updating UPS endpoint to use https. Http is no longer reli� (by @wsajosh)
 - #21484: Populate label elements for street address fields in checkout (by @scottsb)
 - #21465: Module data fixtures for @magentoDataFixtureBeforeTransaction annotations (by @Vinai)
 - #21065: Refactored Retrieval Of Entity ID To Make AbstractDataProvider Usable (by @sprankhub)
 - #21053: Allow redis compression options to be specified during `setup:install` process (by @cmacdonald-au)
 - #20526: [EAV] Improving the EAV attribute code validation, by not allowing to use n� (by @eduard13)
 - #20898: Fixed #13319 , Incorrect method return value in \Magento\Shipping\Model\Carrier\AbstractCarrier::getTotalNumOfBoxes() (by @cedmudit)
 - #19265: add missing fields to quote_address (by @ErikPel)


Fixed GitHub Issues:
 - #21805: Filter in url rewrites table in backend isn't being remembered (reported by @hostep) has been fixed in #21834 by @vbmagento in 2.3-develop branch
   Related commits:
     1. ae6c8bc
     2. d85fd44
     3. f75b3e9
     4. d5a61c0

 - #21134: Invalid argument supplied for foreach thrown in EAV code  (reported by @wojtekn) has been fixed in #21135 by @wojtekn in 2.3-develop branch
   Related commits:
     1. ac40d43
     2. 059f399
     3. 9f0dfcf

 - #15972: Since Magento 2.2.1, certain variables in the configuration get resolved to their actual value (reported by @hostep) has been fixed in #18067 by @hostep in 2.3-develop branch
   Related commits:
     1. a8f1729

 - #10893: Street fields in checkout don't have a label that's readable by a screenreader (reported by @TomFranssen) has been fixed in #21484 by @scottsb in 2.3-develop branch
   Related commits:
     1. e1fa289

 - #20766: AttributeCode column name length validation throws wrong error message (reported by @brosenberger) has been fixed in #20526 by @eduard13 in 2.3-develop branch
   Related commits:
     1. 6f83604
     2. adb1a8f
     3. 3c8acbb
     4. 82f5511
     5. 4488371
     6. e028d6f
     7. 8129886
     8. 079bb15
     9. 5666a85
     10. 50b78da
     11. 6878668
     12. 40683de
     13. 392cd1b

 - #20943: No complete validation while creation of attributes. (reported by @irajneeshgupta) has been fixed in #20526 by @eduard13 in 2.3-develop branch
   Related commits:
     1. 6f83604
     2. adb1a8f
     3. 3c8acbb
     4. 82f5511
     5. 4488371
     6. e028d6f
     7. 8129886
     8. 079bb15
     9. 5666a85
     10. 50b78da
     11. 6878668
     12. 40683de
     13. 392cd1b

 - #13319: Incorrect method return value in \Magento\Shipping\Model\Carrier\AbstractCarrier::getTotalNumOfBoxes() (reported by @korostii) has been fixed in #20898 by @cedmudit in 2.3-develop branch
   Related commits:
     1. 56504e1

 - #17658: validate function in vatvalidation calls checkVatNumber a lot (reported by @sanderjongsma) has been fixed in #19265 by @ErikPel in 2.3-develop branch
   Related commits:
     1. e27f09f
     2. 7f15bd8
  • Loading branch information
magento-engcom-team authored Mar 30, 2019
2 parents 450880c + 46033f1 commit 2bca2aa
Show file tree
Hide file tree
Showing 32 changed files with 607 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,25 +195,6 @@ public function execute()
? $model->getAttributeCode()
: $this->getRequest()->getParam('attribute_code');
$attributeCode = $attributeCode ?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]);
if (strlen($attributeCode) > 0) {
$validatorAttrCode = new \Zend_Validate_Regex(
['pattern' => '/^[a-zA-Z\x{600}-\x{6FF}][a-zA-Z\x{600}-\x{6FF}_0-9]{0,30}$/u']
);
if (!$validatorAttrCode->isValid($attributeCode)) {
$this->messageManager->addErrorMessage(
__(
'Attribute code "%1" is invalid. Please use only letters (a-z or A-Z), ' .
'numbers (0-9) or underscore(_) in this field, first character should be a letter.',
$attributeCode
)
);
return $this->returnResult(
'catalog/*/edit',
['attribute_id' => $attributeId, '_current' => true],
['error' => true]
);
}
}
$data['attribute_code'] = $attributeCode;

//validate frontend_input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute;

use Magento\Framework\Serialize\Serializer\FormData;
use Magento\Catalog\Controller\Adminhtml\Product\Attribute as AttributeAction;
use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject;
use Magento\Catalog\Controller\Adminhtml\Product\Attribute as AttributeAction;
use Magento\Framework\Serialize\Serializer\FormData;

/**
* Product attribute validate controller.
Expand Down Expand Up @@ -43,6 +44,11 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
*/
private $formDataSerializer;

/**
* @var AttributeCodeValidator
*/
private $attributeCodeValidator;

/**
* Constructor
*
Expand All @@ -54,6 +60,7 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
* @param array $multipleAttributeList
* @param FormData|null $formDataSerializer
* @param AttributeCodeValidator|null $attributeCodeValidator
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
Expand All @@ -63,14 +70,18 @@ public function __construct(
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\View\LayoutFactory $layoutFactory,
array $multipleAttributeList = [],
FormData $formDataSerializer = null
FormData $formDataSerializer = null,
AttributeCodeValidator $attributeCodeValidator = null
) {
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
$this->resultJsonFactory = $resultJsonFactory;
$this->layoutFactory = $layoutFactory;
$this->multipleAttributeList = $multipleAttributeList;
$this->formDataSerializer = $formDataSerializer ?: ObjectManager::getInstance()
->get(FormData::class);
$this->attributeCodeValidator = $attributeCodeValidator ?: ObjectManager::getInstance()->get(
AttributeCodeValidator::class
);
}

/**
Expand Down Expand Up @@ -115,6 +126,12 @@ public function execute()
$response->setError(true);
$response->setProductAttribute($attribute->toArray());
}

if (!$this->attributeCodeValidator->isValid($attributeCode)) {
$this->setMessageToResponse($response, $this->attributeCodeValidator->getMessages());
$response->setError(true);
}

if ($this->getRequest()->has('new_attribute_set_name')) {
$setName = $this->getRequest()->getParam('new_attribute_set_name');
/** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */
Expand Down
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\Controller\Adminhtml\Product\Attribute\Save;
use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator;
use Magento\Framework\Serialize\Serializer\FormData;
use Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\AttributeTest;
use Magento\Catalog\Model\Product\AttributeSet\BuildFactory;
Expand Down Expand Up @@ -94,6 +95,11 @@ class SaveTest extends AttributeTest
*/
private $productAttributeMock;

/**
* @var AttributeCodeValidator|\PHPUnit_Framework_MockObject_MockObject
*/
private $attributeCodeValidatorMock;

protected function setUp()
{
parent::setUp();
Expand Down Expand Up @@ -138,6 +144,9 @@ protected function setUp()
$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();
Expand Down Expand Up @@ -171,6 +180,7 @@ protected function getModel()
'groupCollectionFactory' => $this->groupCollectionFactoryMock,
'layoutFactory' => $this->layoutFactoryMock,
'formDataSerializer' => $this->formDataSerializerMock,
'attributeCodeValidator' => $this->attributeCodeValidatorMock
]);
}

Expand Down Expand Up @@ -224,6 +234,10 @@ public function testExecute()
$this->productAttributeMock
->method('getAttributeCode')
->willReturn('test_code');
$this->attributeCodeValidatorMock
->method('isValid')
->with('test_code')
->willReturn(true);
$this->requestMock->expects($this->once())
->method('getPostValue')
->willReturn($data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Attribute;

use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Validate;
use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator;
use Magento\Framework\Serialize\Serializer\FormData;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\AttributeTest;
Expand Down Expand Up @@ -67,6 +68,11 @@ class ValidateTest extends AttributeTest
*/
private $formDataSerializerMock;

/**
* @var AttributeCodeValidator|\PHPUnit_Framework_MockObject_MockObject
*/
private $attributeCodeValidatorMock;

protected function setUp()
{
parent::setUp();
Expand Down Expand Up @@ -95,6 +101,9 @@ protected function setUp()
$this->formDataSerializerMock = $this->getMockBuilder(FormData::class)
->disableOriginalConstructor()
->getMock();
$this->attributeCodeValidatorMock = $this->getMockBuilder(AttributeCodeValidator::class)
->disableOriginalConstructor()
->getMock();

$this->contextMock->expects($this->any())
->method('getObjectManager')
Expand All @@ -117,6 +126,7 @@ protected function getModel()
'layoutFactory' => $this->layoutFactoryMock,
'multipleAttributeList' => ['select' => 'option'],
'formDataSerializer' => $this->formDataSerializerMock,
'attributeCodeValidator' => $this->attributeCodeValidatorMock,
]
);
}
Expand All @@ -141,6 +151,12 @@ public function testExecute()
$this->attributeMock->expects($this->once())
->method('loadByCode')
->willReturnSelf();

$this->attributeCodeValidatorMock->expects($this->once())
->method('isValid')
->with('test_attribute_code')
->willReturn(true);

$this->requestMock->expects($this->once())
->method('has')
->with('new_attribute_set_name')
Expand Down Expand Up @@ -190,6 +206,11 @@ public function testUniqueValidation(array $options, $isError)
->with($serializedOptions)
->willReturn($options);

$this->attributeCodeValidatorMock->expects($this->once())
->method('isValid')
->with('test_attribute_code')
->willReturn(true);

$this->objectManagerMock->expects($this->once())
->method('create')
->willReturn($this->attributeMock);
Expand Down Expand Up @@ -333,6 +354,11 @@ public function testEmptyOption(array $options, $result)
->method('loadByCode')
->willReturnSelf();

$this->attributeCodeValidatorMock->expects($this->once())
->method('isValid')
->with('test_attribute_code')
->willReturn(true);

$this->resultJsonFactoryMock->expects($this->once())
->method('create')
->willReturn($this->resultJson);
Expand Down Expand Up @@ -444,6 +470,10 @@ public function testExecuteWithOptionsDataError()
[\Magento\Eav\Model\Entity\Attribute\Set::class, [], $this->attributeSetMock]
]);

$this->attributeCodeValidatorMock
->method('isValid')
->willReturn(true);

$this->attributeMock
->method('loadByCode')
->willReturnSelf();
Expand All @@ -463,4 +493,81 @@ public function testExecuteWithOptionsDataError()

$this->getModel()->execute();
}

/**
* Test execute with an invalid attribute code
*
* @dataProvider provideInvalidAttributeCodes
* @param string $attributeCode
* @param $result
* @throws \Magento\Framework\Exception\NotFoundException
*/
public function testExecuteWithInvalidAttributeCode($attributeCode, $result)
{
$serializedOptions = '{"key":"value"}';
$this->requestMock->expects($this->any())
->method('getParam')
->willReturnMap([
['frontend_label', null, null],
['frontend_input', 'select', 'multipleselect'],
['attribute_code', null, $attributeCode],
['new_attribute_set_name', null, 'test_attribute_set_name'],
['message_key', Validate::DEFAULT_MESSAGE_KEY, 'message'],
['serialized_options', '[]', $serializedOptions],
]);

$this->formDataSerializerMock
->expects($this->once())
->method('unserialize')
->with($serializedOptions)
->willReturn(["key" => "value"]);

$this->objectManagerMock->expects($this->once())
->method('create')
->willReturn($this->attributeMock);

$this->attributeMock->expects($this->once())
->method('loadByCode')
->willReturnSelf();

$this->attributeCodeValidatorMock->expects($this->once())
->method('isValid')
->with($attributeCode)
->willReturn(false);

$this->attributeCodeValidatorMock->expects($this->once())
->method('getMessages')
->willReturn(['Invalid Attribute Code.']);

$this->resultJsonFactoryMock->expects($this->once())
->method('create')
->willReturn($this->resultJson);

$this->resultJson->expects($this->once())
->method('setJsonData')
->willReturnArgument(0);

$response = $this->getModel()->execute();
$responseObject = json_decode($response);

$this->assertEquals($responseObject, $result);
}

/**
* Providing invalid attribute codes
*
* @return array
*/
public function provideInvalidAttributeCodes()
{
return [
'invalid attribute code' => [
'.attribute_code',
(object) [
'error' => true,
'message' => 'Invalid Attribute Code.',
]
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
for ($lineIndex = 0; $lineIndex < (int)$attributeConfig['size']; $lineIndex++) {
$isFirstLine = $lineIndex === 0;
$line = [
'label' => __("%1: Line %2", $attributeConfig['label'], $lineIndex + 1),
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
// customScope is used to group elements within a single form e.g. they can be validated separately
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Config/Block/System/Config/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Fie
$backendModel = $field->getBackendModel();
// Backend models which implement ProcessorInterface are processed by ScopeConfigInterface
if (!$backendModel instanceof ProcessorInterface) {
if (array_key_exists($path, $this->_configData)) {
$data = $this->_configData[$path];
}

$backendModel->setPath($path)
->setValue($data)
->setWebsite($this->getWebsiteCode())
Expand Down
Loading

0 comments on commit 2bca2aa

Please sign in to comment.