Skip to content

Commit 03ab0fd

Browse files
author
Lysenko Olexandr
authored
Merge pull request #3023 from magento-chaika/chaika_august2
[Chaika] bugfixes
2 parents a7893f9 + c123f05 commit 03ab0fd

File tree

22 files changed

+773
-247
lines changed

22 files changed

+773
-247
lines changed

app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\ConfigurableProduct\Test\Unit\Block\Product\View\Type;
78

89
use Magento\Customer\Model\Session;
@@ -83,6 +84,9 @@ class ConfigurableTest extends \PHPUnit\Framework\TestCase
8384
*/
8485
private $variationPricesMock;
8586

87+
/**
88+
* {@inheritDoc}
89+
*/
8690
protected function setUp()
8791
{
8892
$this->mockContextObject();
@@ -174,7 +178,7 @@ protected function setUp()
174178
*
175179
* @return array
176180
*/
177-
public function cacheKeyProvider() : array
181+
public function cacheKeyProvider(): array
178182
{
179183
return [
180184
'without_currency_and_customer_group' => [
@@ -313,11 +317,7 @@ public function testGetJsonConfig()
313317
$this->localeFormat->expects($this->atLeastOnce())->method('getPriceFormat')->willReturn([]);
314318
$this->localeFormat->expects($this->any())
315319
->method('getNumber')
316-
->willReturnMap([
317-
[$amount, $amount],
318-
[$priceQty, $priceQty],
319-
[$percentage, $percentage],
320-
]);
320+
->willReturnArgument(0);
321321

322322
$this->variationPricesMock->expects($this->once())
323323
->method('getFormattedPrices')
@@ -349,13 +349,13 @@ public function testGetJsonConfig()
349349
/**
350350
* Retrieve array with expected parameters for method getJsonConfig()
351351
*
352-
* @param $productId
353-
* @param $amount
354-
* @param $priceQty
355-
* @param $percentage
352+
* @param int $productId
353+
* @param double $amount
354+
* @param int $priceQty
355+
* @param int $percentage
356356
* @return array
357357
*/
358-
private function getExpectedArray($productId, $amount, $priceQty, $percentage)
358+
private function getExpectedArray($productId, $amount, $priceQty, $percentage): array
359359
{
360360
$expectedArray = [
361361
'attributes' => [],

app/code/Magento/Customer/Controller/Address/FormPost.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Customer\Controller\Address;
78

89
use Magento\Customer\Api\AddressRepositoryInterface;
@@ -197,17 +198,17 @@ public function execute()
197198
try {
198199
$address = $this->_extractAddress();
199200
$this->_addressRepository->save($address);
200-
$this->messageManager->addSuccess(__('You saved the address.'));
201+
$this->messageManager->addSuccessMessage(__('You saved the address.'));
201202
$url = $this->_buildUrl('*/*/index', ['_secure' => true]);
202203
return $this->resultRedirectFactory->create()->setUrl($this->_redirect->success($url));
203204
} catch (InputException $e) {
204-
$this->messageManager->addError($e->getMessage());
205+
$this->messageManager->addErrorMessage($e->getMessage());
205206
foreach ($e->getErrors() as $error) {
206-
$this->messageManager->addError($error->getMessage());
207+
$this->messageManager->addErrorMessage($error->getMessage());
207208
}
208209
} catch (\Exception $e) {
209210
$redirectUrl = $this->_buildUrl('*/*/index');
210-
$this->messageManager->addException($e, __('We can\'t save the address.'));
211+
$this->messageManager->addExceptionMessage($e, __('We can\'t save the address.'));
211212
}
212213

213214
$url = $redirectUrl;

app/code/Magento/Customer/Model/Metadata/Form/Text.php

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
* Copyright © Magento, Inc. All rights reserved.
66
* See COPYING.txt for license details.
77
*/
8+
89
namespace Magento\Customer\Model\Metadata\Form;
910

11+
use Magento\Customer\Api\Data\AttributeMetadataInterface;
1012
use Magento\Framework\Api\ArrayObjectSearch;
1113

1214
class Text extends AbstractData
@@ -19,7 +21,7 @@ class Text extends AbstractData
1921
/**
2022
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
2123
* @param \Psr\Log\LoggerInterface $logger
22-
* @param \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute
24+
* @param AttributeMetadataInterface $attribute
2325
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
2426
* @param string $value
2527
* @param string $entityTypeCode
@@ -29,7 +31,7 @@ class Text extends AbstractData
2931
public function __construct(
3032
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
3133
\Psr\Log\LoggerInterface $logger,
32-
\Magento\Customer\Api\Data\AttributeMetadataInterface $attribute,
34+
AttributeMetadataInterface $attribute,
3335
\Magento\Framework\Locale\ResolverInterface $localeResolver,
3436
$value,
3537
$entityTypeCode,
@@ -41,15 +43,15 @@ public function __construct(
4143
}
4244

4345
/**
44-
* {@inheritdoc}
46+
* @inheritdoc
4547
*/
4648
public function extractValue(\Magento\Framework\App\RequestInterface $request)
4749
{
4850
return $this->_applyInputFilter($this->_getRequestValue($request));
4951
}
5052

5153
/**
52-
* {@inheritdoc}
54+
* @inheritdoc
5355
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
5456
* @SuppressWarnings(PHPMD.NPathComplexity)
5557
*/
@@ -72,26 +74,7 @@ public function validateValue($value)
7274
return true;
7375
}
7476

75-
// validate length
76-
$length = $this->_string->strlen(trim($value));
77-
78-
$validateRules = $attribute->getValidationRules();
79-
80-
$minTextLength = ArrayObjectSearch::getArrayElementByName(
81-
$validateRules,
82-
'min_text_length'
83-
);
84-
if ($minTextLength !== null && $length < $minTextLength) {
85-
$errors[] = __('"%1" length must be equal or greater than %2 characters.', $label, $minTextLength);
86-
}
87-
88-
$maxTextLength = ArrayObjectSearch::getArrayElementByName(
89-
$validateRules,
90-
'max_text_length'
91-
);
92-
if ($maxTextLength !== null && $length > $maxTextLength) {
93-
$errors[] = __('"%1" length must be equal or less than %2 characters.', $label, $maxTextLength);
94-
}
77+
$errors = $this->validateLength($value, $attribute, $errors);
9578

9679
$result = $this->_validateInputRule($value);
9780
if ($result !== true) {
@@ -105,26 +88,64 @@ public function validateValue($value)
10588
}
10689

10790
/**
108-
* {@inheritdoc}
91+
* @inheritdoc
10992
*/
11093
public function compactValue($value)
11194
{
11295
return $value;
11396
}
11497

11598
/**
116-
* {@inheritdoc}
99+
* @inheritdoc
117100
*/
118101
public function restoreValue($value)
119102
{
120103
return $this->compactValue($value);
121104
}
122105

123106
/**
124-
* {@inheritdoc}
107+
* @inheritdoc
125108
*/
126109
public function outputValue($format = \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_TEXT)
127110
{
128111
return $this->_applyOutputFilter($this->_value);
129112
}
113+
114+
/**
115+
* Length validation
116+
*
117+
* @param mixed $value
118+
* @param AttributeMetadataInterface $attribute
119+
* @param array $errors
120+
* @return array
121+
*/
122+
private function validateLength($value, AttributeMetadataInterface $attribute, array $errors): array
123+
{
124+
// validate length
125+
$label = __($attribute->getStoreLabel());
126+
127+
$length = $this->_string->strlen(trim($value));
128+
129+
$validateRules = $attribute->getValidationRules();
130+
131+
if (!empty(ArrayObjectSearch::getArrayElementByName($validateRules, 'input_validation'))) {
132+
$minTextLength = ArrayObjectSearch::getArrayElementByName(
133+
$validateRules,
134+
'min_text_length'
135+
);
136+
if ($minTextLength !== null && $length < $minTextLength) {
137+
$errors[] = __('"%1" length must be equal or greater than %2 characters.', $label, $minTextLength);
138+
}
139+
140+
$maxTextLength = ArrayObjectSearch::getArrayElementByName(
141+
$validateRules,
142+
'max_text_length'
143+
);
144+
if ($maxTextLength !== null && $length > $maxTextLength) {
145+
$errors[] = __('"%1" length must be equal or less than %2 characters.', $label, $maxTextLength);
146+
}
147+
}
148+
149+
return $errors;
150+
}
130151
}

0 commit comments

Comments
 (0)