Skip to content

Commit cf1be2d

Browse files
committed
Merge remote-tracking branch 'origin/MC-33522' into 2.4.1-develop-pr25
2 parents 9d4a761 + c798ca3 commit cf1be2d

File tree

2 files changed

+39
-6
lines changed
  • app/code/Magento/Customer/Controller/Adminhtml/Index
  • dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index

2 files changed

+39
-6
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected function _extractData(
248248
* @param array $extractedCustomerData
249249
* @return array
250250
*/
251-
protected function saveDefaultFlags(array $addressIdList, array & $extractedCustomerData)
251+
protected function saveDefaultFlags(array $addressIdList, array &$extractedCustomerData)
252252
{
253253
$result = [];
254254
$extractedCustomerData[CustomerInterface::DEFAULT_BILLING] = null;
@@ -290,7 +290,7 @@ protected function saveDefaultFlags(array $addressIdList, array & $extractedCust
290290
* @param array $extractedCustomerData
291291
* @return array
292292
*/
293-
protected function _extractCustomerAddressData(array & $extractedCustomerData)
293+
protected function _extractCustomerAddressData(array &$extractedCustomerData)
294294
{
295295
$addresses = $this->getRequest()->getPost('address');
296296
$result = [];
@@ -380,6 +380,12 @@ public function execute()
380380
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
381381
$this->messageManager->addSuccessMessage(__('You saved the customer.'));
382382
$returnToEdit = (bool)$this->getRequest()->getParam('back', false);
383+
} catch (NoSuchEntityException $exception) {
384+
$this->messageManager->addExceptionMessage(
385+
$exception,
386+
__('Something went wrong while saving the customer.')
387+
);
388+
$returnToEdit = false;
383389
} catch (\Magento\Framework\Validator\Exception $exception) {
384390
$messages = $exception->getMessages();
385391
if (empty($messages)) {

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/SaveTest.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Store\Model\Store;
2323
use Magento\Store\Model\StoreManagerInterface;
2424
use Magento\TestFramework\TestCase\AbstractBackendController;
25+
use PHPUnit\Framework\MockObject\MockObject;
2526

2627
/**
2728
* Tests for save customer via backend/customer/index/save controller.
@@ -224,6 +225,32 @@ public function createCustomerErrorsProvider(): array
224225
];
225226
}
226227

228+
/**
229+
* Update customer with exceptions
230+
*
231+
* @magentoDbIsolation enabled
232+
*
233+
* @return void
234+
*/
235+
public function testUpdateCustomerErrors(): void
236+
{
237+
$postData = [
238+
'customer' => [
239+
CustomerData::FIRSTNAME => 'John',
240+
CustomerData::LASTNAME => 'Doe',
241+
],
242+
'subscription' => '1',
243+
];
244+
$expectedMessages = [(string)__('Something went wrong while saving the customer.')];
245+
$postData['customer']['entity_id'] = -1;
246+
$params = ['back' => true];
247+
$this->dispatchCustomerSave($postData, $params);
248+
$this->assertSessionMessages(
249+
$this->equalTo($expectedMessages),
250+
MessageInterface::TYPE_ERROR
251+
);
252+
}
253+
227254
/**
228255
* Update customer with subscription and redirect to edit page.
229256
*
@@ -512,15 +539,15 @@ private function assertCustomerSubscription(
512539
* @param array $sender
513540
* @param int $customerId
514541
* @param string|null $newEmail
515-
* @return \PHPUnit\Framework\MockObject\MockObject
542+
* @return MockObject
516543
*/
517544
private function prepareEmailMock(
518545
int $occurrenceNumber,
519546
string $templateId,
520547
array $sender,
521548
int $customerId,
522549
$newEmail = null
523-
) : \PHPUnit\Framework\MockObject\MockObject {
550+
) : MockObject {
524551
$area = Area::AREA_FRONTEND;
525552
$customer = $this->customerRepository->getById($customerId);
526553
$storeId = $customer->getStoreId();
@@ -568,12 +595,12 @@ private function prepareEmailMock(
568595
/**
569596
* Add email mock to class
570597
*
571-
* @param \PHPUnit\Framework\MockObject\MockObject $transportBuilderMock
598+
* @param MockObject $transportBuilderMock
572599
* @param string $className
573600
* @return void
574601
*/
575602
private function addEmailMockToClass(
576-
\PHPUnit\Framework\MockObject\MockObject $transportBuilderMock,
603+
MockObject $transportBuilderMock,
577604
$className
578605
): void {
579606
$mocked = $this->_objectManager->create(

0 commit comments

Comments
 (0)