Skip to content

Fixed the usage of deprecated methods of Messagemanager #25782

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

Merged
Merged
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Controller/Account/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function execute()
$metadata->setPath('/');
$this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
}
$this->messageManager->addSuccess($this->getSuccessMessage());
$this->messageManager->addSuccessMessage($this->getSuccessMessage());
$resultRedirect->setUrl($this->getSuccessRedirect());
return $resultRedirect;
} catch (StateException $e) {
Expand Down
2 changes: 0 additions & 2 deletions app/code/Magento/Customer/Controller/Account/CreatePost.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,7 @@ public function execute()
$resultRedirect->setUrl($this->_redirect->success($url));
} else {
$this->session->setCustomerDataAsLoggedIn($customer);

$this->messageManager->addMessage($this->getMessageManagerSuccessMessage());

$requestedRedirect = $this->accountRedirect->getRedirectCookie();
if (!$this->scopeConfig->getValue('customer/startup/redirect_dashboard') && $requestedRedirect) {
$resultRedirect->setUrl($this->_redirect->success($requestedRedirect));
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Customer/Controller/Account/EditPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function execute()
$isPasswordChanged
);
$this->dispatchSuccessEvent($customerCandidateDataObject);
$this->messageManager->addSuccess(__('You saved the account information.'));
$this->messageManager->addSuccessMessage(__('You saved the account information.'));
return $resultRedirect->setPath('customer/account');
} catch (InvalidEmailOrPasswordException $e) {
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
Expand All @@ -227,15 +227,15 @@ public function execute()
);
$this->session->logout();
$this->session->start();
$this->messageManager->addError($message);
$this->messageManager->addErrorMessage($message);
return $resultRedirect->setPath('customer/account/login');
} catch (InputException $e) {
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
foreach ($e->getErrors() as $error) {
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($error->getMessage()));
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t save the customer.'));
}
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Customer/Controller/Account/LoginPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ public function execute()
$message = $e->getMessage();
} catch (\Exception $e) {
// PA DSS violation: throwing or logging an exception here can disclose customer password
$this->messageManager->addError(
$this->messageManager->addErrorMessage(
__('An unspecified error occurred. Please contact us for assistance.')
);
} finally {
if (isset($message)) {
$this->messageManager->addError($message);
$this->messageManager->addErrorMessage($message);
$this->session->setUsername($login['username']);
}
}
} else {
$this->messageManager->addError(__('A login and a password are required.'));
$this->messageManager->addErrorMessage(__('A login and a password are required.'));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public function execute()
$passwordConfirmation = (string)$this->getRequest()->getPost('password_confirmation');

if ($password !== $passwordConfirmation) {
$this->messageManager->addError(__("New Password and Confirm New Password values didn't match."));
$this->messageManager->addErrorMessage(__("New Password and Confirm New Password values didn't match."));
$resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]);

return $resultRedirect;
}
if (iconv_strlen($password) <= 0) {
$this->messageManager->addError(__('Please enter a new password.'));
$this->messageManager->addErrorMessage(__('Please enter a new password.'));
$resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]);

return $resultRedirect;
Expand All @@ -92,17 +92,17 @@ public function execute()
$password
);
$this->session->unsRpToken();
$this->messageManager->addSuccess(__('You updated your password.'));
$this->messageManager->addSuccessMessage(__('You updated your password.'));
$resultRedirect->setPath('*/*/login');

