Skip to content

Commit e828eca

Browse files
committed
ACP2E-2684: Address attribute value stored incorrectly in the magento_customercustomattributes_sales_flat_quote_address table
1 parent 47d63b2 commit e828eca

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\Directory\Model\RegionFactory;
1818
use Magento\Directory\Model\ResourceModel\Region\Collection;
1919
use Magento\Eav\Model\Config;
20+
use Magento\Framework\Api\AttributeInterface;
21+
use Magento\Framework\Api\AttributeValue;
2022
use Magento\Framework\Data\Collection\AbstractDb;
2123
use Magento\Framework\DataObject;
2224
use Magento\Framework\Model\Context;
@@ -434,6 +436,57 @@ public function getStreetFullDataProvider()
434436
];
435437
}
436438

439+
/**
440+
* @return void
441+
*/
442+
public function testSetCustomerAttributes(): void
443+
{
444+
$model = $this->getMockBuilder(AbstractAddress::class)
445+
->onlyMethods(['getCustomAttributesCodes'])
446+
->disableOriginalConstructor()
447+
->getMockForAbstractClass();
448+
$customAttributeFactory = $this->createMock(\Magento\Customer\Model\AttributeFactory::class);
449+
$customAttributeFactory->method('create')
450+
->willReturnCallback(
451+
function ($data) {
452+
return new AttributeValue($data);
453+
}
454+
);
455+
$data = [
456+
'customer_attribute1' => new AttributeValue([
457+
'attribute_code' => 'customer_attribute1',
458+
'value' => 'customer_attribute1_value'
459+
]),
460+
'customer_attribute2' => new AttributeValue([
461+
'attribute_code' => 'customer_attribute2',
462+
'value' => ['customer_attribute2_value1', 'customer_attribute2_value2']
463+
])
464+
];
465+
$model->method('getCustomAttributesCodes')->willReturn(array_keys($data));
466+
$this->objectManager->setBackwardCompatibleProperty(
467+
$model,
468+
'customAttributeFactory',
469+
$customAttributeFactory
470+
);
471+
$model->setData('custom_attributes', $data);
472+
$this->assertEquals(
473+
[
474+
[
475+
'attribute_code' => 'customer_attribute1',
476+
'value' => 'customer_attribute1_value'
477+
],
478+
[
479+
'attribute_code' => 'customer_attribute2',
480+
'value' => "customer_attribute2_value1\ncustomer_attribute2_value2"
481+
]
482+
],
483+
array_map(
484+
fn ($attr) => ['attribute_code' => $attr->getAttributeCode(), 'value' => $attr->getValue()],
485+
$model->getCustomAttributes()
486+
)
487+
);
488+
}
489+
437490
protected function tearDown(): void
438491
{
439492
$this->objectManager->setBackwardCompatibleProperty(

0 commit comments

Comments
 (0)