Skip to content

Commit

Permalink
#7844 - fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
storbahn committed May 21, 2017
1 parent b9d5669 commit 9e25d8c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function _validateCustomer($response)
\Magento\Customer\Api\Data\CustomerInterface::class
);
$submittedData = $this->getRequest()->getParam('customer');
if (array_key_exists('entity_id', $submittedData)) {
if (isset($submittedData['entity_id'])) {
$entity_id = $submittedData['entity_id'];
$customer->setId($entity_id);
}
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 9e25d8c

Please sign in to comment.