diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php index 18e420bd72ccd..8e098a3b7ee16 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php @@ -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); } diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ValidateTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ValidateTest.php index 07d78932d6f45..ac631795b61cd 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ValidateTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ValidateTest.php @@ -101,7 +101,7 @@ protected function setUp() false, true, true, - ['getPost'] + ['getPost', 'getParam'] ); $this->response = $this->getMockForAbstractClass( \Magento\Framework\App\ResponseInterface::class, @@ -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([]); @@ -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(); + } }