Skip to content

Commit

Permalink
MAGETWO-69373: Customer with unique attribute can't be saved #7844 #9712
Browse files Browse the repository at this point in the history
  • Loading branch information
ishakhsuvarov authored May 31, 2017
2 parents c4b9e21 + bc664fa commit 7512794
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ protected function _validateCustomer($response)
$data,
\Magento\Customer\Api\Data\CustomerInterface::class
);
$submittedData = $this->getRequest()->getParam('customer');
if (isset($submittedData['entity_id'])) {
$entity_id = $submittedData['entity_id'];
$customer->setId($entity_id);
}
$errors = $this->customerAccountManagement->validate($customer)->getMessages();
} catch (\Magento\Framework\Validator\Exception $exception) {
/* @var $error Error */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function setUp()
false,
true,
true,
['getPost']
['getPost', 'getParam']
);
$this->response = $this->getMockForAbstractClass(
\Magento\Framework\App\ResponseInterface::class,
Expand Down Expand Up @@ -169,6 +169,17 @@ public function testExecute()
'_template_' => null,
'address_index' => null
]);
$customerEntityId = 2;
$this->request->expects($this->once())
->method('getParam')
->with('customer')
->willReturn([
'entity_id' => $customerEntityId
]);

$this->customer->expects($this->once())
->method('setId')
->with($customerEntityId);

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

$this->controller->execute();
}

public function testExecuteWithNewCustomerAndNoEntityId()
{
$this->request->expects($this->once())
->method('getPost')
->willReturn([
'_template_' => null,
'address_index' => null
]);
$this->request->expects($this->once())
->method('getParam')
->with('customer')
->willReturn([]);

$this->customer->expects($this->never())
->method('setId');

$this->form->expects($this->once())->method('setInvisibleIgnored');
$this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]);

$error = $this->getMock(\Magento\Framework\Message\Error::class, [], [], '', false);
$this->form->expects($this->once())
->method('validateData')
->willReturn([$error]);

$validationResult = $this->getMockForAbstractClass(
\Magento\Customer\Api\Data\ValidationResultsInterface::class,
[],
'',
false,
true,
true
);
$validationResult->expects($this->once())
->method('getMessages')
->willReturn(['Error message']);

$this->customerAccountManagement->expects($this->once())
->method('validate')
->willReturn($validationResult);

$this->controller->execute();
}
}

0 comments on commit 7512794

Please sign in to comment.