return $resultRedirect;
} catch (InputException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
foreach ($e->getErrors() as $error) {
$this->messageManager->addError($error->getMessage());
$this->messageManager->addErrorMessage($error->getMessage());
}
} catch (\Exception $exception) {
$this->messageManager->addError(__('Something went wrong while saving the new password.'));
$this->messageManager->addErrorMessage(__('Something went wrong while saving the new password.'));
}
$resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]);

Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/Controller/Address/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function execute()
$address = $this->_addressRepository->getById($addressId);
if ($address->getCustomerId() === $this->_getSession()->getCustomerId()) {
$this->_addressRepository->deleteById($addressId);
$this->messageManager->addSuccess(__('You deleted the address.'));
$this->messageManager->addSuccessMessage(__('You deleted the address.'));
} else {
$this->messageManager->addError(__('We can\'t delete the address right now.'));
$this->messageManager->addErrorMessage(__('We can\'t delete the address right now.'));
}
} catch (\Exception $other) {
$this->messageManager->addException($other, __('We can\'t delete the address right now.'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ public function execute()
if ($customerId = $this->getRequest()->getParam('customer_id')) {
try {
$this->tokenService->revokeCustomerAccessToken($customerId);
$this->messageManager->addSuccess(__('You have revoked the customer\'s tokens.'));
$this->messageManager->addSuccessMessage(__('You have revoked the customer\'s tokens.'));
$resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]);
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
$resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]);
}
} else {
$this->messageManager->addError(__('We can\'t find a customer to revoke.'));
$this->messageManager->addErrorMessage(__('We can\'t find a customer to revoke.'));
$resultRedirect->setPath('customer/index/index');
}
return $resultRedirect;
Expand Down
10 changes: 6 additions & 4 deletions app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
Expand All @@ -9,6 +8,9 @@
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Exception\NoSuchEntityException;

