Skip to content

Commit 7512794

Browse files
MAGETWO-69373: Customer with unique attribute can't be saved #7844 #9712
2 parents c4b9e21 + bc664fa commit 7512794

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ protected function _validateCustomer($response)
4444
$data,
4545
\Magento\Customer\Api\Data\CustomerInterface::class
4646
);
47+
$submittedData = $this->getRequest()->getParam('customer');
48+
if (isset($submittedData['entity_id'])) {
49+
$entity_id = $submittedData['entity_id'];
50+
$customer->setId($entity_id);
51+
}
4752
$errors = $this->customerAccountManagement->validate($customer)->getMessages();
4853
} catch (\Magento\Framework\Validator\Exception $exception) {
4954
/* @var $error Error */

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ValidateTest.php

+55-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function setUp()
101101
false,
102102
true,
103103
true,
104-
['getPost']
104+
['getPost', 'getParam']
105105
);
106106
$this->response = $this->getMockForAbstractClass(
107107
\Magento\Framework\App\ResponseInterface::class,
@@ -169,6 +169,17 @@ public function testExecute()
169169
'_template_' => null,
170170
'address_index' => null
171171
]);
172+
$customerEntityId = 2;
173+
$this->request->expects($this->once())
174+
->method('getParam')
175+
->with('customer')
176+
->willReturn([
177+
'entity_id' => $customerEntityId
178+
]);
179+
180+
$this->customer->expects($this->once())
181+
->method('setId')
182+
->with($customerEntityId);
172183

173184
$this->form->expects($this->once())->method('setInvisibleIgnored');
174185
$this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]);
@@ -273,4 +284,47 @@ public function testExecuteWithException()
273284

274285
$this->controller->execute();
275286
}
287+
288+
public function testExecuteWithNewCustomerAndNoEntityId()
289+
{
290+
$this->request->expects($this->once())
291+
->method('getPost')
292+
->willReturn([
293+
'_template_' => null,
294+
'address_index' => null
295+
]);
296+
$this->request->expects($this->once())
297+
->method('getParam')
298+
->with('customer')
299+
->willReturn([]);
300+
301+
$this->customer->expects($this->never())
302+
->method('setId');
303+
304+
$this->form->expects($this->once())->method('setInvisibleIgnored');
305+
$this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]);
306+
307+
$error = $this->getMock(\Magento\Framework\Message\Error::class, [], [], '', false);
308+
$this->form->expects($this->once())
309+
->method('validateData')
310+
->willReturn([$error]);
311+
312+
$validationResult = $this->getMockForAbstractClass(
313+
\Magento\Customer\Api\Data\ValidationResultsInterface::class,
314+
[],
315+
'',
316+
false,
317+
true,
318+
true
319+
);
320+
$validationResult->expects($this->once())
321+
->method('getMessages')
322+
->willReturn(['Error message']);
323+
324+
$this->customerAccountManagement->expects($this->once())
325+
->method('validate')
326+
->willReturn($validationResult);
327+
328+
$this->controller->execute();
329+
}
276330
}

0 commit comments

Comments
 (0)