Skip to content

Commit a3af656

Browse files
committed
Merge remote-tracking branch 'origin/MC-33554' into 2.4.1-develop-pr25
2 parents cf1be2d + d8e782b commit a3af656

File tree

2 files changed

+66
-14
lines changed

2 files changed

+66
-14
lines changed

app/code/Magento/Customer/Model/CustomerExtractor.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ public function extract(
9393
$customerData,
9494
\Magento\Customer\Api\Data\CustomerInterface::class
9595
);
96-
96+
9797
$store = $this->storeManager->getStore();
9898
$storeId = $store->getId();
99-
99+
100100
if ($isGroupIdEmpty) {
101+
$groupId = isset($customerData['group_id']) ? $customerData['group_id']
102+
: $this->customerGroupManagement->getDefaultGroup($storeId)->getId();
101103
$customerDataObject->setGroupId(
102-
$this->customerGroupManagement->getDefaultGroup($storeId)->getId()
104+
$groupId
103105
);
104106
}
105107

app/code/Magento/Customer/Test/Unit/Model/CustomerExtractorTest.php

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,27 @@ protected function setUp(): void
121121
);
122122
}
123123

124-
public function testExtract()
124+
/**
125+
* @param int $storeId
126+
* @param int $websiteId
127+
* @param array $customerData
128+
* @dataProvider getDataProvider
129+
* @return void
130+
*/
131+
public function testExtract(int $storeId, int $websiteId, array $customerData)
125132
{
126-
$customerData = [
127-
'firstname' => 'firstname',
128-
'lastname' => 'firstname',
129-
'email' => 'email.example.com',
130-
];
133+
$this->initializeExpectation($storeId, $websiteId, $customerData);
131134

135+
$this->assertSame($this->customerData, $this->customerExtractor->extract('form-code', $this->request));
136+
}
137+
138+
/**
139+
* @param int $storeId
140+
* @param int $websiteId
141+
* @param array $customerData
142+
*/
143+
private function initializeExpectation(int $storeId, int $websiteId, array $customerData): void
144+
{
132145
$this->formFactory->expects($this->once())
133146
->method('create')
134147
->with('customer', 'form-code')
@@ -156,17 +169,54 @@ public function testExtract()
156169
->willReturn($this->store);
157170
$this->store->expects($this->once())
158171
->method('getId')
159-
->willReturn(1);
172+
->willReturn($storeId);
160173
$this->store->expects($this->once())
161174
->method('getWebsiteId')
162-
->willReturn(1);
175+
->willReturn($websiteId);
163176
$this->customerData->expects($this->once())
164177
->method('setWebsiteId')
165-
->with(1);
178+
->with($websiteId);
166179
$this->customerData->expects($this->once())
167180
->method('setStoreId')
168-
->with(1);
181+
->with($storeId);
182+
}
169183

170-
$this->assertSame($this->customerData, $this->customerExtractor->extract('form-code', $this->request));
184+
/**
185+
* @return array
186+
*/
187+
public function getDataProvider()
188+
{
189+
return [
190+
'extract data when group id is null' => [
191+
1,
192+
1,
193+
[
194+
'firstname' => 'firstname-1',
195+
'lastname' => 'firstname-1',
196+
'email' => 'email-1.example.com',
197+
'group_id' => null
198+
]
199+
],
200+
'extract data when group id is not null and default' => [
201+
1,
202+
2,
203+
[
204+
'firstname' => 'firstname-2',
205+
'lastname' => 'firstname-3',
206+
'email' => 'email-2.example.com',
207+
'group_id' => 1
208+
]
209+
],
210+
'extract data when group id is different from default' => [
211+
1,
212+
1,
213+
[
214+
'firstname' => 'firstname-3',
215+
'lastname' => 'firstname-3',
216+
'email' => 'email-3.example.com',
217+
'group_id' => 2
218+
]
219+
],
220+
];
171221
}
172222
}

0 commit comments

Comments
 (0)