Skip to content

Commit f1b5f19

Browse files
committed
Merge remote-tracking branch 'origin/MC-37102' into 2.4-develop-sidecar-pr4
2 parents 732dfeb + c20af32 commit f1b5f19

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Model\AccountManagement;
9+
10+
use Magento\Customer\Api\AccountManagementInterface;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Customer\Api\Data\AddressInterfaceFactory;
13+
use Magento\Customer\Api\Data\CustomerInterface;
14+
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
15+
use Magento\Framework\ObjectManagerInterface;
16+
use Magento\Framework\Registry;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Test for creation customer with address via customer account management service.
22+
*
23+
* @magentoDbIsolation enabled
24+
*/
25+
class CreateAccountWithAddressTest extends TestCase
26+
{
27+
/** @var ObjectManagerInterface */
28+
private $objectManager;
29+
30+
/** @var AccountManagementInterface */
31+
private $accountManagement;
32+
33+
/** @var CustomerInterfaceFactory */
34+
private $customerFactory;
35+
36+
/** @var CustomerRepositoryInterface */
37+
private $customerRepository;
38+
39+
/** @var AddressInterfaceFactory */
40+
private $addressFactory;
41+
42+
/** @var CustomerInterface */
43+
private $customer;
44+
45+
/** @var Registry */
46+
private $registry;
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
protected function setUp(): void
52+
{
53+
parent::setUp();
54+
55+
$this->objectManager = Bootstrap::getObjectManager();
56+
$this->accountManagement = $this->objectManager->get(AccountManagementInterface::class);
57+
$this->customerFactory = $this->objectManager->get(CustomerInterfaceFactory::class);
58+
$this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
59+
$this->addressFactory = $this->objectManager->get(AddressInterfaceFactory::class);
60+
$this->registry = $this->objectManager->get(Registry::class);
61+
}
62+
63+
/**
64+
* @inheritdoc
65+
*/
66+
protected function tearDown(): void
67+
{
68+
if ($this->customer instanceof CustomerInterface) {
69+
$this->registry->unregister('isSecureArea');
70+
$this->registry->register('isSecureArea', true);
71+
$this->customerRepository->delete($this->customer);
72+
$this->registry->unregister('isSecureArea');
73+
$this->registry->register('isSecureArea', false);
74+
}
75+
76+
parent::tearDown();
77+
}
78+
79+
/**
80+
* @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php
81+
* @magentoConfigFixture default_store general/country/allow BD,BB,AF
82+
* @magentoConfigFixture fixture_second_store_store general/country/allow AS,BM
83+
* @return void
84+
*/
85+
public function testCreateNewCustomerWithAddress(): void
86+
{
87+
$availableCountry = 'BD';
88+
$address = $this->addressFactory->create();
89+
$address->setCountryId($availableCountry)
90+
->setPostcode('75477')
91+
->setRegionId(1)
92+
->setStreet(['Green str, 67'])
93+
->setTelephone('3468676')
94+
->setCity('CityM')
95+
->setFirstname('John')
96+
->setLastname('Smith')
97+
->setIsDefaultShipping(true)
98+
->setIsDefaultBilling(true);
99+
$customerEntity = $this->customerFactory->create();
100+
$customerEntity->setEmail('test@example.com')
101+
->setFirstname('John')
102+
->setLastname('Smith')
103+
->setStoreId(1);
104+
$customerEntity->setAddresses([$address]);
105+
$this->customer = $this->accountManagement->createAccount($customerEntity);
106+
$this->assertCount(1, $this->customer->getAddresses(), 'The available address wasn\'t saved.');
107+
$this->assertSame(
108+
$availableCountry,
109+
$this->customer->getAddresses()[0]->getCountryId(),
110+
'The address was saved with disallowed country.'
111+
);
112+
}
113+
}

dev/tests/integration/testsuite/Magento/Customer/Model/Address/CreateAddressTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,23 @@ public function testAddressCreatedWithGroupAssignByVatIdWithError(): void
424424
$this->assertEquals(2, $this->getCustomerGroupId('customer5@example.com'));
425425
}
426426

427+
/**
428+
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
429+
* @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php
430+
* @magentoConfigFixture default_store general/country/allow BD,BB,AF
431+
* @magentoConfigFixture fixture_second_store_store general/country/allow AS,BM
432+
*
433+
* @return void
434+
*/
435+
public function testCreateAvailableAddress(): void
436+
{
437+
$countryId = 'BB';
438+
$addressData = array_merge(self::STATIC_CUSTOMER_ADDRESS_DATA, [AddressInterface::COUNTRY_ID => $countryId]);
439+
$customer = $this->customerRepository->get('customer5@example.com');
440+
$address = $this->createAddress((int)$customer->getId(), $addressData);
441+
$this->assertSame($countryId, $address->getCountryId());
442+
}
443+
427444
/**
428445
* Create customer address with provided address data.
429446
*

0 commit comments

Comments
 (0)