Skip to content

Commit 3bfbf3b

Browse files
committed
Merge branch 'ACP2E-2166' of https://github.com/magento-l3/magento2ce into Tier4-PR-10-30-2023
2 parents 36e6e6f + 268418d commit 3bfbf3b

File tree

2 files changed

+103
-8
lines changed

2 files changed

+103
-8
lines changed

app/code/Magento/Customer/Model/Address/CustomerAddressDataProvider.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77

88
namespace Magento\Customer\Model\Address;
99

10+
use Magento\Customer\Api\Data\CustomerInterface;
1011
use Magento\Customer\Model\Config\Share;
1112
use Magento\Directory\Model\AllowedCountries;
1213
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\Exception\LocalizedException;
1315

14-
/**
15-
* Provides customer address data.
16-
*/
1716
class CustomerAddressDataProvider
1817
{
1918
/**
20-
* Customer addresses.
21-
*
2219
* @var array
2320
*/
2421
private $customerAddresses = [];
@@ -58,12 +55,14 @@ public function __construct(
5855
/**
5956
* Get addresses for customer.
6057
*
61-
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
58+
* @param CustomerInterface $customer
59+
* @param int|null $addressLimit
6260
* @return array
63-
* @throws \Magento\Framework\Exception\LocalizedException
61+
* @throws LocalizedException
6462
*/
6563
public function getAddressDataByCustomer(
66-
\Magento\Customer\Api\Data\CustomerInterface $customer
64+
\Magento\Customer\Api\Data\CustomerInterface $customer,
65+
?int $addressLimit = null
6766
): array {
6867
if (!empty($this->customerAddresses)) {
6968
return $this->customerAddresses;
@@ -83,6 +82,9 @@ public function getAddressDataByCustomer(
8382
}
8483

8584
$customerAddresses[$address->getId()] = $this->customerAddressDataFormatter->prepareAddress($address);
85+
if ($addressLimit && count($customerAddresses) >= $addressLimit) {
86+
break;
87+
}
8688
}
8789

8890
$this->customerAddresses = $customerAddresses;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\Customer\Test\Unit\Model\Address;
18+
19+
use Magento\Customer\Api\Data\AddressInterface;
20+
use Magento\Customer\Api\Data\CustomerInterface;
21+
use Magento\Customer\Model\Address\CustomerAddressDataFormatter;
22+
use Magento\Customer\Model\Address\CustomerAddressDataProvider;
23+
use Magento\Customer\Model\Config\Share;
24+
use Magento\Directory\Model\AllowedCountries;
25+
use PHPUnit\Framework\MockObject\MockObject;
26+
use PHPUnit\Framework\TestCase;
27+
28+
class CustomerAddressDataProviderTest extends TestCase
29+
{
30+
/**
31+
* @var CustomerAddressDataFormatter|MockObject
32+
*/
33+
private CustomerAddressDataFormatter $customerAddressDataFormatter;
34+
35+
/**
36+
* @var Share|MockObject
37+
*/
38+
private Share $shareConfig;
39+
40+
/**
41+
* @var AllowedCountries|MockObject
42+
*/
43+
private AllowedCountries $allowedCountryReader;
44+
45+
/**
46+
* @var CustomerAddressDataProvider
47+
*/
48+
private CustomerAddressDataProvider $provider;
49+
50+
/**
51+
* @inheritdoc
52+
*/
53+
protected function setUp(): void
54+
{
55+
$this->customerAddressDataFormatter = $this->createMock(CustomerAddressDataFormatter::class);
56+
$this->shareConfig = $this->createMock(Share::class);
57+
$this->allowedCountryReader = $this->createMock(AllowedCountries::class);
58+
59+
$this->provider = new CustomerAddressDataProvider(
60+
$this->customerAddressDataFormatter,
61+
$this->shareConfig,
62+
$this->allowedCountryReader
63+
);
64+
}
65+
66+
/**
67+
* @return void
68+
* @throws \Magento\Framework\Exception\LocalizedException
69+
*/
70+
public function testGetAddressDataByCustomer(): void
71+
{
72+
$addressLimit = 1;
73+
$this->allowedCountryReader->expects($this->once())->method('getAllowedCountries')->willReturn(['1']);
74+
$this->customerAddressDataFormatter->expects($this->once())
75+
->method('prepareAddress')
76+
->willreturn([1]);
77+
$this->shareConfig->expects($this->any())->method('isGlobalScope')->willReturn(false);
78+
79+
$viableAddress = $this->getMockForAbstractClass(AddressInterface::class);
80+
$viableAddress->expects($this->once())->method('getId')->willReturn(1);
81+
$faultyAddress = $this->getMockForAbstractClass(AddressInterface::class);
82+
83+
$customer = $this->getMockForAbstractClass(CustomerInterface::class);
84+
$customer->expects($this->once())
85+
->method('getAddresses')
86+
->willReturn([$viableAddress, $faultyAddress]);
87+
88+
$expectedResult = [
89+
'1' => [1]
90+
];
91+
$this->assertSame($expectedResult, $this->provider->getAddressDataByCustomer($customer, $addressLimit));
92+
}
93+
}

0 commit comments

Comments
 (0)