From e27f09f987f289b0a2d3f1e0552f67c63e2e302d Mon Sep 17 00:00:00 2001 From: Erik Pellikka Date: Sat, 17 Nov 2018 23:54:53 +0200 Subject: [PATCH 01/38] add missing fields to quote_address --- app/code/Magento/Quote/etc/db_schema.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Quote/etc/db_schema.xml b/app/code/Magento/Quote/etc/db_schema.xml index 7dd215b87e8cc..ec06077cbe43b 100644 --- a/app/code/Magento/Quote/etc/db_schema.xml +++ b/app/code/Magento/Quote/etc/db_schema.xml @@ -202,6 +202,8 @@ + + From 7f15bd86241bace94cdc77b5487bc7f593482a69 Mon Sep 17 00:00:00 2001 From: Erik Pellikka Date: Mon, 19 Nov 2018 17:49:14 +0200 Subject: [PATCH 02/38] add translations for the new columns --- app/code/Magento/Quote/i18n/en_US.csv | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Quote/i18n/en_US.csv b/app/code/Magento/Quote/i18n/en_US.csv index ae7453aa0d0cc..b24179297493a 100644 --- a/app/code/Magento/Quote/i18n/en_US.csv +++ b/app/code/Magento/Quote/i18n/en_US.csv @@ -65,3 +65,5 @@ error345,error345 Carts,Carts "Manage carts","Manage carts" "Invalid state change requested","Invalid state change requested" +"Validated Country Code","Validated Country Code" +"Validated Vat Number","Validated Vat Number" From 6f83604f8a702ac0f4fda98ca7697d15a5c60456 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Wed, 23 Jan 2019 16:47:07 +0200 Subject: [PATCH 03/38] Improving the eav attribute code validation, by not allowing to use not allowed chars --- .../Magento/Eav/Model/Entity/Attribute.php | 39 ++++++------ .../Eav/Model/Validator/Attribute/Code.php | 63 +++++++++++++++++++ app/code/Magento/Eav/Setup/EavSetup.php | 32 ++++------ .../Magento/Eav/Setup/EavSetupTest.php | 29 ++++++++- 4 files changed, 122 insertions(+), 41 deletions(-) create mode 100644 app/code/Magento/Eav/Model/Validator/Attribute/Code.php diff --git a/app/code/Magento/Eav/Model/Entity/Attribute.php b/app/code/Magento/Eav/Model/Entity/Attribute.php index 06a4abb985802..ab8a869123dce 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute.php @@ -5,7 +5,9 @@ */ namespace Magento\Eav\Model\Entity; +use Magento\Eav\Model\Validator\Attribute\Code; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Stdlib\DateTime; use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface; @@ -80,6 +82,11 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im */ protected $dateTimeFormatter; + /** + * @var Code|null + */ + private $attributeCodeValidator; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -99,6 +106,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im * @param DateTimeFormatterInterface $dateTimeFormatter * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Code|null $attributeCodeValidator * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @codeCoverageIgnore @@ -122,7 +130,8 @@ public function __construct( DateTimeFormatterInterface $dateTimeFormatter, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + Code $attributeCodeValidator = null ) { parent::__construct( $context, @@ -145,6 +154,9 @@ public function __construct( $this->_localeResolver = $localeResolver; $this->reservedAttributeList = $reservedAttributeList; $this->dateTimeFormatter = $dateTimeFormatter; + $this->attributeCodeValidator = $attributeCodeValidator ?: ObjectManager::getInstance()->get( + Code::class + ); } /** @@ -230,6 +242,10 @@ public function loadEntityAttributeIdBySet() */ public function beforeSave() { + if (isset($this->_data['attribute_code'])) { + $this->attributeCodeValidator->isValid($this->_data['attribute_code']); + } + // prevent overriding product data if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) { throw new LocalizedException( @@ -240,25 +256,6 @@ public function beforeSave() ); } - /** - * Check for maximum attribute_code length - */ - if (isset( - $this->_data['attribute_code'] - ) && !\Zend_Validate::is( - $this->_data['attribute_code'], - 'StringLength', - ['max' => self::ATTRIBUTE_CODE_MAX_LENGTH] - ) - ) { - throw new LocalizedException( - __( - 'The attribute code needs to be %1 characters or fewer. Re-enter the code and try again.', - self::ATTRIBUTE_CODE_MAX_LENGTH - ) - ); - } - $defaultValue = $this->getDefaultValue(); $hasDefaultValue = (string)$defaultValue != ''; @@ -513,7 +510,7 @@ public function __sleep() public function __wakeup() { parent::__wakeup(); - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $objectManager = ObjectManager::getInstance(); $this->_localeDate = $objectManager->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class); $this->_localeResolver = $objectManager->get(\Magento\Framework\Locale\ResolverInterface::class); $this->reservedAttributeList = $objectManager->get(\Magento\Catalog\Model\Product\ReservedAttributeList::class); diff --git a/app/code/Magento/Eav/Model/Validator/Attribute/Code.php b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php new file mode 100644 index 0000000000000..01e3dac499bae --- /dev/null +++ b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php @@ -0,0 +1,63 @@ + $minLength, 'max' => $maxLength] + ); + if (!$isAllowedLength) { + throw new LocalizedException(__( + 'An attribute code must not be less than %1 and more than %2 characters.', + $minLength, + $maxLength + )); + } + + return true; + } +} diff --git a/app/code/Magento/Eav/Setup/EavSetup.php b/app/code/Magento/Eav/Setup/EavSetup.php index 6e81ddc36e9c9..77fd0e95de364 100644 --- a/app/code/Magento/Eav/Setup/EavSetup.php +++ b/app/code/Magento/Eav/Setup/EavSetup.php @@ -9,6 +9,7 @@ use Magento\Eav\Model\Entity\Setup\Context; use Magento\Eav\Model\Entity\Setup\PropertyMapperInterface; use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory; +use Magento\Eav\Model\Validator\Attribute\Code; use Magento\Framework\App\CacheInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\App\ResourceConnection; @@ -80,6 +81,11 @@ class EavSetup */ private $_defaultAttributeSetName = 'Default'; + /** + * @var Code + */ + private $attributeCodeValidator; + /** * Init * @@ -87,17 +93,22 @@ class EavSetup * @param Context $context * @param CacheInterface $cache * @param CollectionFactory $attrGroupCollectionFactory + * @param Code|null $attributeCodeValidator */ public function __construct( ModuleDataSetupInterface $setup, Context $context, CacheInterface $cache, - CollectionFactory $attrGroupCollectionFactory + CollectionFactory $attrGroupCollectionFactory, + Code $attributeCodeValidator = null ) { $this->cache = $cache; $this->attrGroupCollectionFactory = $attrGroupCollectionFactory; $this->attributeMapper = $context->getAttributeMapper(); $this->setup = $setup; + $this->attributeCodeValidator = $attributeCodeValidator ?: ObjectManager::getInstance()->get( + Code::class + ); } /** @@ -783,25 +794,8 @@ private function _getValue($array, $key, $default = null) */ private function _validateAttributeData($data) { - $minLength = \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MIN_LENGTH; - $maxLength = \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH; $attributeCode = isset($data['attribute_code']) ? $data['attribute_code'] : ''; - - $isAllowedLength = \Zend_Validate::is( - trim($attributeCode), - 'StringLength', - ['min' => $minLength, 'max' => $maxLength] - ); - - if (!$isAllowedLength) { - $errorMessage = __( - 'An attribute code must not be less than %1 and more than %2 characters.', - $minLength, - $maxLength - ); - - throw new LocalizedException($errorMessage); - } + $this->attributeCodeValidator->isValid($attributeCode); return true; } diff --git a/dev/tests/integration/testsuite/Magento/Eav/Setup/EavSetupTest.php b/dev/tests/integration/testsuite/Magento/Eav/Setup/EavSetupTest.php index 5d7a72c65597d..3e8e146144c36 100644 --- a/dev/tests/integration/testsuite/Magento/Eav/Setup/EavSetupTest.php +++ b/dev/tests/integration/testsuite/Magento/Eav/Setup/EavSetupTest.php @@ -55,7 +55,7 @@ public function addAttributeDataProvider() { return [ ['eav_setup_test'], - ['_59_characters_59_characters_59_characters_59_characters_59'], + ['characters_59_characters_59_characters_59_characters_59_59_'], ]; } @@ -90,6 +90,33 @@ public function addAttributeThrowExceptionDataProvider() ]; } + /** + * Verify that add attribute throw exception if attribute_code is not valid. + * + * @param string|null $attributeCode + * + * @dataProvider addInvalidAttributeThrowExceptionDataProvider + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first char + */ + public function testAddInvalidAttributeThrowException($attributeCode) + { + $attributeData = $this->getAttributeData(); + $this->eavSetup->addAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, $attributeData); + } + /** + * Data provider for testAddInvalidAttributeThrowException(). + * + * @return array + */ + public function addInvalidAttributeThrowExceptionDataProvider() + { + return [ + ['1first_character_is_not_letter'], + ['attribute.with.dots'], + ]; + } + /** * Get simple attribute data. */ From adb1a8f6f16a0da2cada4d2a838328334b4e3a18 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Wed, 23 Jan 2019 23:14:29 +0200 Subject: [PATCH 04/38] Declaring strict typing --- app/code/Magento/Eav/Model/Validator/Attribute/Code.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Eav/Model/Validator/Attribute/Code.php b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php index 01e3dac499bae..c3a29854d227f 100644 --- a/app/code/Magento/Eav/Model/Validator/Attribute/Code.php +++ b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php @@ -3,18 +3,21 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Eav\Model\Validator\Attribute; use Magento\Eav\Model\Entity\Attribute; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Validator\AbstractValidator; +use Zend_Validate; /** * Class Code * * Validation EAV attribute code */ -class Code extends \Magento\Framework\Validator\AbstractValidator +class Code extends AbstractValidator { /** * Validates the correctness of the attribute code @@ -45,7 +48,7 @@ public function isValid($attributeCode) */ $minLength = Attribute::ATTRIBUTE_CODE_MIN_LENGTH; $maxLength = Attribute::ATTRIBUTE_CODE_MAX_LENGTH; - $isAllowedLength = \Zend_Validate::is( + $isAllowedLength = Zend_Validate::is( trim($attributeCode), 'StringLength', ['min' => $minLength, 'max' => $maxLength] From 3c8acbbe6fe490141af37f5f9cea80df8401d885 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Thu, 24 Jan 2019 20:08:15 +0200 Subject: [PATCH 05/38] Using an alias for attribute code validator --- app/code/Magento/Eav/Model/Entity/Attribute.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Eav/Model/Entity/Attribute.php b/app/code/Magento/Eav/Model/Entity/Attribute.php index ab8a869123dce..38e47cc98a524 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute.php @@ -5,7 +5,7 @@ */ namespace Magento\Eav\Model\Entity; -use Magento\Eav\Model\Validator\Attribute\Code; +use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator; use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; @@ -83,7 +83,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im protected $dateTimeFormatter; /** - * @var Code|null + * @var AttributeCodeValidator|null */ private $attributeCodeValidator; @@ -106,7 +106,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im * @param DateTimeFormatterInterface $dateTimeFormatter * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection - * @param Code|null $attributeCodeValidator + * @param AttributeCodeValidator|null $attributeCodeValidator * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @codeCoverageIgnore @@ -131,7 +131,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - Code $attributeCodeValidator = null + AttributeCodeValidator $attributeCodeValidator = null ) { parent::__construct( $context, @@ -155,7 +155,7 @@ public function __construct( $this->reservedAttributeList = $reservedAttributeList; $this->dateTimeFormatter = $dateTimeFormatter; $this->attributeCodeValidator = $attributeCodeValidator ?: ObjectManager::getInstance()->get( - Code::class + AttributeCodeValidator::class ); } From 82f5511ee558549501a2b533b6b0a31df609fae5 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Mon, 28 Jan 2019 15:40:21 +0200 Subject: [PATCH 06/38] Adding returning strict typing --- app/code/Magento/Eav/Model/Validator/Attribute/Code.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Eav/Model/Validator/Attribute/Code.php b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php index c3a29854d227f..af4791cc0d5d1 100644 --- a/app/code/Magento/Eav/Model/Validator/Attribute/Code.php +++ b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php @@ -22,11 +22,11 @@ class Code extends AbstractValidator /** * Validates the correctness of the attribute code * - * @param $attributeCode + * @param string $attributeCode * @return bool * @throws LocalizedException */ - public function isValid($attributeCode) + public function isValid($attributeCode): bool { /** * Check attribute_code for allowed characters From 56504e1d8b0bde92a0eba4cec2ef233ad147dfc9 Mon Sep 17 00:00:00 2001 From: Mudit Shukla Date: Sun, 3 Feb 2019 11:01:36 +0530 Subject: [PATCH 07/38] Updated AbstractCarrier.php Fixed #13319 , added type casting and updated function comment.. --- .../Magento/Shipping/Model/Carrier/AbstractCarrier.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php index f9030ee75630b..628bc9c4295b0 100644 --- a/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php +++ b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php @@ -531,10 +531,10 @@ protected function _getPerorderPrice($cost, $handlingType, $handlingFee) } /** - * Sets the number of boxes for shipping + * Gets the average weight of each box available for shipping * - * @param int $weight in some measure - * @return int + * @param float $weight in some measure + * @return float */ public function getTotalNumOfBoxes($weight) { @@ -545,7 +545,7 @@ public function getTotalNumOfBoxes($weight) $maxPackageWeight = $this->getConfigData('max_package_weight'); if ($weight > $maxPackageWeight && $maxPackageWeight != 0) { $this->_numBoxes = ceil($weight / $maxPackageWeight); - $weight = $weight / $this->_numBoxes; + $weight = (float)$weight / $this->_numBoxes; } return $weight; From 448837183069ececaba307b47c7e7ebb1ca27963 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Mon, 4 Feb 2019 19:40:07 +0200 Subject: [PATCH 08/38] Allowing usage of the capital letters in attribute code --- app/code/Magento/Eav/Model/Validator/Attribute/Code.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Eav/Model/Validator/Attribute/Code.php b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php index af4791cc0d5d1..578816bc99abd 100644 --- a/app/code/Magento/Eav/Model/Validator/Attribute/Code.php +++ b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php @@ -32,7 +32,7 @@ public function isValid($attributeCode): bool * Check attribute_code for allowed characters */ if (trim($attributeCode) - && !preg_match('/^[a-z][a-z0-9_]*$/', trim($attributeCode)) + && !preg_match('/^[a-zA-Z]+[a-zA-Z0-9_]*$/', trim($attributeCode)) ) { throw new LocalizedException( __( From e028d6f490a0c616095654daf221cc6d9b27f66f Mon Sep 17 00:00:00 2001 From: eduard13 Date: Wed, 6 Feb 2019 09:30:03 +0200 Subject: [PATCH 09/38] Improving the validation rules on product attribute save --- .../Adminhtml/Product/Attribute/Save.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index 39ed11b1806cd..cdf0397674e30 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -196,8 +196,23 @@ public function execute() : $this->getRequest()->getParam('attribute_code'); $attributeCode = $attributeCode ?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]); if (strlen($attributeCode) > 0) { + $attributeCodeIsValid = true; + $minLength = \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MIN_LENGTH; + $maxLength = \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH; + + if (strlen($attributeCode) < $minLength || strlen($attributeCode) > $maxLength) { + $this->messageManager->addErrorMessage( + __( + 'An attribute code must not be less than %1 and more than %2 characters.', + $minLength, + $maxLength + ) + ); + $attributeCodeIsValid = false; + } + $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'] + ['pattern' => '/^[a-zA-Z]+[a-zA-Z0-9_]$/u'] ); if (!$validatorAttrCode->isValid($attributeCode)) { $this->messageManager->addErrorMessage( @@ -207,6 +222,10 @@ public function execute() $attributeCode ) ); + $attributeCodeIsValid = false; + } + + if (!$attributeCodeIsValid) { return $this->returnResult( 'catalog/*/edit', ['attribute_id' => $attributeId, '_current' => true], From 8129886905890be85b009d499451854653f9ebf8 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Thu, 7 Feb 2019 17:48:05 +0200 Subject: [PATCH 10/38] Fixing the Regex expr --- .../Catalog/Controller/Adminhtml/Product/Attribute/Save.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index cdf0397674e30..3fb93911b85d7 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -212,7 +212,7 @@ public function execute() } $validatorAttrCode = new \Zend_Validate_Regex( - ['pattern' => '/^[a-zA-Z]+[a-zA-Z0-9_]$/u'] + ['pattern' => '/^[a-zA-Z]+[a-zA-Z0-9_]+$/u'] ); if (!$validatorAttrCode->isValid($attributeCode)) { $this->messageManager->addErrorMessage( From 079bb15922f35995991d42be8b671d034f7cd0b9 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Thu, 7 Feb 2019 18:27:09 +0200 Subject: [PATCH 11/38] Using the same regex rule as it is in attribute code validator --- .../Catalog/Controller/Adminhtml/Product/Attribute/Save.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index 3fb93911b85d7..78a25567eb195 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -212,7 +212,7 @@ public function execute() } $validatorAttrCode = new \Zend_Validate_Regex( - ['pattern' => '/^[a-zA-Z]+[a-zA-Z0-9_]+$/u'] + ['pattern' => '/^[a-zA-Z]+[a-zA-Z0-9_]*$/u'] ); if (!$validatorAttrCode->isValid($attributeCode)) { $this->messageManager->addErrorMessage( From fa477196ef25c2df82cd7c7bc03257c48a04d14b Mon Sep 17 00:00:00 2001 From: "colin.macdonald" Date: Fri, 8 Feb 2019 14:34:48 +1100 Subject: [PATCH 12/38] allowing setup:install to specify redis-compress-data and redis-compression-library for cache and pagecache --- .../Setup/Model/ConfigOptionsList/Cache.php | 26 ++++++++++++++++--- .../Model/ConfigOptionsList/PageCache.php | 26 +++++++++++++------ .../Model/ConfigOptionsList/CacheTest.php | 22 +++++++++++++--- .../Model/ConfigOptionsList/PageCacheTest.php | 20 +++++++++----- 4 files changed, 74 insertions(+), 20 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php index 173064b472217..eb1b30093a670 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php @@ -27,6 +27,8 @@ class Cache implements ConfigOptionsListInterface const INPUT_KEY_CACHE_BACKEND_REDIS_DATABASE = 'cache-backend-redis-db'; const INPUT_KEY_CACHE_BACKEND_REDIS_PORT = 'cache-backend-redis-port'; const INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD = 'cache-backend-redis-password'; + const INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA = 'cache-backend-redis-compress-data'; + const INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY = 'cache-backend-redis-compression-library'; const INPUT_KEY_CACHE_ID_PREFIX = 'cache-id-prefix'; const CONFIG_PATH_CACHE_BACKEND = 'cache/frontend/default/backend'; @@ -34,6 +36,8 @@ class Cache implements ConfigOptionsListInterface const CONFIG_PATH_CACHE_BACKEND_DATABASE = 'cache/frontend/default/backend_options/database'; const CONFIG_PATH_CACHE_BACKEND_PORT = 'cache/frontend/default/backend_options/port'; const CONFIG_PATH_CACHE_BACKEND_PASSWORD = 'cache/frontend/default/backend_options/password'; + const CONFIG_PATH_CACHE_BACKEND_COMPRESS_DATA = 'cache/frontend/default/backend_options/compress_data'; + const CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIBRARY = 'cache/frontend/default/backend_options/compression_library'; const CONFIG_PATH_CACHE_ID_PREFIX = 'cache/frontend/default/id_prefix'; /** @@ -43,7 +47,9 @@ class Cache implements ConfigOptionsListInterface self::INPUT_KEY_CACHE_BACKEND_REDIS_SERVER => '127.0.0.1', self::INPUT_KEY_CACHE_BACKEND_REDIS_DATABASE => '0', self::INPUT_KEY_CACHE_BACKEND_REDIS_PORT => '6379', - self::INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD => '' + self::INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD => '', + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA => '0', + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY => '', ]; /** @@ -60,7 +66,9 @@ class Cache implements ConfigOptionsListInterface self::INPUT_KEY_CACHE_BACKEND_REDIS_SERVER => self::CONFIG_PATH_CACHE_BACKEND_SERVER, self::INPUT_KEY_CACHE_BACKEND_REDIS_DATABASE => self::CONFIG_PATH_CACHE_BACKEND_DATABASE, self::INPUT_KEY_CACHE_BACKEND_REDIS_PORT => self::CONFIG_PATH_CACHE_BACKEND_PORT, - self::INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD => self::CONFIG_PATH_CACHE_BACKEND_PASSWORD + self::INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD => self::CONFIG_PATH_CACHE_BACKEND_PASSWORD, + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA => self::CONFIG_PATH_CACHE_BACKEND_COMPRESS_DATA, + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY => self::CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIBRARY, ]; /** @@ -115,12 +123,24 @@ public function getOptions() self::CONFIG_PATH_CACHE_BACKEND_PASSWORD, 'Redis server password' ), + new TextConfigOption( + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA, + TextConfigOption::FRONTEND_WIZARD_TEXT, + self::CONFIG_PATH_CACHE_BACKEND_COMPRESS_DATA, + 'Set to 1 to compress the cache (use 0 to disable)' + ), + new TextConfigOption( + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY, + TextConfigOption::FRONTEND_WIZARD_TEXT, + self::CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIBRARY, + 'Compression library to use [snappy,lzf,l4z,zstd,gzip] (leave blank to determine automatically)' + ), new TextConfigOption( self::INPUT_KEY_CACHE_ID_PREFIX, TextConfigOption::FRONTEND_WIZARD_TEXT, self::CONFIG_PATH_CACHE_ID_PREFIX, 'ID prefix for cache keys' - ) + ), ]; } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php index 7451b59356828..57912cb117c2a 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php @@ -26,16 +26,18 @@ class PageCache implements ConfigOptionsListInterface const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_SERVER = 'page-cache-redis-server'; const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_DATABASE = 'page-cache-redis-db'; const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PORT = 'page-cache-redis-port'; - const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA = 'page-cache-redis-compress-data'; const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD = 'page-cache-redis-password'; + const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA = 'page-cache-redis-compress-data'; + const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY = 'page-cache-redis-compression-library'; const INPUT_KEY_PAGE_CACHE_ID_PREFIX = 'page-cache-id-prefix'; const CONFIG_PATH_PAGE_CACHE_BACKEND = 'cache/frontend/page_cache/backend'; const CONFIG_PATH_PAGE_CACHE_BACKEND_SERVER = 'cache/frontend/page_cache/backend_options/server'; const CONFIG_PATH_PAGE_CACHE_BACKEND_DATABASE = 'cache/frontend/page_cache/backend_options/database'; const CONFIG_PATH_PAGE_CACHE_BACKEND_PORT = 'cache/frontend/page_cache/backend_options/port'; - const CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESS_DATA = 'cache/frontend/page_cache/backend_options/compress_data'; const CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD = 'cache/frontend/page_cache/backend_options/password'; + const CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESS_DATA = 'cache/frontend/page_cache/backend_options/compress_data'; + const CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIBRARY = 'cache/frontend/page_cache/backend_options/compression_library'; const CONFIG_PATH_PAGE_CACHE_ID_PREFIX = 'cache/frontend/page_cache/id_prefix'; /** @@ -45,8 +47,9 @@ class PageCache implements ConfigOptionsListInterface self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_SERVER => '127.0.0.1', self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_DATABASE => '1', self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PORT => '6379', + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD => '', self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA => '0', - self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD => '' + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY => '', ]; /** @@ -63,8 +66,9 @@ class PageCache implements ConfigOptionsListInterface self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_SERVER => self::CONFIG_PATH_PAGE_CACHE_BACKEND_SERVER, self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_DATABASE => self::CONFIG_PATH_PAGE_CACHE_BACKEND_DATABASE, self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PORT => self::CONFIG_PATH_PAGE_CACHE_BACKEND_PORT, + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD => self::CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD, self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA => self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESS_DATA, - self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD => self::CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY => self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIBRARY, ]; /** @@ -113,6 +117,12 @@ public function getOptions() self::CONFIG_PATH_PAGE_CACHE_BACKEND_PORT, 'Redis server listen port' ), + new TextConfigOption( + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD, + TextConfigOption::FRONTEND_WIZARD_TEXT, + self::CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD, + 'Redis server password' + ), new TextConfigOption( self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA, TextConfigOption::FRONTEND_WIZARD_TEXT, @@ -120,17 +130,17 @@ public function getOptions() 'Set to 1 to compress the full page cache (use 0 to disable)' ), new TextConfigOption( - self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD, + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY, TextConfigOption::FRONTEND_WIZARD_TEXT, - self::CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD, - 'Redis server password' + self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIBRARY, + 'Compression library to use [snappy,lzf,l4z,zstd,gzip] (leave blank to determine automatically)' ), new TextConfigOption( self::INPUT_KEY_PAGE_CACHE_ID_PREFIX, TextConfigOption::FRONTEND_WIZARD_TEXT, self::CONFIG_PATH_PAGE_CACHE_ID_PREFIX, 'ID prefix for cache keys' - ) + ), ]; } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php index 9c123fcb330dd..f4d8136e85270 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php @@ -68,8 +68,17 @@ public function testGetOptions() $this->assertEquals('cache-backend-redis-password', $options[4]->getName()); $this->assertArrayHasKey(5, $options); + $this->assertInstanceOf(TextConfigOption::class, $options[6]); + $this->assertEquals('cache-backend-redis-compress-data', $options[6]->getName()); + + $this->assertArrayHasKey(6, $options); + $this->assertInstanceOf(TextConfigOption::class, $options[7]); + $this->assertEquals('cache-backend-redis-compression-library', $options[7]->getName()); + + $this->assertArrayHasKey(7, $options); $this->assertInstanceOf(TextConfigOption::class, $options[5]); $this->assertEquals('cache-id-prefix', $options[5]->getName()); + } /** @@ -88,7 +97,9 @@ public function testCreateConfigCacheRedis() 'server' => '', 'port' => '', 'database' => '', - 'password' => '' + 'password' => '', + 'compress_data' => '0', + 'compression_library' => '', ], 'id_prefix' => $this->expectedIdPrefix(), ] @@ -115,18 +126,23 @@ public function testCreateConfigWithRedisConfig() 'server' => 'localhost', 'port' => '1234', 'database' => '5', - 'password' => '' + 'password' => '', + 'compress_data' => '1', + 'compression_library' => 'gzip', ], 'id_prefix' => $this->expectedIdPrefix(), ] ] ] ]; + $options = [ 'cache-backend' => 'redis', 'cache-backend-redis-server' => 'localhost', 'cache-backend-redis-port' => '1234', - 'cache-backend-redis-db' => '5' + 'cache-backend-redis-db' => '5', + 'cache-backend-redis-compress-data' => '1', + 'cache-backend-redis-compression-library' => 'gzip' ]; $configData = $this->configOptionsList->createConfig($options, $this->deploymentConfigMock); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php index 1cf3937f98684..f0a68d213d407 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php @@ -65,15 +65,20 @@ public function testGetOptions() $this->assertArrayHasKey(4, $options); $this->assertInstanceOf(TextConfigOption::class, $options[4]); - $this->assertEquals('page-cache-redis-compress-data', $options[4]->getName()); + $this->assertEquals('page-cache-redis-password', $options[4]->getName()); $this->assertArrayHasKey(5, $options); $this->assertInstanceOf(TextConfigOption::class, $options[5]); - $this->assertEquals('page-cache-redis-password', $options[5]->getName()); + $this->assertEquals('page-cache-redis-compress-data', $options[5]->getName()); $this->assertArrayHasKey(6, $options); $this->assertInstanceOf(TextConfigOption::class, $options[6]); - $this->assertEquals('page-cache-id-prefix', $options[6]->getName()); + $this->assertEquals('page-cache-redis-compression-library', $options[6]->getName()); + + $this->assertArrayHasKey(7, $options); + $this->assertInstanceOf(TextConfigOption::class, $options[7]); + $this->assertEquals('page-cache-id-prefix', $options[7]->getName()); + } /** @@ -93,7 +98,8 @@ public function testCreateConfigWithRedis() 'port' => '', 'database' => '', 'compress_data' => '', - 'password' => '' + 'password' => '', + 'compression_library' => '', ], 'id_prefix' => $this->expectedIdPrefix(), ] @@ -120,8 +126,9 @@ public function testCreateConfigWithRedisConfiguration() 'server' => 'foo.bar', 'port' => '9000', 'database' => '6', + 'password' => '', 'compress_data' => '1', - 'password' => '' + 'compression_library' => 'gzip', ], 'id_prefix' => $this->expectedIdPrefix(), ] @@ -134,7 +141,8 @@ public function testCreateConfigWithRedisConfiguration() 'page-cache-redis-server' => 'foo.bar', 'page-cache-redis-port' => '9000', 'page-cache-redis-db' => '6', - 'page-cache-redis-compress-data' => '1' + 'page-cache-redis-compress-data' => '1', + 'page-cache-redis-compression-library' => 'gzip', ]; $configData = $this->configList->createConfig($options, $this->deploymentConfigMock); From dd913cf0aab0fe3edc4aa95722b2a1113b8b2470 Mon Sep 17 00:00:00 2001 From: "colin.macdonald" Date: Fri, 8 Feb 2019 14:46:13 +1100 Subject: [PATCH 13/38] Allowing compression by default (previous, standard behaviour). Cleaning up test count. --- setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php | 4 ++-- .../Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php | 4 ++-- .../Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php index eb1b30093a670..9f822d6dd5d37 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php @@ -48,7 +48,7 @@ class Cache implements ConfigOptionsListInterface self::INPUT_KEY_CACHE_BACKEND_REDIS_DATABASE => '0', self::INPUT_KEY_CACHE_BACKEND_REDIS_PORT => '6379', self::INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD => '', - self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA => '0', + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA => '1', self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY => '', ]; @@ -127,7 +127,7 @@ public function getOptions() self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA, TextConfigOption::FRONTEND_WIZARD_TEXT, self::CONFIG_PATH_CACHE_BACKEND_COMPRESS_DATA, - 'Set to 1 to compress the cache (use 0 to disable)' + 'Set to 0 to disable compression (default is 1, enabled)' ), new TextConfigOption( self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY, diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php index f4d8136e85270..e9a0cf27c0110 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php @@ -45,7 +45,7 @@ protected function setUp() public function testGetOptions() { $options = $this->configOptionsList->getOptions(); - $this->assertCount(6, $options); + $this->assertCount(8, $options); $this->assertArrayHasKey(0, $options); $this->assertInstanceOf(SelectConfigOption::class, $options[0]); @@ -98,7 +98,7 @@ public function testCreateConfigCacheRedis() 'port' => '', 'database' => '', 'password' => '', - 'compress_data' => '0', + 'compress_data' => '1', 'compression_library' => '', ], 'id_prefix' => $this->expectedIdPrefix(), diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php index f0a68d213d407..8fc30ce5ea64b 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php @@ -45,7 +45,7 @@ protected function setUp() public function testGetOptions() { $options = $this->configList->getOptions(); - $this->assertCount(7, $options); + $this->assertCount(8, $options); $this->assertArrayHasKey(0, $options); $this->assertInstanceOf(SelectConfigOption::class, $options[0]); From 68623a9cf84169d7826d7ef6d4619a3826121086 Mon Sep 17 00:00:00 2001 From: "colin.macdonald" Date: Fri, 8 Feb 2019 14:51:01 +1100 Subject: [PATCH 14/38] cleaning expected blank config test struct --- .../Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php index e9a0cf27c0110..d3c3a10f6bd68 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php @@ -98,7 +98,7 @@ public function testCreateConfigCacheRedis() 'port' => '', 'database' => '', 'password' => '', - 'compress_data' => '1', + 'compress_data' => '', 'compression_library' => '', ], 'id_prefix' => $this->expectedIdPrefix(), From eb213d86ca8281d5ff6a8a526c936b514f379122 Mon Sep 17 00:00:00 2001 From: "colin.macdonald" Date: Fri, 8 Feb 2019 15:00:22 +1100 Subject: [PATCH 15/38] cm/redis listens for compression_lib - be consistent --- .../Setup/Model/ConfigOptionsList/Cache.php | 14 +++++++------- .../Setup/Model/ConfigOptionsList/PageCache.php | 12 ++++++------ .../Unit/Model/ConfigOptionsList/CacheTest.php | 8 ++++---- .../Unit/Model/ConfigOptionsList/PageCacheTest.php | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php index 9f822d6dd5d37..89a37429c47c9 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php @@ -28,7 +28,7 @@ class Cache implements ConfigOptionsListInterface const INPUT_KEY_CACHE_BACKEND_REDIS_PORT = 'cache-backend-redis-port'; const INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD = 'cache-backend-redis-password'; const INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA = 'cache-backend-redis-compress-data'; - const INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY = 'cache-backend-redis-compression-library'; + const INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIB = 'cache-backend-redis-compression-lib'; const INPUT_KEY_CACHE_ID_PREFIX = 'cache-id-prefix'; const CONFIG_PATH_CACHE_BACKEND = 'cache/frontend/default/backend'; @@ -37,7 +37,7 @@ class Cache implements ConfigOptionsListInterface const CONFIG_PATH_CACHE_BACKEND_PORT = 'cache/frontend/default/backend_options/port'; const CONFIG_PATH_CACHE_BACKEND_PASSWORD = 'cache/frontend/default/backend_options/password'; const CONFIG_PATH_CACHE_BACKEND_COMPRESS_DATA = 'cache/frontend/default/backend_options/compress_data'; - const CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIBRARY = 'cache/frontend/default/backend_options/compression_library'; + const CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIB = 'cache/frontend/default/backend_options/compression_lib'; const CONFIG_PATH_CACHE_ID_PREFIX = 'cache/frontend/default/id_prefix'; /** @@ -49,7 +49,7 @@ class Cache implements ConfigOptionsListInterface self::INPUT_KEY_CACHE_BACKEND_REDIS_PORT => '6379', self::INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD => '', self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA => '1', - self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY => '', + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIB => '', ]; /** @@ -68,7 +68,7 @@ class Cache implements ConfigOptionsListInterface self::INPUT_KEY_CACHE_BACKEND_REDIS_PORT => self::CONFIG_PATH_CACHE_BACKEND_PORT, self::INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD => self::CONFIG_PATH_CACHE_BACKEND_PASSWORD, self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA => self::CONFIG_PATH_CACHE_BACKEND_COMPRESS_DATA, - self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY => self::CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIBRARY, + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIB => self::CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIB, ]; /** @@ -130,10 +130,10 @@ public function getOptions() 'Set to 0 to disable compression (default is 1, enabled)' ), new TextConfigOption( - self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY, + self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIB, TextConfigOption::FRONTEND_WIZARD_TEXT, - self::CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIBRARY, - 'Compression library to use [snappy,lzf,l4z,zstd,gzip] (leave blank to determine automatically)' + self::CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIB, + 'Compression lib to use [snappy,lzf,l4z,zstd,gzip] (leave blank to determine automatically)' ), new TextConfigOption( self::INPUT_KEY_CACHE_ID_PREFIX, diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php index 57912cb117c2a..01c8b5ff10e05 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php @@ -28,7 +28,7 @@ class PageCache implements ConfigOptionsListInterface const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PORT = 'page-cache-redis-port'; const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD = 'page-cache-redis-password'; const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA = 'page-cache-redis-compress-data'; - const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY = 'page-cache-redis-compression-library'; + const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIB = 'page-cache-redis-compression-lib'; const INPUT_KEY_PAGE_CACHE_ID_PREFIX = 'page-cache-id-prefix'; const CONFIG_PATH_PAGE_CACHE_BACKEND = 'cache/frontend/page_cache/backend'; @@ -37,7 +37,7 @@ class PageCache implements ConfigOptionsListInterface const CONFIG_PATH_PAGE_CACHE_BACKEND_PORT = 'cache/frontend/page_cache/backend_options/port'; const CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD = 'cache/frontend/page_cache/backend_options/password'; const CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESS_DATA = 'cache/frontend/page_cache/backend_options/compress_data'; - const CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIBRARY = 'cache/frontend/page_cache/backend_options/compression_library'; + const CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIB = 'cache/frontend/page_cache/backend_options/compression_lib'; const CONFIG_PATH_PAGE_CACHE_ID_PREFIX = 'cache/frontend/page_cache/id_prefix'; /** @@ -49,7 +49,7 @@ class PageCache implements ConfigOptionsListInterface self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PORT => '6379', self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD => '', self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA => '0', - self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY => '', + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIB => '', ]; /** @@ -68,7 +68,7 @@ class PageCache implements ConfigOptionsListInterface self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PORT => self::CONFIG_PATH_PAGE_CACHE_BACKEND_PORT, self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD => self::CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD, self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA => self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESS_DATA, - self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY => self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIBRARY, + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIB => self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIB, ]; /** @@ -130,9 +130,9 @@ public function getOptions() 'Set to 1 to compress the full page cache (use 0 to disable)' ), new TextConfigOption( - self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIBRARY, + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIB, TextConfigOption::FRONTEND_WIZARD_TEXT, - self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIBRARY, + self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIB, 'Compression library to use [snappy,lzf,l4z,zstd,gzip] (leave blank to determine automatically)' ), new TextConfigOption( diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php index d3c3a10f6bd68..e7d1099884d7d 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php @@ -73,7 +73,7 @@ public function testGetOptions() $this->assertArrayHasKey(6, $options); $this->assertInstanceOf(TextConfigOption::class, $options[7]); - $this->assertEquals('cache-backend-redis-compression-library', $options[7]->getName()); + $this->assertEquals('cache-backend-redis-compression-lib', $options[7]->getName()); $this->assertArrayHasKey(7, $options); $this->assertInstanceOf(TextConfigOption::class, $options[5]); @@ -99,7 +99,7 @@ public function testCreateConfigCacheRedis() 'database' => '', 'password' => '', 'compress_data' => '', - 'compression_library' => '', + 'compression_lib' => '', ], 'id_prefix' => $this->expectedIdPrefix(), ] @@ -128,7 +128,7 @@ public function testCreateConfigWithRedisConfig() 'database' => '5', 'password' => '', 'compress_data' => '1', - 'compression_library' => 'gzip', + 'compression_lib' => 'gzip', ], 'id_prefix' => $this->expectedIdPrefix(), ] @@ -142,7 +142,7 @@ public function testCreateConfigWithRedisConfig() 'cache-backend-redis-port' => '1234', 'cache-backend-redis-db' => '5', 'cache-backend-redis-compress-data' => '1', - 'cache-backend-redis-compression-library' => 'gzip' + 'cache-backend-redis-compression-lib' => 'gzip' ]; $configData = $this->configOptionsList->createConfig($options, $this->deploymentConfigMock); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php index 8fc30ce5ea64b..2b96be2deee23 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php @@ -73,7 +73,7 @@ public function testGetOptions() $this->assertArrayHasKey(6, $options); $this->assertInstanceOf(TextConfigOption::class, $options[6]); - $this->assertEquals('page-cache-redis-compression-library', $options[6]->getName()); + $this->assertEquals('page-cache-redis-compression-lib', $options[6]->getName()); $this->assertArrayHasKey(7, $options); $this->assertInstanceOf(TextConfigOption::class, $options[7]); @@ -99,7 +99,7 @@ public function testCreateConfigWithRedis() 'database' => '', 'compress_data' => '', 'password' => '', - 'compression_library' => '', + 'compression_lib' => '', ], 'id_prefix' => $this->expectedIdPrefix(), ] @@ -128,7 +128,7 @@ public function testCreateConfigWithRedisConfiguration() 'database' => '6', 'password' => '', 'compress_data' => '1', - 'compression_library' => 'gzip', + 'compression_lib' => 'gzip', ], 'id_prefix' => $this->expectedIdPrefix(), ] @@ -142,7 +142,7 @@ public function testCreateConfigWithRedisConfiguration() 'page-cache-redis-port' => '9000', 'page-cache-redis-db' => '6', 'page-cache-redis-compress-data' => '1', - 'page-cache-redis-compression-library' => 'gzip', + 'page-cache-redis-compression-lib' => 'gzip', ]; $configData = $this->configList->createConfig($options, $this->deploymentConfigMock); From 589bcb2bb238e0a3a60350f0c069c2a57f290ff6 Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Fri, 8 Feb 2019 11:45:11 +0100 Subject: [PATCH 16/38] refactored retrieval of entity ID --- app/code/Magento/Ui/Component/Form.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/Component/Form.php b/app/code/Magento/Ui/Component/Form.php index 4033abba820e0..b560097e490e0 100644 --- a/app/code/Magento/Ui/Component/Form.php +++ b/app/code/Magento/Ui/Component/Form.php @@ -60,7 +60,8 @@ public function getDataSourceData() $dataSource = []; $id = $this->getContext()->getRequestParam($this->getContext()->getDataProvider()->getRequestFieldName(), null); - $filter = $this->filterBuilder->setField($this->getContext()->getDataProvider()->getPrimaryFieldName()) + $idFieldName = $this->getContext()->getDataProvider()->getPrimaryFieldName(); + $filter = $this->filterBuilder->setField($idFieldName) ->setValue($id) ->create(); $this->getContext()->getDataProvider() @@ -74,7 +75,7 @@ public function getDataSourceData() ]; } elseif (isset($data['items'])) { foreach ($data['items'] as $item) { - if ($item[$item['id_field_name']] == $id) { + if ($item[$idFieldName] == $id) { $dataSource = ['data' => ['general' => $item]]; } } From ce6dee1833114fa788f90bc260fcb6d426076714 Mon Sep 17 00:00:00 2001 From: "colin.macdonald" Date: Mon, 11 Feb 2019 10:56:17 +1100 Subject: [PATCH 17/38] Correct options ordering in assertions --- .../Test/Unit/Model/ConfigOptionsList/CacheTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php index e7d1099884d7d..b3c88930c948a 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php @@ -68,16 +68,16 @@ public function testGetOptions() $this->assertEquals('cache-backend-redis-password', $options[4]->getName()); $this->assertArrayHasKey(5, $options); - $this->assertInstanceOf(TextConfigOption::class, $options[6]); - $this->assertEquals('cache-backend-redis-compress-data', $options[6]->getName()); + $this->assertInstanceOf(TextConfigOption::class, $options[5]); + $this->assertEquals('cache-backend-redis-compress-data', $options[5]->getName()); $this->assertArrayHasKey(6, $options); - $this->assertInstanceOf(TextConfigOption::class, $options[7]); - $this->assertEquals('cache-backend-redis-compression-lib', $options[7]->getName()); + $this->assertInstanceOf(TextConfigOption::class, $options[6]); + $this->assertEquals('cache-backend-redis-compression-lib', $options[6]->getName()); $this->assertArrayHasKey(7, $options); - $this->assertInstanceOf(TextConfigOption::class, $options[5]); - $this->assertEquals('cache-id-prefix', $options[5]->getName()); + $this->assertInstanceOf(TextConfigOption::class, $options[7]); + $this->assertEquals('cache-id-prefix', $options[7]->getName()); } From ac40d43e4a51ad235b4817d09f28cb50869c13a1 Mon Sep 17 00:00:00 2001 From: Wojtek Naruniec Date: Mon, 11 Feb 2019 13:45:13 +0100 Subject: [PATCH 18/38] Add missing attributes initialization to avoid throwing foreach error --- app/code/Magento/Eav/Model/Form.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Eav/Model/Form.php b/app/code/Magento/Eav/Model/Form.php index c8c50521f5509..1d867109aaf38 100644 --- a/app/code/Magento/Eav/Model/Form.php +++ b/app/code/Magento/Eav/Model/Form.php @@ -323,6 +323,8 @@ public function getAttributes() if ($this->_attributes === null) { $this->_attributes = []; $this->_userAttributes = []; + $this->_systemAttributes = []; + $this->_allowedAttributes = []; /** @var $attribute \Magento\Eav\Model\Attribute */ foreach ($this->_getFilteredFormAttributeCollection() as $attribute) { $this->_attributes[$attribute->getAttributeCode()] = $attribute; From 50b78da7822d922b5b39e3f76790e91cfb8c9e04 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Wed, 13 Feb 2019 15:01:11 +0200 Subject: [PATCH 19/38] Refactoring the validator usage. Updating the Unit/Integration tests. Covering the new validator class by Unit Test --- .../Adminhtml/Product/Attribute/Save.php | 38 ------- .../Adminhtml/Product/Attribute/Validate.php | 18 ++- .../Adminhtml/Product/Attribute/SaveTest.php | 14 +++ .../Product/Attribute/ValidateTest.php | 107 ++++++++++++++++++ .../Magento/Eav/Model/Entity/Attribute.php | 7 +- .../Eav/Model/Validator/Attribute/Code.php | 30 +++-- app/code/Magento/Eav/Setup/EavSetup.php | 23 ++-- .../Model/Validator/Attribute/CodeTest.php | 67 +++++++++++ app/code/Magento/Ui/i18n/en_US.csv | 1 + .../Adminhtml/Product/AttributeTest.php | 2 +- .../Magento/Eav/Setup/EavSetupTest.php | 2 +- 11 files changed, 238 insertions(+), 71 deletions(-) create mode 100644 app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/CodeTest.php diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index 78a25567eb195..853cc65270306 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -195,44 +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) { - $attributeCodeIsValid = true; - $minLength = \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MIN_LENGTH; - $maxLength = \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH; - - if (strlen($attributeCode) < $minLength || strlen($attributeCode) > $maxLength) { - $this->messageManager->addErrorMessage( - __( - 'An attribute code must not be less than %1 and more than %2 characters.', - $minLength, - $maxLength - ) - ); - $attributeCodeIsValid = false; - } - - $validatorAttrCode = new \Zend_Validate_Regex( - ['pattern' => '/^[a-zA-Z]+[a-zA-Z0-9_]*$/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 - ) - ); - $attributeCodeIsValid = false; - } - - if (!$attributeCodeIsValid) { - return $this->returnResult( - 'catalog/*/edit', - ['attribute_id' => $attributeId, '_current' => true], - ['error' => true] - ); - } - } $data['attribute_code'] = $attributeCode; //validate frontend_input diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php index 50f58efae7127..02c12ad185ee8 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -7,6 +7,7 @@ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; +use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator; use Magento\Framework\Serialize\Serializer\FormData; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; @@ -43,6 +44,11 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo */ private $formDataSerializer; + /** + * @var AttributeCodeValidator + */ + private $attributeCodeValidator; + /** * Constructor * @@ -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, @@ -63,7 +70,8 @@ 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; @@ -71,6 +79,8 @@ public function __construct( $this->multipleAttributeList = $multipleAttributeList; $this->formDataSerializer = $formDataSerializer ?: ObjectManager::getInstance() ->get(FormData::class); + $this->attributeCodeValidator = $attributeCodeValidator ?: ObjectManager::getInstance()->get( + AttributeCodeValidator::class); } /** @@ -115,6 +125,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 */ diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php index ced65b2d2e15d..30d3503e4640e 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php @@ -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; @@ -94,6 +95,11 @@ class SaveTest extends AttributeTest */ private $productAttributeMock; + /** + * @var AttributeCodeValidator|\PHPUnit_Framework_MockObject_MockObject + */ + private $attributeCodeValidatorMock; + protected function setUp() { parent::setUp(); @@ -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(); @@ -171,6 +180,7 @@ protected function getModel() 'groupCollectionFactory' => $this->groupCollectionFactoryMock, 'layoutFactory' => $this->layoutFactoryMock, 'formDataSerializer' => $this->formDataSerializerMock, + 'attributeCodeValidator' => $this->attributeCodeValidatorMock ]); } @@ -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); diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php index c6210f93e1290..742148b1bf7f1 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php @@ -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; @@ -67,6 +68,11 @@ class ValidateTest extends AttributeTest */ private $formDataSerializerMock; + /** + * @var AttributeCodeValidator|\PHPUnit_Framework_MockObject_MockObject + */ + private $attributeCodeValidatorMock; + protected function setUp() { parent::setUp(); @@ -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') @@ -117,6 +126,7 @@ protected function getModel() 'layoutFactory' => $this->layoutFactoryMock, 'multipleAttributeList' => ['select' => 'option'], 'formDataSerializer' => $this->formDataSerializerMock, + 'attributeCodeValidator' => $this->attributeCodeValidatorMock, ] ); } @@ -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') @@ -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); @@ -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); @@ -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(); @@ -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.', + ] + ] + ]; + } } diff --git a/app/code/Magento/Eav/Model/Entity/Attribute.php b/app/code/Magento/Eav/Model/Entity/Attribute.php index 38e47cc98a524..4924b65896421 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute.php @@ -242,8 +242,11 @@ public function loadEntityAttributeIdBySet() */ public function beforeSave() { - if (isset($this->_data['attribute_code'])) { - $this->attributeCodeValidator->isValid($this->_data['attribute_code']); + if (isset($this->_data['attribute_code']) + && !$this->attributeCodeValidator->isValid($this->_data['attribute_code']) + ) { + $errorMessages = implode("\n", $this->attributeCodeValidator->getMessages()); + throw new LocalizedException(__($errorMessages)); } // prevent overriding product data diff --git a/app/code/Magento/Eav/Model/Validator/Attribute/Code.php b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php index 578816bc99abd..f3ee37721b8ce 100644 --- a/app/code/Magento/Eav/Model/Validator/Attribute/Code.php +++ b/app/code/Magento/Eav/Model/Validator/Attribute/Code.php @@ -17,29 +17,33 @@ * * Validation EAV attribute code */ -class Code extends AbstractValidator +class Code extends AbstractValidator { + /** + * Validation pattern for attribute code + */ + const VALIDATION_RULE_PATTERN = '/^[a-zA-Z]+[a-zA-Z0-9_]*$/u'; + /** * Validates the correctness of the attribute code * * @param string $attributeCode * @return bool - * @throws LocalizedException + * @throws \Zend_Validate_Exception */ public function isValid($attributeCode): bool { + $errorMessages = []; /** * Check attribute_code for allowed characters */ if (trim($attributeCode) - && !preg_match('/^[a-zA-Z]+[a-zA-Z0-9_]*$/', trim($attributeCode)) + && !preg_match(self::VALIDATION_RULE_PATTERN, trim($attributeCode)) ) { - throw new LocalizedException( - __( - 'Attribute code "%1" is invalid. Please use only letters (a-z), ' . - 'numbers (0-9) or underscore(_) in this field, first character should be a letter.', - $attributeCode - ) + $errorMessages[] = __( + 'Attribute code "%1" is invalid. Please use only letters (a-z or A-Z), ' . + 'numbers (0-9) or underscore (_) in this field, and the first character should be a letter.', + $attributeCode ); } @@ -54,13 +58,15 @@ public function isValid($attributeCode): bool ['min' => $minLength, 'max' => $maxLength] ); if (!$isAllowedLength) { - throw new LocalizedException(__( + $errorMessages[] = __( 'An attribute code must not be less than %1 and more than %2 characters.', $minLength, $maxLength - )); + ); } - return true; + $this->_addMessages($errorMessages); + + return !$this->hasMessages(); } } diff --git a/app/code/Magento/Eav/Setup/EavSetup.php b/app/code/Magento/Eav/Setup/EavSetup.php index 77fd0e95de364..221c1a9a7de77 100644 --- a/app/code/Magento/Eav/Setup/EavSetup.php +++ b/app/code/Magento/Eav/Setup/EavSetup.php @@ -785,21 +785,6 @@ private function _getValue($array, $key, $default = null) return isset($array[$key]) ? $array[$key] : $default; } - /** - * Validate attribute data before insert into table - * - * @param array $data - * @return true - * @throws LocalizedException - */ - private function _validateAttributeData($data) - { - $attributeCode = isset($data['attribute_code']) ? $data['attribute_code'] : ''; - $this->attributeCodeValidator->isValid($attributeCode); - - return true; - } - /** * Add attribute to an entity type * @@ -809,6 +794,7 @@ private function _validateAttributeData($data) * @param string $code * @param array $attr * @return $this + * @throws LocalizedException */ public function addAttribute($entityTypeId, $code, array $attr) { @@ -819,7 +805,12 @@ public function addAttribute($entityTypeId, $code, array $attr) $this->attributeMapper->map($attr, $entityTypeId) ); - $this->_validateAttributeData($data); + $attributeCode = isset($data['attribute_code']) ? $data['attribute_code'] : ''; + if (!$this->attributeCodeValidator->isValid($attributeCode)) { + $errorMessage = implode("\n", $this->attributeCodeValidator->getMessages()); + + throw new LocalizedException(__($errorMessage)); + } $sortOrder = isset($attr['sort_order']) ? $attr['sort_order'] : null; $attributeId = $this->getAttribute($entityTypeId, $code, 'attribute_id'); diff --git a/app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/CodeTest.php b/app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/CodeTest.php new file mode 100644 index 0000000000000..9db290bcba3e1 --- /dev/null +++ b/app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/CodeTest.php @@ -0,0 +1,67 @@ +assertEquals($expected, $validator->isValid($attributeCode)); + } + + /** + * Data provider for testIsValid + * + * @return array + */ + public function isValidDataProvider(): array + { + return [ + [ + 'Attribute_code', + true + ], [ + 'attribute_1', + true + ],[ + 'Attribute_1', + true + ], [ + '_attribute_code', + false + ], [ + 'attribute.code', + false + ], [ + '1attribute_code', + false + ], [ + 'more_than_60_chars_more_than_60_chars_more_than_60_chars_more', + false + ] + ]; + } +} diff --git a/app/code/Magento/Ui/i18n/en_US.csv b/app/code/Magento/Ui/i18n/en_US.csv index d51ff98108376..d8021c3aa8087 100644 --- a/app/code/Magento/Ui/i18n/en_US.csv +++ b/app/code/Magento/Ui/i18n/en_US.csv @@ -78,6 +78,7 @@ Keyword,Keyword "Empty Value.","Empty Value." "Please use only letters (a-z or A-Z), numbers (0-9) or spaces only in this field.","Please use only letters (a-z or A-Z), numbers (0-9) or spaces only in this field." "Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in this field, and the first character should be a letter.","Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in this field, and the first character should be a letter." +"Attribute code ""%1"" is invalid. Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in this field, and the first character should be a letter.","Attribute code ""%1"" is invalid. Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in this field, and the first character should be a letter." "Please use only letters (a-z or A-Z), numbers (0-9), spaces and ""#"" in this field.","Please use only letters (a-z or A-Z), numbers (0-9), spaces and ""#"" in this field." "Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.","Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890." "Please enter a valid fax number (Ex: 123-456-7890).","Please enter a valid fax number (Ex: 123-456-7890)." diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php index fe08ec01a9715..e1d3e960593a9 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php @@ -157,7 +157,7 @@ public function testWrongAttributeCode() $message = $messages->getItemsByType('error')[0]; $this->assertEquals( 'Attribute code "_()&&&?" 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.', + . ' numbers (0-9) or underscore (_) in this field, and the first character should be a letter.', $message->getText() ); } diff --git a/dev/tests/integration/testsuite/Magento/Eav/Setup/EavSetupTest.php b/dev/tests/integration/testsuite/Magento/Eav/Setup/EavSetupTest.php index 3e8e146144c36..a5843f20ad98a 100644 --- a/dev/tests/integration/testsuite/Magento/Eav/Setup/EavSetupTest.php +++ b/dev/tests/integration/testsuite/Magento/Eav/Setup/EavSetupTest.php @@ -97,7 +97,7 @@ public function addAttributeThrowExceptionDataProvider() * * @dataProvider addInvalidAttributeThrowExceptionDataProvider * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first char + * @expectedExceptionMessage Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in this field, */ public function testAddInvalidAttributeThrowException($attributeCode) { From a8f17290363aa157eb1ec77984b3df2201a97ea9 Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Sat, 15 Sep 2018 15:23:08 +0200 Subject: [PATCH 20/38] Fixes variables in configuration not being replaced with actual values in the backend form fields. --- app/code/Magento/Config/Block/System/Config/Form.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Config/Block/System/Config/Form.php b/app/code/Magento/Config/Block/System/Config/Form.php index 2a29fa33feb74..8378c058c1955 100644 --- a/app/code/Magento/Config/Block/System/Config/Form.php +++ b/app/code/Magento/Config/Block/System/Config/Form.php @@ -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()) From 767c86c9fd55649da52bfc267dea45ed09c38dff Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Thu, 21 Feb 2019 09:44:12 +0100 Subject: [PATCH 21/38] implemented UI component form test for usage with AbstractDataProvider Signed-off-by: Simon Sprankel --- .../Ui/Test/Unit/Component/FormTest.php | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/Test/Unit/Component/FormTest.php b/app/code/Magento/Ui/Test/Unit/Component/FormTest.php index 6951583291df9..6df69c7d0e48d 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/FormTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/FormTest.php @@ -9,7 +9,6 @@ use Magento\Framework\Api\FilterBuilder; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface; -use Magento\Framework\View\Element\UiComponent\Processor; use Magento\Ui\Component\Form; class FormTest extends \PHPUnit\Framework\TestCase @@ -215,4 +214,65 @@ public function testGetDataSourceDataWithoutId() $this->assertEquals($dataSource, $this->model->getDataSourceData()); } + + public function testGetDataSourceDataWithAbstractDataProvider() + { + $requestFieldName = 'request_id'; + $primaryFieldName = 'primary_id'; + $fieldId = 44; + $row = ['key' => 'value', $primaryFieldName => $fieldId]; + $data = [ + 'items' => [$row], + ]; + $dataSource = [ + 'data' => [ + 'general' => $row + ], + ]; + + /** @var DataProviderInterface|\PHPUnit_Framework_MockObject_MockObject $dataProviderMock */ + $dataProviderMock = + $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface::class) + ->getMock(); + $dataProviderMock->expects($this->once()) + ->method('getRequestFieldName') + ->willReturn($requestFieldName); + $dataProviderMock->expects($this->once()) + ->method('getPrimaryFieldName') + ->willReturn($primaryFieldName); + + $this->contextMock->expects($this->any()) + ->method('getDataProvider') + ->willReturn($dataProviderMock); + $this->contextMock->expects($this->once()) + ->method('getRequestParam') + ->with($requestFieldName) + ->willReturn($fieldId); + + /** @var Filter|\PHPUnit_Framework_MockObject_MockObject $filterMock */ + $filterMock = $this->getMockBuilder(\Magento\Framework\Api\Filter::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->filterBuilderMock->expects($this->once()) + ->method('setField') + ->with($primaryFieldName) + ->willReturnSelf(); + $this->filterBuilderMock->expects($this->once()) + ->method('setValue') + ->with($fieldId) + ->willReturnSelf(); + $this->filterBuilderMock->expects($this->once()) + ->method('create') + ->willReturn($filterMock); + + $dataProviderMock->expects($this->once()) + ->method('addFilter') + ->with($filterMock); + $dataProviderMock->expects($this->once()) + ->method('getData') + ->willReturn($data); + + $this->assertEquals($dataSource, $this->model->getDataSourceData()); + } } From 0c7218b9889af1b11bba56fb8e0e0b6958ea4409 Mon Sep 17 00:00:00 2001 From: Oleksandr Kravchuk Date: Fri, 22 Feb 2019 10:43:48 +0200 Subject: [PATCH 22/38] Fix static tests --- app/code/Magento/Ui/Component/Form.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/Component/Form.php b/app/code/Magento/Ui/Component/Form.php index b560097e490e0..dc6e7b5ca06ab 100644 --- a/app/code/Magento/Ui/Component/Form.php +++ b/app/code/Magento/Ui/Component/Form.php @@ -10,6 +10,7 @@ use Magento\Framework\View\Element\UiComponentInterface; /** + * Ui component Form * @api * @since 100.0.2 */ @@ -53,7 +54,7 @@ public function getComponentName() } /** - * {@inheritdoc} + * @inheritdoc */ public function getDataSourceData() { From 18a590fb52d1268d3db1c5348805a629bf6b28e4 Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Tue, 26 Feb 2019 22:55:47 +0100 Subject: [PATCH 23/38] Allow module data fixtures for @magentoDataFixtureBeforeTransaction annotations Extend the option to specify a module based data fixture files to the @magentoDataFixtureBeforeTransaction annotation. Previously they where only available for the @magentoDataFixture annotation. The syntax is the same: @magentoDataFixtureBeforeAnnotation Foo_DataFixtureDummy::Test/Integration/foo.php There is no backward compatibility break associated with this commit. --- .../TestFramework/Annotation/DataFixture.php | 11 ++---- .../DataFixtureBeforeTransaction.php | 39 ++++++++++++++++++- .../Test/Annotation/DataFixtureTest.php | 14 +++++++ 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php index f0ee8c7b3c2bb..ddebbf37b16d1 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php @@ -158,14 +158,9 @@ private function isModuleAnnotation(string $fixture) */ private function getModulePath(string $fixture) { - $fixturePathParts = explode('::', $fixture, 2); - $moduleName = $fixturePathParts[0]; - $fixtureFile = $fixturePathParts[1]; + [$moduleName, $fixtureFile] = explode('::', $fixture, 2); - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - /** @var ComponentRegistrar $componentRegistrar */ - $componentRegistrar = $objectManager->get(ComponentRegistrar::class); - $modulePath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); + $modulePath = (new ComponentRegistrar())->getPath(ComponentRegistrar::MODULE, $moduleName); if ($modulePath === null) { throw new \Magento\Framework\Exception\LocalizedException( @@ -173,7 +168,7 @@ private function getModulePath(string $fixture) ); } - return $modulePath . '/' . $fixtureFile; + return $modulePath . '/' . ltrim($fixtureFile, '/'); } /** diff --git a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixtureBeforeTransaction.php b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixtureBeforeTransaction.php index db7f57362d807..0d4f652823c45 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixtureBeforeTransaction.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixtureBeforeTransaction.php @@ -5,10 +5,11 @@ */ /** - * Implementation of the @magentoDataFixture DocBlock annotation + * Implementation of the @magentoDataFixtureBeforeTransaction DocBlock annotation */ namespace Magento\TestFramework\Annotation; +use Magento\Framework\Component\ComponentRegistrar; use PHPUnit\Framework\Exception; class DataFixtureBeforeTransaction @@ -93,6 +94,8 @@ protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope = null $fixtureMethod = [get_class($test), $fixture]; if (is_callable($fixtureMethod)) { $result[] = $fixtureMethod; + } elseif ($this->isModuleAnnotation($fixture)) { + $result[] = $this->getModulePath($fixture); } else { $result[] = $this->_fixtureBaseDir . '/' . $fixture; } @@ -101,6 +104,40 @@ protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope = null return $result; } + /** + * Check is the Annotation like Magento_InventoryApi::Test/_files/products.php + * + * @param string $fixture + * @return bool + */ + private function isModuleAnnotation(string $fixture) + { + return (strpos($fixture, '::') !== false); + } + + /** + * Resolve the Fixture + * + * @param string $fixture + * @return string + * @throws \Magento\Framework\Exception\LocalizedException + * @SuppressWarnings(PHPMD.StaticAccess) + */ + private function getModulePath(string $fixture) + { + [$moduleName, $fixtureFile] = explode('::', $fixture, 2); + + $modulePath = (new ComponentRegistrar())->getPath(ComponentRegistrar::MODULE, $moduleName); + + if ($modulePath === null) { + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Can\'t find registered Module with name %1 .', [$moduleName]) + ); + } + + return $modulePath . '/' . ltrim($fixtureFile, '/'); + } + /** * @param \PHPUnit\Framework\TestCase $test * @return array diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DataFixtureTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DataFixtureTest.php index 22240ad8e1fe9..00af4419e1142 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DataFixtureTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DataFixtureTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Test\Annotation; +use Magento\Framework\Component\ComponentRegistrar; + /** * Test class for \Magento\TestFramework\Annotation\DataFixture. * @@ -178,4 +180,16 @@ public function testRollbackTransactionRevertFixtureFile() ); $this->_object->rollbackTransaction(); } + + /** + * @magentoDataFixture Foo_DataFixtureDummy::Test/Integration/foo.php + * @SuppressWarnings(PHPMD.StaticAccess) + */ + public function testModuleDataFixture() + { + ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Foo_DataFixtureDummy', __DIR__); + $this->_object->expects($this->once())->method('_applyOneFixture') + ->with(__DIR__ . '/Test/Integration/foo.php'); + $this->_object->startTransaction($this); + } } From 005a57c9fd11d7b3f260c4be62c9c5ad595a860d Mon Sep 17 00:00:00 2001 From: wsajosh Date: Thu, 28 Feb 2019 14:56:54 +0000 Subject: [PATCH 24/38] SHQ18-1568 Updating UPS endpoint to use https. Http is no longer reliably returning rates --- app/code/Magento/Ups/Model/Carrier.php | 2 +- app/code/Magento/Ups/etc/config.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ups/Model/Carrier.php b/app/code/Magento/Ups/Model/Carrier.php index 8c60f5a53a2d9..75ce0c3014efa 100644 --- a/app/code/Magento/Ups/Model/Carrier.php +++ b/app/code/Magento/Ups/Model/Carrier.php @@ -77,7 +77,7 @@ class Carrier extends AbstractCarrierOnline implements CarrierInterface * * @var string */ - protected $_defaultCgiGatewayUrl = 'http://www.ups.com:80/using/services/rave/qcostcgi.cgi'; + protected $_defaultCgiGatewayUrl = 'https://www.ups.com:80/using/services/rave/qcostcgi.cgi'; /** * Test urls for shipment diff --git a/app/code/Magento/Ups/etc/config.xml b/app/code/Magento/Ups/etc/config.xml index e2ac1c6d6c443..791b325c65e3f 100644 --- a/app/code/Magento/Ups/etc/config.xml +++ b/app/code/Magento/Ups/etc/config.xml @@ -19,7 +19,7 @@ RES GND - http://www.ups.com/using/services/rave/qcostcgi.cgi + https://www.ups.com/using/services/rave/qcostcgi.cgi https://onlinetools.ups.com/ups.app/xml/Rate 0 Magento\Ups\Model\Carrier From ff94ee1739dc1f26b710aa74b7ffc8f87c987742 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Mon, 4 Mar 2019 10:07:27 +0000 Subject: [PATCH 25/38] Update app/code/Magento/Ups/Model/Carrier.php Co-Authored-By: wsajosh --- app/code/Magento/Ups/Model/Carrier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ups/Model/Carrier.php b/app/code/Magento/Ups/Model/Carrier.php index 75ce0c3014efa..9cb1fe615aa42 100644 --- a/app/code/Magento/Ups/Model/Carrier.php +++ b/app/code/Magento/Ups/Model/Carrier.php @@ -77,7 +77,7 @@ class Carrier extends AbstractCarrierOnline implements CarrierInterface * * @var string */ - protected $_defaultCgiGatewayUrl = 'https://www.ups.com:80/using/services/rave/qcostcgi.cgi'; + protected $_defaultCgiGatewayUrl = 'https://www.ups.com/using/services/rave/qcostcgi.cgi'; /** * Test urls for shipment From e1fa2898da686fcad88d0478f0f7e610cc0c6ce6 Mon Sep 17 00:00:00 2001 From: Scott Buchanan Date: Tue, 26 Feb 2019 12:49:36 -0500 Subject: [PATCH 26/38] populate labels for street lines in checkout --- app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php | 1 + .../Magento/blank/Magento_Customer/web/css/source/_module.less | 2 +- .../Magento/luma/Magento_Customer/web/css/source/_module.less | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php index a20c146d68d92..5dedf2c7e7eba 100644 --- a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php +++ b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php @@ -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 diff --git a/app/design/frontend/Magento/blank/Magento_Customer/web/css/source/_module.less b/app/design/frontend/Magento/blank/Magento_Customer/web/css/source/_module.less index 8cf5cd313edc5..54a7620b3c8c7 100644 --- a/app/design/frontend/Magento/blank/Magento_Customer/web/css/source/_module.less +++ b/app/design/frontend/Magento/blank/Magento_Customer/web/css/source/_module.less @@ -165,7 +165,7 @@ // Checkout address (create shipping address) .field.street { - .field.additional { + .field { .label { &:extend(.abs-visually-hidden all); } diff --git a/app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less b/app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less index 5b0f717ff15bc..3da7dd7411930 100755 --- a/app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less +++ b/app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less @@ -200,7 +200,7 @@ // Checkout address (create shipping address) .field.street { - .field.additional { + .field { .label { &:extend(.abs-visually-hidden all); } From 6af6d4021a9caeeb590ed21121e9f4427d8c7423 Mon Sep 17 00:00:00 2001 From: asim-vax Date: Thu, 14 Mar 2019 13:51:45 +0000 Subject: [PATCH 27/38] fixes sitemap checking for null, when is empty instead --- .../Magento/Sitemap/Model/ResourceModel/Catalog/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php index 82024b3b015e5..ebcc7b9bd62e8 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php @@ -324,7 +324,7 @@ public function getCollection($storeId) [] )->joinLeft( ['url_rewrite' => $this->getTable('url_rewrite')], - 'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1 AND url_rewrite.metadata IS ' + 'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1 AND NULLIF(url_rewrite.metadata,"") IS ' . $urlsConfigCondition . 'NULL' . $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId()) . $connection->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE), From ae6c8bcff2d8203f7e9b36dad790a90047827b84 Mon Sep 17 00:00:00 2001 From: vbmagento Date: Tue, 19 Mar 2019 10:58:24 +0000 Subject: [PATCH 28/38] Add argument to show filter text in URL rewrite grid after click on back button --- .../view/adminhtml/layout/adminhtml_url_rewrite_index.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml b/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml index 7d8151d270308..10f73829ada2c 100644 --- a/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml +++ b/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml @@ -14,6 +14,7 @@ urlrewriteGrid Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection url_rewrite_id + 1 From d85fd44346a024cd3f4f61f28dbd50a9ba8074a1 Mon Sep 17 00:00:00 2001 From: vbmagento Date: Wed, 20 Mar 2019 09:57:01 +0000 Subject: [PATCH 29/38] Add comment in xml file --- .../view/adminhtml/layout/adminhtml_url_rewrite_index.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml b/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml index 10f73829ada2c..e32397921a032 100644 --- a/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml +++ b/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml @@ -14,6 +14,7 @@ urlrewriteGrid Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection url_rewrite_id + 1 From f75b3e9eba8192fef0116d63832aa375b22a1848 Mon Sep 17 00:00:00 2001 From: Vaibhav Bhalerao Date: Wed, 20 Mar 2019 18:40:37 +0530 Subject: [PATCH 30/38] Update adminhtml_url_rewrite_index.xml Used spaces instead of tabs --- .../view/adminhtml/layout/adminhtml_url_rewrite_index.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml b/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml index e32397921a032..bae22d0a10385 100644 --- a/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml +++ b/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml @@ -14,8 +14,8 @@ urlrewriteGrid Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection url_rewrite_id - - 1 + + 1 From d5a61c01cec3429d9fb93c1a56b78a264b06ba45 Mon Sep 17 00:00:00 2001 From: Vaibhav Bhalerao Date: Wed, 20 Mar 2019 19:15:19 +0530 Subject: [PATCH 31/38] Update adminhtml_url_rewrite_index.xml --- .../view/adminhtml/layout/adminhtml_url_rewrite_index.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml b/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml index bae22d0a10385..de8575178d06d 100644 --- a/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml +++ b/app/code/Magento/UrlRewrite/view/adminhtml/layout/adminhtml_url_rewrite_index.xml @@ -14,8 +14,8 @@ urlrewriteGrid Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection url_rewrite_id - - 1 + + 1 From 337397a030102e3014e5f31182f0fde1a15c6b12 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Thu, 21 Mar 2019 16:21:36 +0200 Subject: [PATCH 32/38] ENGCOM-4267: Static tests fix. --- .../Magento/Setup/Model/ConfigOptionsList/PageCache.php | 9 +++++---- .../Test/Unit/Model/ConfigOptionsList/CacheTest.php | 1 - .../Test/Unit/Model/ConfigOptionsList/PageCacheTest.php | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php index 01c8b5ff10e05..65bfc650c0206 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php @@ -6,10 +6,10 @@ namespace Magento\Setup\Model\ConfigOptionsList; -use Magento\Framework\Setup\ConfigOptionsListInterface; -use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\Data\ConfigData; +use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\Setup\ConfigOptionsListInterface; use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; use Magento\Setup\Validator\RedisConnectionValidator; @@ -68,7 +68,8 @@ class PageCache implements ConfigOptionsListInterface self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PORT => self::CONFIG_PATH_PAGE_CACHE_BACKEND_PORT, self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD => self::CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD, self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA => self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESS_DATA, - self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIB => self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIB, + self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESSION_LIB => + self::CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESSION_LIB, ]; /** @@ -234,7 +235,7 @@ private function validateRedisConfig(array $options, DeploymentConfig $deploymen self::CONFIG_PATH_PAGE_CACHE_BACKEND_DATABASE, $this->getDefaultConfigValue(self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_DATABASE) ); - + $config['password'] = isset($options[self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD]) ? $options[self::INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD] : $deploymentConfig->get( diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php index b3c88930c948a..783c11e941eed 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php @@ -78,7 +78,6 @@ public function testGetOptions() $this->assertArrayHasKey(7, $options); $this->assertInstanceOf(TextConfigOption::class, $options[7]); $this->assertEquals('cache-id-prefix', $options[7]->getName()); - } /** diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php index 2b96be2deee23..673168fe2fffd 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php @@ -78,7 +78,6 @@ public function testGetOptions() $this->assertArrayHasKey(7, $options); $this->assertInstanceOf(TextConfigOption::class, $options[7]); $this->assertEquals('page-cache-id-prefix', $options[7]->getName()); - } /** From def3be9388834af9809f03f469d4d6fc10ad8d8d Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Mon, 25 Mar 2019 14:18:24 +0200 Subject: [PATCH 33/38] magento/magento2#21749: Static test fix. --- .../Sitemap/Model/ResourceModel/Catalog/Product.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php index ebcc7b9bd62e8..2e2e3cc1dcc5b 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php @@ -5,12 +5,12 @@ */ namespace Magento\Sitemap\Model\ResourceModel\Catalog; +use Magento\Catalog\Helper\Product as HelperProduct; use Magento\Catalog\Model\Product\Image\UrlBuilder; use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; -use Magento\Store\Model\Store; use Magento\Framework\App\ObjectManager; use Magento\Store\Model\ScopeInterface; -use Magento\Catalog\Helper\Product as HelperProduct; +use Magento\Store\Model\Store; /** * Sitemap resource product collection model @@ -259,7 +259,7 @@ protected function _joinAttribute($storeId, $attributeCode, $column = null) // Add attribute value to result set if needed if (isset($column)) { $this->_select->columns([ - $column => $columnValue + $column => $columnValue ]); } } @@ -282,7 +282,7 @@ protected function _getAttribute($attributeCode) 'attribute_id' => $attribute->getId(), 'table' => $attribute->getBackend()->getTable(), 'is_global' => $attribute->getIsGlobal() == - \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, 'backend_type' => $attribute->getBackendType(), ]; } @@ -324,7 +324,8 @@ public function getCollection($storeId) [] )->joinLeft( ['url_rewrite' => $this->getTable('url_rewrite')], - 'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1 AND NULLIF(url_rewrite.metadata,"") IS ' + 'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1 ' + . 'AND NULLIF(url_rewrite.metadata,"") IS ' . $urlsConfigCondition . 'NULL' . $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId()) . $connection->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE), From 059f399232fe51f54e0e8c16986bf99c6fecbc4d Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Tue, 26 Mar 2019 15:27:12 +0200 Subject: [PATCH 34/38] Fix static tests. --- app/code/Magento/Eav/Model/Form.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Eav/Model/Form.php b/app/code/Magento/Eav/Model/Form.php index 1d867109aaf38..a34b53eede354 100644 --- a/app/code/Magento/Eav/Model/Form.php +++ b/app/code/Magento/Eav/Model/Form.php @@ -286,7 +286,8 @@ public function getFormCode() } /** - * Return entity type instance + * Return entity type instance. + * * Return EAV entity type if entity type is not defined * * @return \Magento\Eav\Model\Entity\Type From 749551f939430907a95f0d72ac49ea20ad9a781f Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Wed, 27 Mar 2019 10:06:35 +0200 Subject: [PATCH 35/38] Fix static tests. --- .../Annotation/DataFixtureBeforeTransaction.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixtureBeforeTransaction.php b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixtureBeforeTransaction.php index 0d4f652823c45..ba23ecd13b6a7 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixtureBeforeTransaction.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixtureBeforeTransaction.php @@ -4,14 +4,14 @@ * See COPYING.txt for license details. */ -/** - * Implementation of the @magentoDataFixtureBeforeTransaction DocBlock annotation - */ namespace Magento\TestFramework\Annotation; use Magento\Framework\Component\ComponentRegistrar; use PHPUnit\Framework\Exception; +/** + * Implementation of the @magentoDataFixtureBeforeTransaction DocBlock annotation + */ class DataFixtureBeforeTransaction { /** @@ -139,6 +139,8 @@ private function getModulePath(string $fixture) } /** + * Get annotations for test. + * * @param \PHPUnit\Framework\TestCase $test * @return array */ From 48ea21df20d5edf1e460b7443b8f17dd0f0df2ba Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Wed, 27 Mar 2019 16:21:11 +0200 Subject: [PATCH 36/38] Fix static tests. --- .../Shipping/Model/Carrier/AbstractCarrier.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php index 628bc9c4295b0..76555ce8a6d8c 100644 --- a/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php +++ b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php @@ -160,7 +160,8 @@ public function getConfigFlag($field) } /** - * Do request to shipment + * Do request to shipment. + * * Implementation must be in overridden method * * @param Request $request @@ -173,7 +174,8 @@ public function requestToShipment($request) } /** - * Do return of shipment + * Do return of shipment. + * * Implementation must be in overridden method * * @param Request $request @@ -275,6 +277,8 @@ public function getDeliveryConfirmationTypes(\Magento\Framework\DataObject $para } /** + * Validate request for available ship countries. + * * @param \Magento\Framework\DataObject $request * @return $this|bool|false|\Magento\Framework\Model\AbstractModel * @SuppressWarnings(PHPMD.CyclomaticComplexity) @@ -400,6 +404,8 @@ public function getSortOrder() } /** + * Allows free shipping when all product items have free shipping. + * * @param \Magento\Quote\Model\Quote\Address\RateRequest $request * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) @@ -671,7 +677,8 @@ protected function filterDebugData($data) } /** - * Recursive replace sensitive xml nodes values by specified mask + * Recursive replace sensitive xml nodes values by specified mask. + * * @param \SimpleXMLElement $xml * @return void */ From 40683deb8285bc61de61dd475dd7a539eb1078ee Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Wed, 27 Mar 2019 17:27:42 +0200 Subject: [PATCH 37/38] magento/magento2#20526: Absent ObjectManager fix. --- app/code/Magento/Eav/Setup/EavSetup.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Eav/Setup/EavSetup.php b/app/code/Magento/Eav/Setup/EavSetup.php index 6a8f6ef36bfdb..ecb085453bb6c 100644 --- a/app/code/Magento/Eav/Setup/EavSetup.php +++ b/app/code/Magento/Eav/Setup/EavSetup.php @@ -11,6 +11,7 @@ use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory; use Magento\Eav\Model\Validator\Attribute\Code; use Magento\Framework\App\CacheInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Setup\ModuleDataSetupInterface; From 392cd1bfabad342926142dcd98981c6d3b39f261 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Thu, 28 Mar 2019 11:57:30 +0200 Subject: [PATCH 38/38] magento/magento2#20526: Static test fix. --- .../Adminhtml/Product/Attribute/Validate.php | 7 +++--- .../Magento/Eav/Model/Entity/Attribute.php | 2 +- app/code/Magento/Eav/Setup/EavSetup.php | 25 ++++++++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php index 072f3ff3ac38e..c74a382724a00 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -7,13 +7,13 @@ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; +use Magento\Catalog\Controller\Adminhtml\Product\Attribute as AttributeAction; use Magento\Eav\Model\Validator\Attribute\Code as AttributeCodeValidator; -use Magento\Framework\Serialize\Serializer\FormData; 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. @@ -80,7 +80,8 @@ public function __construct( $this->formDataSerializer = $formDataSerializer ?: ObjectManager::getInstance() ->get(FormData::class); $this->attributeCodeValidator = $attributeCodeValidator ?: ObjectManager::getInstance()->get( - AttributeCodeValidator::class); + AttributeCodeValidator::class + ); } /** diff --git a/app/code/Magento/Eav/Model/Entity/Attribute.php b/app/code/Magento/Eav/Model/Entity/Attribute.php index 4924b65896421..23054ad613c21 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute.php @@ -106,8 +106,8 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im * @param DateTimeFormatterInterface $dateTimeFormatter * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection - * @param AttributeCodeValidator|null $attributeCodeValidator * @param array $data + * @param AttributeCodeValidator|null $attributeCodeValidator * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @codeCoverageIgnore */ diff --git a/app/code/Magento/Eav/Setup/EavSetup.php b/app/code/Magento/Eav/Setup/EavSetup.php index ecb085453bb6c..de285e81b1d03 100644 --- a/app/code/Magento/Eav/Setup/EavSetup.php +++ b/app/code/Magento/Eav/Setup/EavSetup.php @@ -799,6 +799,7 @@ private function _getValue($array, $key, $default = null) * @param array $attr * @return $this * @throws LocalizedException + * @throws \Zend_Validate_Exception */ public function addAttribute($entityTypeId, $code, array $attr) { @@ -809,12 +810,7 @@ public function addAttribute($entityTypeId, $code, array $attr) $this->attributeMapper->map($attr, $entityTypeId) ); - $attributeCode = isset($data['attribute_code']) ? $data['attribute_code'] : ''; - if (!$this->attributeCodeValidator->isValid($attributeCode)) { - $errorMessage = implode("\n", $this->attributeCodeValidator->getMessages()); - - throw new LocalizedException(__($errorMessage)); - } + $this->validateAttributeCode($data); $sortOrder = isset($attr['sort_order']) ? $attr['sort_order'] : null; $attributeId = $this->getAttribute($entityTypeId, $code, 'attribute_id'); @@ -1535,4 +1531,21 @@ private function _insertAttributeAdditionalData($entityTypeId, array $data) return $this; } + + /** + * Validate attribute code. + * + * @param array $data + * @throws LocalizedException + * @throws \Zend_Validate_Exception + */ + private function validateAttributeCode(array $data): void + { + $attributeCode = $data['attribute_code'] ?? ''; + if (!$this->attributeCodeValidator->isValid($attributeCode)) { + $errorMessage = implode('\n', $this->attributeCodeValidator->getMessages()); + + throw new LocalizedException(__($errorMessage)); + } + } }