Skip to content

Commit

Permalink
MAGETWO-71697: Fix possible bug when saving address with empty street…
Browse files Browse the repository at this point in the history
… line #10582
  • Loading branch information
ishakhsuvarov authored and vovayatsyuk committed Nov 9, 2017
1 parent dbcc3c4 commit db377d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/code/Magento/Customer/Model/Address/AbstractAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function setData($key, $value = null)
{
if (is_array($key)) {
$key = $this->_implodeArrayField($key);
} elseif (is_array($value) && !empty($value) && $this->isAddressMultilineAttribute($key)) {
} elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
$value = $this->_implodeArrayValues($value);
}
return parent::setData($key, $value);
Expand Down Expand Up @@ -309,7 +309,11 @@ protected function _implodeArrayField(array $data)
*/
protected function _implodeArrayValues($value)
{
if (is_array($value) && count($value)) {
if (is_array($value)) {
if (!count($value)) {
return '';
}

$isScalar = false;
foreach ($value as $val) {
if (is_scalar($val)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,15 @@ public function testGetStreetFullAlwaysReturnsString($expectedResult, $street)
$this->assertEquals($expectedResult, $this->model->getStreetFull());
}

/**
* @dataProvider getStreetFullDataProvider
*/
public function testSetDataStreetAlwaysConvertedToString($expectedResult, $street)
{
$this->model->setData('street', $street);
$this->assertEquals($expectedResult, $this->model->getData('street'));
}

/**
* @return array
*/
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Test class for sales quote address model
*
* @see \Magento\Quote\Model\Quote\Address
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AddressTest extends \PHPUnit\Framework\TestCase
Expand All @@ -48,6 +49,11 @@ class AddressTest extends \PHPUnit\Framework\TestCase
*/
private $quote;

/**
* @var \Magento\Quote\Model\Quote\Address\CustomAttributeListInterface | \PHPUnit_Framework_MockObject_MockObject
*/
private $attributeList;

/**
* @var \Magento\Framework\App\Config | \PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -166,9 +172,13 @@ protected function setUp()
->disableOriginalConstructor()
->getMock();

$this->attributeList = $this->createMock(\Magento\Quote\Model\Quote\Address\CustomAttributeListInterface::class);
$this->attributeList->method('getAttributes')->willReturn([]);

$this->address = $objectManager->getObject(
\Magento\Quote\Model\Quote\Address::class,
[
'attributeList' => $this->attributeList,
'scopeConfig' => $this->scopeConfig,
'serializer' => $this->serializer,
'storeManager' => $this->storeManager,
Expand Down

0 comments on commit db377d0

Please sign in to comment.