/**
* Class Delete
*/
class Delete extends \Magento\Customer\Controller\Adminhtml\Group implements HttpPostActionInterface
{
/**
Expand All @@ -24,12 +26,12 @@ public function execute()
if ($id) {
try {
$this->groupRepository->deleteById($id);
$this->messageManager->addSuccess(__('You deleted the customer group.'));
$this->messageManager->addSuccessMessage(__('You deleted the customer group.'));
} catch (NoSuchEntityException $e) {
$this->messageManager->addError(__('The customer group no longer exists.'));
$this->messageManager->addErrorMessage(__('The customer group no longer exists.'));
return $resultRedirect->setPath('customer/*/');
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
return $resultRedirect->setPath('customer/group/edit', ['id' => $id]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public function execute()

$this->groupRepository->save($customerGroup);

$this->messageManager->addSuccess(__('You saved the customer group.'));
$this->messageManager->addSuccessMessage(__('You saved the customer group.'));
$resultRedirect->setPath('customer/group');
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
if ($customerGroup != null) {
$this->storeCustomerGroupDataToSession(
$this->dataObjectProcessor->buildOutputDataArray(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function execute()
$collection = $this->filter->getCollection($this->collectionFactory->create());
return $this->massAction($collection);
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath($this->redirectUrl);
Expand All @@ -73,6 +73,7 @@ public function execute()

/**
* Return component referer url
*
* TODO: Technical dept referer url should be implement as a part of Action configuration in appropriate way
*
* @return null|string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ public function execute()
$formKeyIsValid = $this->_formKeyValidator->validate($this->getRequest());
$isPost = $this->getRequest()->isPost();
if (!$formKeyIsValid || !$isPost) {
$this->messageManager->addError(__('Customer could not be deleted.'));
$this->messageManager->addErrorMessage(__('Customer could not be deleted.'));
return $resultRedirect->setPath('customer/index');
}

$customerId = $this->initCurrentCustomer();
if (!empty($customerId)) {
try {
$this->_customerRepository->deleteById($customerId);
$this->messageManager->addSuccess(__('You deleted the customer.'));
$this->messageManager->addSuccessMessage(__('You deleted the customer.'));
} catch (\Exception $exception) {
$this->messageManager->addError($exception->getMessage());
$this->messageManager->addErrorMessage($exception->getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $ad
->willReturnSelf();

$this->messageManagerMock->expects($this->any())
->method('addSuccess')
->method('addSuccessMessage')
->with($this->stringContains($successMessage))
->willReturnSelf();

Expand Down Expand Up @@ -402,7 +402,7 @@ public function testSuccessRedirect(
->willReturnSelf();

$this->messageManagerMock->expects($this->any())
->method('addSuccess')
->method('addSuccessMessage')
->with($this->stringContains($successMessage))
->willReturnSelf();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function testExecuteEmptyLoginData()
->willReturn([]);

$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with(__('A login and a password are required.'))
->willReturnSelf();

Expand Down Expand Up @@ -557,7 +557,7 @@ protected function mockExceptions($exception, $username)
$url
);
$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with($message)
->willReturnSelf();

Expand All @@ -569,7 +569,7 @@ protected function mockExceptions($exception, $username)

case \Magento\Framework\Exception\AuthenticationException::class:
$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with(
__(
'The account sign-in was incorrect or your account is disabled temporarily. '
Expand All @@ -586,7 +586,7 @@ protected function mockExceptions($exception, $username)

case '\Exception':
$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with(__('An unspecified error occurred. Please contact us for assistance.'))
->willReturnSelf();
break;
Expand All @@ -597,7 +597,7 @@ protected function mockExceptions($exception, $username)
. 'Please wait and try again later.'
);
$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with($message)
->willReturnSelf();
$this->session->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function testExecute()
->method('deleteById')
->with($addressId);
$this->messageManager->expects($this->once())
->method('addSuccess')
->method('addSuccessMessage')
->with(__('You deleted the address.'));
$this->resultRedirect->expects($this->once())
->method('setPath')
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testExecuteWithException()
->willReturn(34);
$exception = new \Exception('Exception');
$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with(__('We can\'t delete the address right now.'))
->willThrowException($exception);
$this->messageManager->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ public function testExecuteWithTaxClassAndException()
->method('save')
->with($this->group);
$this->messageManager->expects($this->once())
->method('addSuccess')
->method('addSuccessMessage')
->with(__('You saved the customer group.'));
$exception = new \Exception('Exception');
$this->resultRedirect->expects($this->at(0))
->method('setPath')
->with('customer/group')
->willThrowException($exception);
$this->messageManager->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with('Exception');
$this->dataObjectProcessorMock->expects($this->once())
->method('buildOutputDataArray')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function testExecuteWithException()
->willThrowException(new \Exception('Some message.'));

$this->messageManagerMock->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with('Some message.');

$this->massAction->execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testExecuteWithException()
->willThrowException(new \Exception('Some message.'));

$this->messageManagerMock->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with('Some message.');

$this->massAction->execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function testExecuteWithException()
->willThrowException(new \Exception('Some message.'));

$this->messageManagerMock->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with('Some message.');

$this->massAction->execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function testExecuteWithException()
->willThrowException(new \Exception('Some message.'));

$this->messageManagerMock->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with('Some message.');

$this->massAction->execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ public function setUp()
$this->groupRepository = $objectManager->get(\Magento\Customer\Api\GroupRepositoryInterface::class);
}

/**
* @inheritDoc
*/
public function tearDown()
{
parent::tearDown();
//$this->session->unsCustomerGroupData();
}

/**
* Test new group form.
*/
Expand Down Expand Up @@ -199,7 +190,7 @@ public function testSaveActionCreateNewGroupWithoutCode()
$this->dispatch('backend/customer/group/save');

$this->assertSessionMessages(
$this->equalTo(['"code" is required. Enter and try again.']),
$this->equalTo([htmlspecialchars('"code" is required. Enter and try again.')]),
MessageInterface::TYPE_ERROR
);
}
Expand Down Expand Up @@ -292,7 +283,7 @@ public function testSaveActionNewGroupWithoutGroupCode()
$this->dispatch('backend/customer/group/save');

$this->assertSessionMessages(
$this->equalTo(['"code" is required. Enter and try again.']),
$this->equalTo([htmlspecialchars('"code" is required. Enter and try again.')]),
MessageInterface::TYPE_ERROR
);
$this->assertSessionMessages($this->isEmpty(), MessageInterface::TYPE_SUCCESS);
Expand Down