Skip to content

Commit

Permalink
Merge pull request #3023 from magento-chaika/chaika_august2
Browse files Browse the repository at this point in the history
[Chaika] bugfixes
  • Loading branch information
Lysenko Olexandr authored Aug 15, 2018
2 parents a7893f9 + c123f05 commit 03ab0fd
Show file tree
Hide file tree
Showing 22 changed files with 773 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\ConfigurableProduct\Test\Unit\Block\Product\View\Type;

use Magento\Customer\Model\Session;
Expand Down Expand Up @@ -83,6 +84,9 @@ class ConfigurableTest extends \PHPUnit\Framework\TestCase
*/
private $variationPricesMock;

/**
* {@inheritDoc}
*/
protected function setUp()
{
$this->mockContextObject();
Expand Down Expand Up @@ -174,7 +178,7 @@ protected function setUp()
*
* @return array
*/
public function cacheKeyProvider() : array
public function cacheKeyProvider(): array
{
return [
'without_currency_and_customer_group' => [
Expand Down Expand Up @@ -313,11 +317,7 @@ public function testGetJsonConfig()
$this->localeFormat->expects($this->atLeastOnce())->method('getPriceFormat')->willReturn([]);
$this->localeFormat->expects($this->any())
->method('getNumber')
->willReturnMap([
[$amount, $amount],
[$priceQty, $priceQty],
[$percentage, $percentage],
]);
->willReturnArgument(0);

$this->variationPricesMock->expects($this->once())
->method('getFormattedPrices')
Expand Down Expand Up @@ -349,13 +349,13 @@ public function testGetJsonConfig()
/**
* Retrieve array with expected parameters for method getJsonConfig()
*
* @param $productId
* @param $amount
* @param $priceQty
* @param $percentage
* @param int $productId
* @param double $amount
* @param int $priceQty
* @param int $percentage
* @return array
*/
private function getExpectedArray($productId, $amount, $priceQty, $percentage)
private function getExpectedArray($productId, $amount, $priceQty, $percentage): array
{
$expectedArray = [
'attributes' => [],
Expand Down
9 changes: 5 additions & 4 deletions app/code/Magento/Customer/Controller/Address/FormPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Controller\Address;

use Magento\Customer\Api\AddressRepositoryInterface;
Expand Down Expand Up @@ -197,17 +198,17 @@ public function execute()
try {
$address = $this->_extractAddress();
$this->_addressRepository->save($address);
$this->messageManager->addSuccess(__('You saved the address.'));
$this->messageManager->addSuccessMessage(__('You saved the address.'));
$url = $this->_buildUrl('*/*/index', ['_secure' => true]);
return $this->resultRedirectFactory->create()->setUrl($this->_redirect->success($url));
} catch (InputException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
foreach ($e->getErrors() as $error) {
$this->messageManager->addError($error->getMessage());
$this->messageManager->addErrorMessage($error->getMessage());
}
} catch (\Exception $e) {
$redirectUrl = $this->_buildUrl('*/*/index');
$this->messageManager->addException($e, __('We can\'t save the address.'));
$this->messageManager->addExceptionMessage($e, __('We can\'t save the address.'));
}

$url = $redirectUrl;
Expand Down
75 changes: 48 additions & 27 deletions app/code/Magento/Customer/Model/Metadata/Form/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Model\Metadata\Form;

use Magento\Customer\Api\Data\AttributeMetadataInterface;
use Magento\Framework\Api\ArrayObjectSearch;

class Text extends AbstractData
Expand All @@ -19,7 +21,7 @@ class Text extends AbstractData
/**
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute
* @param AttributeMetadataInterface $attribute
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param string $value
* @param string $entityTypeCode
Expand All @@ -29,7 +31,7 @@ class Text extends AbstractData
public function __construct(
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
\Psr\Log\LoggerInterface $logger,
\Magento\Customer\Api\Data\AttributeMetadataInterface $attribute,
AttributeMetadataInterface $attribute,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
$value,
$entityTypeCode,
Expand All @@ -41,15 +43,15 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function extractValue(\Magento\Framework\App\RequestInterface $request)
{
return $this->_applyInputFilter($this->_getRequestValue($request));
}

/**
* {@inheritdoc}
* @inheritdoc
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
Expand All @@ -72,26 +74,7 @@ public function validateValue($value)
return true;
}

// validate length
$length = $this->_string->strlen(trim($value));

$validateRules = $attribute->getValidationRules();

$minTextLength = ArrayObjectSearch::getArrayElementByName(
$validateRules,
'min_text_length'
);
if ($minTextLength !== null && $length < $minTextLength) {
$errors[] = __('"%1" length must be equal or greater than %2 characters.', $label, $minTextLength);
}

$maxTextLength = ArrayObjectSearch::getArrayElementByName(
$validateRules,
'max_text_length'
);
if ($maxTextLength !== null && $length > $maxTextLength) {
$errors[] = __('"%1" length must be equal or less than %2 characters.', $label, $maxTextLength);
}
$errors = $this->validateLength($value, $attribute, $errors);

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

/**
* {@inheritdoc}
* @inheritdoc
*/
public function compactValue($value)
{
return $value;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function restoreValue($value)
{
return $this->compactValue($value);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function outputValue($format = \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_TEXT)
{
return $this->_applyOutputFilter($this->_value);
}

/**
* Length validation
*
* @param mixed $value
* @param AttributeMetadataInterface $attribute
* @param array $errors
* @return array
*/
private function validateLength($value, AttributeMetadataInterface $attribute, array $errors): array
{
// validate length
$label = __($attribute->getStoreLabel());

$length = $this->_string->strlen(trim($value));

$validateRules = $attribute->getValidationRules();

if (!empty(ArrayObjectSearch::getArrayElementByName($validateRules, 'input_validation'))) {
$minTextLength = ArrayObjectSearch::getArrayElementByName(
$validateRules,
'min_text_length'
);
if ($minTextLength !== null && $length < $minTextLength) {
$errors[] = __('"%1" length must be equal or greater than %2 characters.', $label, $minTextLength);
}

$maxTextLength = ArrayObjectSearch::getArrayElementByName(
$validateRules,
'max_text_length'
);
if ($maxTextLength !== null && $length > $maxTextLength) {
$errors[] = __('"%1" length must be equal or less than %2 characters.', $label, $maxTextLength);
}
}

return $errors;
}
}
Loading

0 comments on commit 03ab0fd

Please sign in to comment.