Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customer with unique attribute can't be saved #7844 #9712

Merged
merged 2 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}