Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/merchant_beta' into MAGETWO-43877
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Kasian committed Oct 13, 2015
2 parents b5a90ab + c8ba429 commit 46a12be
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
16 changes: 13 additions & 3 deletions app/code/Magento/Customer/Model/Address/AbstractAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function setStreet($street)
}

/**
* Enforce format of the street field
* Enforce format of the street field or other multiline custom attributes
*
* @param array|string $key
* @param null $value
Expand All @@ -263,12 +263,22 @@ public function setData($key, $value = null)
{
if (is_array($key)) {
$key = $this->_implodeArrayField($key);
} elseif (is_array($value)) {
} elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
$value = $this->_implodeArrayValues($value);
}
return parent::setData($key, $value);
}

/**
* Check that address can have multiline attribute by this code (as street or some custom attribute)
* @param string $code
* @return bool
*/
protected function isAddressMultilineAttribute($code)
{
return $code == 'street' || in_array($code, $this->getCustomAttributesCodes());
}

/**
* Implode value of the array field, if it is present among other fields
*
Expand All @@ -278,7 +288,7 @@ public function setData($key, $value = null)
protected function _implodeArrayField(array $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
if (is_array($value) && $this->isAddressMultilineAttribute($key)) {
$data[$key] = $this->_implodeArrayValues($data[$key]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public function testSetData()
*/
public function testSetDataWithMultidimensionalArray()
{
$this->markTestSkipped('Need to revert changes from MAGETWO-39106 and then modify this test.');
$expected = [
'key' => 'value',
'array' => 'value1',
Expand All @@ -266,10 +267,10 @@ public function testSetDataWithMultidimensionalArray()
public function testSetDataWithValue()
{
$value = [
'key' => 'value',
'street' => 'value',
];

$this->model->setData('key', $value);
$this->model->setData('street', $value);
$this->assertEquals($value, $this->model->getData());
}

Expand Down
20 changes: 16 additions & 4 deletions app/code/Magento/SalesRule/Test/Unit/Model/Quote/DiscountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testCollectItemNoDiscount()
->getMock();
$addressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address')
->disableOriginalConstructor()
->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup'])
->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup', 'getCustomAttributesCodes'])
->getMock();
$addressMock->expects($this->any())
->method('getQuote')
Expand All @@ -124,6 +124,9 @@ public function testCollectItemNoDiscount()
$addressMock->expects($this->any())
->method('getShippingAmount')
->willReturn(true);
$addressMock->expects($this->any())
->method('getCustomAttributesCodes')
->willReturn([]);

$this->assertInstanceOf(
'Magento\SalesRule\Model\Quote\Discount',
Expand Down Expand Up @@ -165,7 +168,7 @@ public function testCollectItemHasParent()
->getMock();
$addressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address')
->disableOriginalConstructor()
->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup'])
->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup', 'getCustomAttributesCodes'])
->getMock();
$addressMock->expects($this->any())
->method('getQuote')
Expand All @@ -176,6 +179,9 @@ public function testCollectItemHasParent()
$addressMock->expects($this->any())
->method('getShippingAmount')
->willReturn(true);
$addressMock->expects($this->any())
->method('getCustomAttributesCodes')
->willReturn([]);

$this->assertInstanceOf(
'Magento\SalesRule\Model\Quote\Discount',
Expand Down Expand Up @@ -249,7 +255,7 @@ public function testCollectItemHasChildren($childItemData, $parentData, $expecte
->getMock();
$addressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address')
->disableOriginalConstructor()
->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup'])
->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup', 'getCustomAttributesCodes'])
->getMock();
$addressMock->expects($this->any())
->method('getQuote')
Expand All @@ -260,6 +266,9 @@ public function testCollectItemHasChildren($childItemData, $parentData, $expecte
$addressMock->expects($this->any())
->method('getShippingAmount')
->willReturn(true);
$addressMock->expects($this->any())
->method('getCustomAttributesCodes')
->willReturn([]);

$this->assertInstanceOf(
'Magento\SalesRule\Model\Quote\Discount',
Expand Down Expand Up @@ -368,7 +377,7 @@ public function testCollectItemHasNoChildren()
->getMock();
$addressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address')
->disableOriginalConstructor()
->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup'])
->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup', 'getCustomAttributesCodes'])
->getMock();
$addressMock->expects($this->any())
->method('getQuote')
Expand All @@ -379,6 +388,9 @@ public function testCollectItemHasNoChildren()
$addressMock->expects($this->any())
->method('getShippingAmount')
->willReturn(true);
$addressMock->expects($this->any())
->method('getCustomAttributesCodes')
->willReturn([]);

$this->assertInstanceOf(
'Magento\SalesRule\Model\Quote\Discount',
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/SalesRule/Test/Unit/Model/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,17 @@ protected function getAddressMock($shippingAmount = null)

$addressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address')
->disableOriginalConstructor()
->setMethods(['getShippingAmountForDiscount', 'getQuote'])
->setMethods(['getShippingAmountForDiscount', 'getQuote', 'getCustomAttributesCodes'])
->getMock();
$addressMock->expects($this->any())
->method('getShippingAmountForDiscount')
->willReturn($shippingAmount);
$addressMock->expects($this->any())
->method('getQuote')
->willReturn($quoteMock);
$addressMock->expects($this->any())
->method('getCustomAttributesCodes')
->willReturn([]);
return $addressMock;
}

Expand Down
21 changes: 19 additions & 2 deletions app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,21 @@ public function testMapQuoteExtraTaxables($itemData, $addressData)

$address = $this->getMockBuilder('\Magento\Quote\Model\Quote\Address')
->disableOriginalConstructor()
->setMethods(['getAssociatedTaxables', 'getQuote', 'getBillingAddress', 'getRegionId', '__wakeup'])
->setMethods(
[
'getAssociatedTaxables',
'getQuote',
'getBillingAddress',
'getRegionId',
'__wakeup',
'getCustomAttributesCodes'
]
)
->getMock();
$address
->expects($this->any())
->method('getCustomAttributesCodes')
->willReturn([]);
$quote
->expects($this->any())
->method('getBillingAddress')
Expand Down Expand Up @@ -596,7 +609,7 @@ public function testFetch($appliedTaxesData, $addressData)
'\Magento\Quote\Model\Quote\Address',
[
'getAppliedTaxes', 'getQuote', 'getAllItems', 'getGrandTotal', '__wakeup',
'addTotal', 'getTaxAmount'
'addTotal', 'getTaxAmount', 'getCustomAttributesCodes'
],
[],
'',
Expand Down Expand Up @@ -626,6 +639,10 @@ public function testFetch($appliedTaxesData, $addressData)
->expects($this->any())
->method('getTaxAmount')
->will($this->returnValue(8));
$address
->expects($this->any())
->method('getCustomAttributesCodes')
->willReturn([]);

$addressData["cached_items_all"] = $items;
foreach ($addressData as $key => $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ protected function setupAddressMock($itemMock)
'__wakeup',
'getAllItems',
'getQuote',
'getCustomAttributesCodes'
],
[],
'',
Expand All @@ -136,6 +137,7 @@ protected function setupAddressMock($itemMock)

$addressMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock]));
$addressMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
$addressMock->expects($this->any())->method('getCustomAttributesCodes')->willReturn([]);

return $addressMock;
}
Expand Down

0 comments on commit 46a12be

Please sign in to comment.