From 6b42eb2bff1e96c53a602f70f90785607b72c3a3 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Tue, 20 Aug 2019 09:10:12 +0300 Subject: [PATCH 01/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento_Customer module addError -> addErrorMessage addSuccess -> addSuccessMessage addException -> addExceptionMessage --- .../Customer/Controller/Account/Confirm.php | 6 +++--- .../Customer/Controller/Account/Confirmation.php | 6 +++--- .../Customer/Controller/Account/CreatePost.php | 14 +++++++------- .../Customer/Controller/Account/EditPost.php | 8 ++++---- .../Customer/Controller/Account/LoginPost.php | 6 +++--- .../Controller/Account/ResetPasswordPost.php | 12 ++++++------ .../Magento/Customer/Controller/Address/Delete.php | 6 +++--- .../Adminhtml/Customer/InvalidateToken.php | 6 +++--- .../Customer/Controller/Adminhtml/Group/Delete.php | 6 +++--- .../Customer/Controller/Adminhtml/Group/Save.php | 4 ++-- .../Customer/Controller/Adminhtml/Index.php | 4 ++-- .../Adminhtml/Index/AbstractMassAction.php | 2 +- .../Customer/Controller/Adminhtml/Index/Delete.php | 6 +++--- .../Customer/Controller/Adminhtml/Index/Edit.php | 2 +- .../Controller/Adminhtml/Index/InlineEdit.php | 6 +++--- .../Controller/Adminhtml/Index/MassAssignGroup.php | 2 +- .../Controller/Adminhtml/Index/MassDelete.php | 2 +- .../Controller/Adminhtml/Index/MassSubscribe.php | 2 +- .../Controller/Adminhtml/Index/MassUnsubscribe.php | 2 +- .../Controller/Adminhtml/Index/ResetPassword.php | 6 ++++-- .../Customer/Controller/Adminhtml/Index/Save.php | 7 +++++-- .../Customer/Controller/Adminhtml/Locks/Unlock.php | 4 ++-- .../Customer/Observer/AfterAddressSaveObserver.php | 6 +++--- 23 files changed, 65 insertions(+), 60 deletions(-) diff --git a/app/code/Magento/Customer/Controller/Account/Confirm.php b/app/code/Magento/Customer/Controller/Account/Confirm.php index 2b3cb9aa61ab5..4f0fb3ff08550 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirm.php +++ b/app/code/Magento/Customer/Controller/Account/Confirm.php @@ -163,13 +163,13 @@ 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) { - $this->messageManager->addException($e, __('This confirmation key is invalid or has expired.')); + $this->messageManager->addExceptionMessage($e, __('This confirmation key is invalid or has expired.')); } catch (\Exception $e) { - $this->messageManager->addException($e, __('There was an error confirming the account')); + $this->messageManager->addExceptionMessage($e, __('There was an error confirming the account')); } $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); diff --git a/app/code/Magento/Customer/Controller/Account/Confirmation.php b/app/code/Magento/Customer/Controller/Account/Confirmation.php index a3e2db0207630..bd9066dcd464a 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirmation.php +++ b/app/code/Magento/Customer/Controller/Account/Confirmation.php @@ -91,11 +91,11 @@ public function execute() $email, $this->storeManager->getStore()->getWebsiteId() ); - $this->messageManager->addSuccess(__('Please check your email for confirmation key.')); + $this->messageManager->addSuccessMessage(__('Please check your email for confirmation key.')); } catch (InvalidTransitionException $e) { - $this->messageManager->addSuccess(__('This email does not require confirmation.')); + $this->messageManager->addSuccessMessage(__('This email does not require confirmation.')); } catch (\Exception $e) { - $this->messageManager->addException($e, __('Wrong email.')); + $this->messageManager->addExceptionMessage($e, __('Wrong email.')); $resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]); return $resultRedirect; } diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index 4c9c25b5f33d9..510d82879637f 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -366,7 +366,7 @@ public function execute() if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) { $email = $this->customerUrl->getEmailConfirmationUrl($customer->getEmail()); // @codingStandardsIgnoreStart - $this->messageManager->addSuccess( + $this->messageManager->addSuccessMessage( __( 'You must confirm your account. Please check your email for the confirmation link or click here for a new link.', $email @@ -377,7 +377,7 @@ public function execute() $resultRedirect->setUrl($this->_redirect->success($url)); } else { $this->session->setCustomerDataAsLoggedIn($customer); - $this->messageManager->addSuccess($this->getSuccessMessage()); + $this->messageManager->addSuccessMessage($this->getSuccessMessage()); $requestedRedirect = $this->accountRedirect->getRedirectCookie(); if (!$this->scopeConfig->getValue('customer/startup/redirect_dashboard') && $requestedRedirect) { $resultRedirect->setUrl($this->_redirect->success($requestedRedirect)); @@ -401,16 +401,16 @@ public function execute() $url ); // @codingStandardsIgnoreEnd - $this->messageManager->addError($message); + $this->messageManager->addErrorMessage($message); } catch (InputException $e) { - $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage())); + $this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage())); foreach ($e->getErrors() as $error) { - $this->messageManager->addError($this->escaper->escapeHtml($error->getMessage())); + $this->messageManager->addErrorMessage($this->escaper->escapeHtml($error->getMessage())); } } catch (LocalizedException $e) { - $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage())); + $this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage())); } catch (\Exception $e) { - $this->messageManager->addException($e, __('We can\'t save the customer.')); + $this->messageManager->addExceptionMessage($e, __('We can\'t save the customer.')); } $this->session->setCustomerFormData($this->getRequest()->getPostValue()); diff --git a/app/code/Magento/Customer/Controller/Account/EditPost.php b/app/code/Magento/Customer/Controller/Account/EditPost.php index 4eb41cedea29a..d2300b7b490c5 100644 --- a/app/code/Magento/Customer/Controller/Account/EditPost.php +++ b/app/code/Magento/Customer/Controller/Account/EditPost.php @@ -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())); @@ -227,7 +227,7 @@ 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())); @@ -235,9 +235,9 @@ public function execute() $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.')); + $this->messageManager->addExceptionMessage($e, __('We can\'t save the customer.')); } $this->session->setCustomerFormData($this->getRequest()->getPostValue()); diff --git a/app/code/Magento/Customer/Controller/Account/LoginPost.php b/app/code/Magento/Customer/Controller/Account/LoginPost.php index 04051fbbf366b..a7632401933e6 100644 --- a/app/code/Magento/Customer/Controller/Account/LoginPost.php +++ b/app/code/Magento/Customer/Controller/Account/LoginPost.php @@ -217,17 +217,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.')); } } diff --git a/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php b/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php index 27a00f86dd95d..a127f2acf538f 100644 --- a/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php +++ b/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php @@ -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; @@ -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]); diff --git a/app/code/Magento/Customer/Controller/Address/Delete.php b/app/code/Magento/Customer/Controller/Address/Delete.php index a30e15db4b3f8..c90489bfc978e 100644 --- a/app/code/Magento/Customer/Controller/Address/Delete.php +++ b/app/code/Magento/Customer/Controller/Address/Delete.php @@ -27,12 +27,12 @@ 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.')); + $this->messageManager->addExceptionMessage($other, __('We can\'t delete the address right now.')); } } return $this->resultRedirectFactory->create()->setPath('*/*/index'); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php b/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php index b69410ecbfce7..7747d80595cdc 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php @@ -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; diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php index ab32ea08a44aa..819a49178a24d 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php @@ -24,12 +24,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]); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php index 5ffce4cbcd989..64c94fa230fb1 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php @@ -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( diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index.php b/app/code/Magento/Customer/Controller/Adminhtml/Index.php index a0317a51260da..ffae1e9f8bf1e 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index.php @@ -311,7 +311,7 @@ protected function _addSessionErrorMessages($messages) protected function actUponMultipleCustomers(callable $singleAction, $customerIds) { if (!is_array($customerIds)) { - $this->messageManager->addError(__('Please select customer(s).')); + $this->messageManager->addErrorMessage(__('Please select customer(s).')); return 0; } $customersUpdated = 0; @@ -320,7 +320,7 @@ protected function actUponMultipleCustomers(callable $singleAction, $customerIds $singleAction($customerId); $customersUpdated++; } catch (\Exception $exception) { - $this->messageManager->addError($exception->getMessage()); + $this->messageManager->addErrorMessage($exception->getMessage()); } } return $customersUpdated; diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/AbstractMassAction.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/AbstractMassAction.php index e26b49aaebe7a..08c6e5148ade5 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/AbstractMassAction.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/AbstractMassAction.php @@ -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); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php index ab39ca098162f..4b2f2614948cf 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php @@ -31,7 +31,7 @@ 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'); } @@ -39,9 +39,9 @@ public function execute() 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()); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php index 25b4ddd4e1732..d4697ecd6169c 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php @@ -43,7 +43,7 @@ public function execute() //do nothing } } catch (NoSuchEntityException $e) { - $this->messageManager->addException($e, __('Something went wrong while editing the customer.')); + $this->messageManager->addExceptionMessage($e, __('Something went wrong while editing the customer.')); $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('customer/*/index'); return $resultRedirect; diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php index 7220de0356817..41d2c43bdaf75 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php @@ -234,13 +234,13 @@ protected function saveCustomer(CustomerInterface $customer) $this->disableAddressValidation($customer); $this->customerRepository->save($customer); } catch (\Magento\Framework\Exception\InputException $e) { - $this->getMessageManager()->addError($this->getErrorWithCustomerId($e->getMessage())); + $this->getMessageManager()->addErrorMessage($this->getErrorWithCustomerId($e->getMessage())); $this->logger->critical($e); } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->getMessageManager()->addError($this->getErrorWithCustomerId($e->getMessage())); + $this->getMessageManager()->addErrorMessage($this->getErrorWithCustomerId($e->getMessage())); $this->logger->critical($e); } catch (\Exception $e) { - $this->getMessageManager()->addError($this->getErrorWithCustomerId('We can\'t save the customer.')); + $this->getMessageManager()->addErrorMessage($this->getErrorWithCustomerId('We can\'t save the customer.')); $this->logger->critical($e); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php index 5a9c52bf9b1c0..f55c81da7e0b9 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php @@ -60,7 +60,7 @@ protected function massAction(AbstractCollection $collection) } if ($customersUpdated) { - $this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); + $this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php index edaeea6a15eb2..85286573bc5e7 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php @@ -58,7 +58,7 @@ protected function massAction(AbstractCollection $collection) } if ($customersDeleted) { - $this->messageManager->addSuccess(__('A total of %1 record(s) were deleted.', $customersDeleted)); + $this->messageManager->addSuccessMessage(__('A total of %1 record(s) were deleted.', $customersDeleted)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php index 25c56ac60c14b..e072c5cb4cd49 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php @@ -64,7 +64,7 @@ protected function massAction(AbstractCollection $collection) } if ($customersUpdated) { - $this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); + $this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php index 4b40722ba9ab2..e52c9a772ed2d 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php @@ -64,7 +64,7 @@ protected function massAction(AbstractCollection $collection) } if ($customersUpdated) { - $this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); + $this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php index 1e4fa91cbf899..3b9370c32bf6d 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php @@ -44,7 +44,9 @@ public function execute() \Magento\Customer\Model\AccountManagement::EMAIL_REMINDER, $customer->getWebsiteId() ); - $this->messageManager->addSuccess(__('The customer will receive an email with a link to reset password.')); + $this->messageManager->addSuccessMessage( + __('The customer will receive an email with a link to reset password.') + ); } catch (NoSuchEntityException $exception) { $resultRedirect->setPath('customer/index'); return $resultRedirect; @@ -57,7 +59,7 @@ public function execute() } catch (SecurityViolationException $exception) { $this->messageManager->addErrorMessage($exception->getMessage()); } catch (\Exception $exception) { - $this->messageManager->addException( + $this->messageManager->addExceptionMessage( $exception, __('Something went wrong while resetting customer password.') ); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php index 38ed688a835bc..3ee33af9ec073 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php @@ -354,7 +354,7 @@ public function execute() $this->_getSession()->unsCustomerFormData(); // Done Saving customer, finish save action $this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId); - $this->messageManager->addSuccess(__('You saved the customer.')); + $this->messageManager->addSuccessMessage(__('You saved the customer.')); $returnToEdit = (bool)$this->getRequest()->getParam('back', false); } catch (\Magento\Framework\Validator\Exception $exception) { $messages = $exception->getMessages(); @@ -378,7 +378,10 @@ public function execute() $this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData()); $returnToEdit = true; } catch (\Exception $exception) { - $this->messageManager->addException($exception, __('Something went wrong while saving the customer.')); + $this->messageManager->addExceptionMessage( + $exception, + __('Something went wrong while saving the customer.') + ); $this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData()); $returnToEdit = true; } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Locks/Unlock.php b/app/code/Magento/Customer/Controller/Adminhtml/Locks/Unlock.php index 1fd06a3182948..2747ba1a665fd 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Locks/Unlock.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Locks/Unlock.php @@ -55,10 +55,10 @@ public function execute() // unlock customer if ($customerId) { $this->authentication->unlock($customerId); - $this->getMessageManager()->addSuccess(__('Customer has been unlocked successfully.')); + $this->getMessageManager()->addSuccessMessage(__('Customer has been unlocked successfully.')); } } catch (\Exception $e) { - $this->messageManager->addError($e->getMessage()); + $this->messageManager->addErrorMessage($e->getMessage()); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ diff --git a/app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php b/app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php index 41311abee5da8..8677abfa89904 100644 --- a/app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php +++ b/app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php @@ -255,7 +255,7 @@ protected function addValidMessage($customerAddress, $validationResult) : (string)__('You will not be charged tax.'); } - $this->messageManager->addSuccess(implode(' ', $message)); + $this->messageManager->addSuccessMessage(implode(' ', $message)); return $this; } @@ -280,7 +280,7 @@ protected function addInvalidMessage($customerAddress) $message[] = (string)__('You will be charged tax.'); } - $this->messageManager->addError(implode(' ', $message)); + $this->messageManager->addErrorMessage(implode(' ', $message)); return $this; } @@ -307,7 +307,7 @@ protected function addErrorMessage($customerAddress) $email = $this->scopeConfig->getValue('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE); $message[] = (string)__('If you believe this is an error, please contact us at %1', $email); - $this->messageManager->addError(implode(' ', $message)); + $this->messageManager->addErrorMessage(implode(' ', $message)); return $this; } From e56a4c7a62e346472c433f41dabcd320a2ca4cdf Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Tue, 20 Aug 2019 10:02:26 +0300 Subject: [PATCH 02/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento_Customer module Fix. Unit tests --- .../Test/Unit/Controller/Account/ConfirmTest.php | 6 +++--- .../Test/Unit/Controller/Account/CreatePostTest.php | 4 ++-- .../Test/Unit/Controller/Account/LoginPostTest.php | 10 +++++----- .../Test/Unit/Controller/Address/DeleteTest.php | 6 +++--- .../Unit/Controller/Adminhtml/Group/SaveTest.php | 4 ++-- .../Controller/Adminhtml/Index/InlineEditTest.php | 4 ++-- .../Adminhtml/Index/MassAssignGroupTest.php | 4 ++-- .../Controller/Adminhtml/Index/MassDeleteTest.php | 4 ++-- .../Controller/Adminhtml/Index/MassSubscribeTest.php | 4 ++-- .../Adminhtml/Index/MassUnsubscribeTest.php | 4 ++-- .../Controller/Adminhtml/Index/NewsletterTest.php | 2 +- .../Controller/Adminhtml/Index/ResetPasswordTest.php | 6 +++--- .../Unit/Controller/Adminhtml/Index/SaveTest.php | 12 ++++++------ .../Unit/Controller/Adminhtml/Locks/UnlockTest.php | 4 ++-- .../Unit/Observer/AfterAddressSaveObserverTest.php | 6 +++--- 15 files changed, 40 insertions(+), 40 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php index 01fc465d4ae84..0684594d510d7 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php @@ -205,7 +205,7 @@ public function testNoCustomerIdInRequest($customerId, $key) $exception = new \Exception('Bad request.'); $this->messageManagerMock->expects($this->once()) - ->method('addException') + ->method('addExceptionMessage') ->with($this->equalTo($exception), $this->equalTo('There was an error confirming the account')); $testUrl = 'http://example.com'; @@ -281,7 +281,7 @@ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $ad ->willReturnSelf(); $this->messageManagerMock->expects($this->any()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with($this->stringContains($successMessage)) ->willReturnSelf(); @@ -399,7 +399,7 @@ public function testSuccessRedirect( ->willReturnSelf(); $this->messageManagerMock->expects($this->any()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with($this->stringContains($successMessage)) ->willReturnSelf(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php index f8f47eedba3ef..ac52c395d6787 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php @@ -371,7 +371,7 @@ public function testSuccessMessage( ->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with($this->stringContains($successMessage)) ->will($this->returnSelf()); @@ -502,7 +502,7 @@ public function testSuccessRedirect( ->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with($this->stringContains($successMessage)) ->will($this->returnSelf()); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php index 762c76b695dee..51b84d807dc13 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php @@ -222,7 +222,7 @@ public function testExecuteEmptyLoginData() ->willReturn([]); $this->messageManager->expects($this->once()) - ->method('addError') + ->method('addErrorMessage') ->with(__('A login and a password are required.')) ->willReturnSelf(); @@ -551,7 +551,7 @@ protected function mockExceptions($exception, $username) $url ); $this->messageManager->expects($this->once()) - ->method('addError') + ->method('addErrorMessage') ->with($message) ->willReturnSelf(); @@ -563,7 +563,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. ' @@ -580,7 +580,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; @@ -591,7 +591,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()) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php index 4064b8586257d..7424b0f649fdc 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php @@ -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') @@ -183,11 +183,11 @@ 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()) - ->method('addException') + ->method('addExceptionMessage') ->with($exception, __('We can\'t delete the address right now.')); $this->resultRedirect->expects($this->once()) ->method('setPath') diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php index 5f7064d5b124b..c9f885315b0ef 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php @@ -167,7 +167,7 @@ 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)) @@ -175,7 +175,7 @@ public function testExecuteWithTaxClassAndException() ->with('customer/group') ->willThrowException($exception); $this->messageManager->expects($this->once()) - ->method('addError') + ->method('addErrorMessage') ->with('Exception'); $this->dataObjectProcessorMock->expects($this->once()) ->method('buildOutputDataArray') diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php index 45e64f6557d51..c198eb3a212fa 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php @@ -366,7 +366,7 @@ public function testExecuteLocalizedException() ->with($this->customerData) ->willThrowException($exception); $this->messageManager->expects($this->once()) - ->method('addError') + ->method('addErrorMessage') ->with('[Customer ID: 12] Exception message'); $this->logger->expects($this->once()) ->method('critical') @@ -394,7 +394,7 @@ public function testExecuteException() ->with($this->customerData) ->willThrowException($exception); $this->messageManager->expects($this->once()) - ->method('addError') + ->method('addErrorMessage') ->with('[Customer ID: 12] We can\'t save the customer.'); $this->logger->expects($this->once()) ->method('critical') diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassAssignGroupTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassAssignGroupTest.php index 10144bdc318c1..4157359959ae4 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassAssignGroupTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassAssignGroupTest.php @@ -170,7 +170,7 @@ public function testExecute() ->willReturnMap([[10, $customerMock], [11, $customerMock], [12, $customerMock]]); $this->messageManagerMock->expects($this->once()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with(__('A total of %1 record(s) were updated.', count($customersIds))); $this->resultRedirectMock->expects($this->any()) @@ -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(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassDeleteTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassDeleteTest.php index 190ff2c06618f..b436b5b137c78 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassDeleteTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassDeleteTest.php @@ -155,7 +155,7 @@ public function testExecute() ->willReturnMap([[10, true], [11, true], [12, true]]); $this->messageManagerMock->expects($this->once()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with(__('A total of %1 record(s) were deleted.', count($customersIds))); $this->resultRedirectMock->expects($this->any()) @@ -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(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassSubscribeTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassSubscribeTest.php index daf9c64fe7b7b..33e578224400b 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassSubscribeTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassSubscribeTest.php @@ -171,7 +171,7 @@ public function testExecute() ->willReturnMap([[10, true], [11, true], [12, true]]); $this->messageManagerMock->expects($this->once()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with(__('A total of %1 record(s) were updated.', count($customersIds))); $this->resultRedirectMock->expects($this->any()) @@ -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(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassUnsubscribeTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassUnsubscribeTest.php index 05624661a2de4..971efc0e490bc 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassUnsubscribeTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassUnsubscribeTest.php @@ -171,7 +171,7 @@ public function testExecute() ->willReturnMap([[10, true], [11, true], [12, true]]); $this->messageManagerMock->expects($this->once()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with(__('A total of %1 record(s) were updated.', count($customersIds))); $this->resultRedirectMock->expects($this->any()) @@ -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(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/NewsletterTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/NewsletterTest.php index d2f8b8776081e..5ec39360000cb 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/NewsletterTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/NewsletterTest.php @@ -150,7 +150,7 @@ protected function setUp() $this->messageManager = $this->getMockBuilder( \Magento\Framework\Message\Manager::class )->disableOriginalConstructor()->setMethods( - ['addSuccess', 'addMessage', 'addException'] + ['addSuccessMessage', 'addMessageMessage', 'addExceptionMessage'] )->getMock(); $contextArgs = [ diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php index 66e5b57eaa424..67ac60e6b9057 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php @@ -141,7 +141,7 @@ protected function setUp() $this->messageManager = $this->getMockBuilder( \Magento\Framework\Message\Manager::class )->disableOriginalConstructor()->setMethods( - ['addSuccess', 'addMessage', 'addException', 'addErrorMessage'] + ['addSuccessMessage', 'addMessage', 'addExceptionMessage', 'addErrorMessage'] )->getMock(); $this->resultRedirectFactoryMock = $this->getMockBuilder( @@ -442,7 +442,7 @@ public function testResetPasswordActionException() $this->messageManager->expects( $this->once() )->method( - 'addException' + 'addExceptionMessage' )->with( $this->equalTo($exception), $this->equalTo('Something went wrong while resetting customer password.') @@ -502,7 +502,7 @@ public function testResetPasswordActionSendEmail() $this->messageManager->expects( $this->once() )->method( - 'addSuccess' + 'addSuccessMessage' )->with( $this->equalTo('The customer will receive an email with a link to reset password.') ); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php index 57f384d32d980..5f34583c855c1 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php @@ -475,7 +475,7 @@ public function testExecuteWithExistentCustomer() ->with(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId); $this->messageManagerMock->expects($this->once()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with(__('You saved the customer.')) ->willReturnSelf(); @@ -662,7 +662,7 @@ public function testExecuteWithNewCustomer() ->with(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId); $this->messageManagerMock->expects($this->once()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with(__('You saved the customer.')) ->willReturnSelf(); @@ -804,7 +804,7 @@ public function testExecuteWithNewCustomerAndValidationException() ->method('register'); $this->messageManagerMock->expects($this->never()) - ->method('addSuccess'); + ->method('addSuccessMessage'); $this->messageManagerMock->expects($this->once()) ->method('addMessage') @@ -951,7 +951,7 @@ public function testExecuteWithNewCustomerAndLocalizedException() ->method('register'); $this->messageManagerMock->expects($this->never()) - ->method('addSuccess'); + ->method('addSuccessMessage'); $this->messageManagerMock->expects($this->once()) ->method('addMessage') @@ -1099,10 +1099,10 @@ public function testExecuteWithNewCustomerAndException() ->method('register'); $this->messageManagerMock->expects($this->never()) - ->method('addSuccess'); + ->method('addSuccessMessage'); $this->messageManagerMock->expects($this->once()) - ->method('addException') + ->method('addExceptionMessage') ->with($exception, __('Something went wrong while saving the customer.')); $this->sessionMock->expects($this->once()) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Locks/UnlockTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Locks/UnlockTest.php index c92d4ed7812ba..55b4092af7141 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Locks/UnlockTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Locks/UnlockTest.php @@ -118,7 +118,7 @@ public function testExecute() ->with($this->equalTo('customer_id')) ->will($this->returnValue($customerId)); $this->authenticationMock->expects($this->once())->method('unlock')->with($customerId); - $this->messageManagerMock->expects($this->once())->method('addSuccess'); + $this->messageManagerMock->expects($this->once())->method('addSuccessMessage'); $this->redirectMock->expects($this->once()) ->method('setPath') ->with($this->equalTo('customer/index/edit')) @@ -141,7 +141,7 @@ public function testExecuteWithException() ->method('unlock') ->with($customerId) ->willThrowException(new \Exception($phrase)); - $this->messageManagerMock->expects($this->once())->method('addError'); + $this->messageManagerMock->expects($this->once())->method('addErrorMessage'); $this->controller->execute(); } } diff --git a/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php b/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php index 8592d1bda66c1..4501b611aa11f 100644 --- a/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php +++ b/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php @@ -575,7 +575,7 @@ public function testAfterAddressSaveNewGroup( if ($resultValidMessage) { $this->messageManager->expects($this->once()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with($resultValidMessage) ->willReturnSelf(); } @@ -585,7 +585,7 @@ public function testAfterAddressSaveNewGroup( ->with($vatId) ->willReturn($vatId); $this->messageManager->expects($this->once()) - ->method('addError') + ->method('addErrorMessage') ->with($resultInvalidMessage) ->willReturnSelf(); } @@ -595,7 +595,7 @@ public function testAfterAddressSaveNewGroup( ->with('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE) ->willReturn('admin@example.com'); $this->messageManager->expects($this->once()) - ->method('addError') + ->method('addErrorMessage') ->with($resultErrorMessage) ->willReturnSelf(); } From 3a04bb7564bdb6da33aed7ebf886149d87d612e0 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 21 Aug 2019 15:20:23 +0300 Subject: [PATCH 03/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento_Customer module --- .../Customer/Controller/Account/CreatePost.php | 12 +++++------- app/code/Magento/Customer/etc/frontend/di.xml | 14 +++++++++++++- .../customerAlreadyExistsErrorMessage.phtml | 10 ++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 app/code/Magento/Customer/view/frontend/templates/messages/customerAlreadyExistsErrorMessage.phtml diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index 510d82879637f..3a6c1945eb9de 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -394,14 +394,12 @@ public function execute() return $resultRedirect; } catch (StateException $e) { - $url = $this->urlModel->getUrl('customer/account/forgotpassword'); - // @codingStandardsIgnoreStart - $message = __( - 'There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account.', - $url + $this->messageManager->addComplexErrorMessage( + 'customerAlreadyExistsErrorMessage', + [ + 'url' => $this->urlModel->getUrl('customer/account/forgotpassword'), + ] ); - // @codingStandardsIgnoreEnd - $this->messageManager->addErrorMessage($message); } catch (InputException $e) { $this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage())); foreach ($e->getErrors() as $error) { diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index c31742519e581..db6f2a6fc5318 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -77,4 +77,16 @@ - \ No newline at end of file + + + + + \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE + + Magento_Customer::messages/customerAlreadyExistsErrorMessage.phtml + + + + + + diff --git a/app/code/Magento/Customer/view/frontend/templates/messages/customerAlreadyExistsErrorMessage.phtml b/app/code/Magento/Customer/view/frontend/templates/messages/customerAlreadyExistsErrorMessage.phtml new file mode 100644 index 0000000000000..27ffc1433a368 --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/templates/messages/customerAlreadyExistsErrorMessage.phtml @@ -0,0 +1,10 @@ + + +escapeHtml(__('There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account.', $block->getData('url')), ['a']); From 444fb5c24fd6ef5e3ac647b08d1e6f2fecf5cfda Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 21 Aug 2019 18:03:56 +0300 Subject: [PATCH 04/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento_Customer --- .../Customer/Controller/Account/CreatePost.php | 14 ++++++-------- .../Magento/Customer/Controller/Address/Delete.php | 2 +- app/code/Magento/Customer/etc/frontend/di.xml | 12 ++++++++++++ .../messages/confirmAccountSuccessMessage.phtml | 10 ++++++++++ .../messages/unableDeleteAddressMessage.phtml | 10 ++++++++++ 5 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 app/code/Magento/Customer/view/frontend/templates/messages/confirmAccountSuccessMessage.phtml create mode 100644 app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index 3a6c1945eb9de..6c65d8c8d282c 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -364,15 +364,13 @@ public function execute() ); $confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) { - $email = $this->customerUrl->getEmailConfirmationUrl($customer->getEmail()); - // @codingStandardsIgnoreStart - $this->messageManager->addSuccessMessage( - __( - 'You must confirm your account. Please check your email for the confirmation link or click here for a new link.', - $email - ) + $this->messageManager->addComplexSuccessMessage( + 'confirmAccountSuccessMessage', + [ + 'url' => $this->customerUrl->getEmailConfirmationUrl($customer->getEmail()), + ] ); - // @codingStandardsIgnoreEnd + $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); $resultRedirect->setUrl($this->_redirect->success($url)); } else { diff --git a/app/code/Magento/Customer/Controller/Address/Delete.php b/app/code/Magento/Customer/Controller/Address/Delete.php index c90489bfc978e..188ed31bed0ab 100644 --- a/app/code/Magento/Customer/Controller/Address/Delete.php +++ b/app/code/Magento/Customer/Controller/Address/Delete.php @@ -29,7 +29,7 @@ public function execute() $this->_addressRepository->deleteById($addressId); $this->messageManager->addSuccessMessage(__('You deleted the address.')); } else { - $this->messageManager->addErrorMessage(__('We can\'t delete the address right now.')); + $this->messageManager->addComplexErrorMessage('unableDeleteAddressMessage'); } } catch (\Exception $other) { $this->messageManager->addExceptionMessage($other, __('We can\'t delete the address right now.')); diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index db6f2a6fc5318..e43bc4af1fcae 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -86,6 +86,18 @@ Magento_Customer::messages/customerAlreadyExistsErrorMessage.phtml + + \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE + + Magento_Customer::messages/confirmAccountSuccessMessage.phtml + + + + \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE + + Magento_Customer::messages/unableDeleteAddressMessage.phtml + + diff --git a/app/code/Magento/Customer/view/frontend/templates/messages/confirmAccountSuccessMessage.phtml b/app/code/Magento/Customer/view/frontend/templates/messages/confirmAccountSuccessMessage.phtml new file mode 100644 index 0000000000000..3356c1248b37e --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/templates/messages/confirmAccountSuccessMessage.phtml @@ -0,0 +1,10 @@ + + +escapeHtml(__('You must confirm your account. Please check your email for the confirmation link or click here for a new link.', $block->getData('url')), ['a']); diff --git a/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml b/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml new file mode 100644 index 0000000000000..c49a1d4e46420 --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml @@ -0,0 +1,10 @@ + + +escapeHtml(__('We can\'t delete the address right now.')); From c7436240a4802b45b9fadab1039c8d63a8fd7005 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 21 Aug 2019 19:09:54 +0300 Subject: [PATCH 05/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento_Customer --- app/code/Magento/Customer/Controller/Address/Delete.php | 2 +- app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Controller/Address/Delete.php b/app/code/Magento/Customer/Controller/Address/Delete.php index 188ed31bed0ab..9df06c69d4a88 100644 --- a/app/code/Magento/Customer/Controller/Address/Delete.php +++ b/app/code/Magento/Customer/Controller/Address/Delete.php @@ -32,7 +32,7 @@ public function execute() $this->messageManager->addComplexErrorMessage('unableDeleteAddressMessage'); } } catch (\Exception $other) { - $this->messageManager->addExceptionMessage($other, __('We can\'t delete the address right now.')); + $this->messageManager->addException($other, __('We can\'t delete the address right now.')); } } return $this->resultRedirectFactory->create()->setPath('*/*/index'); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php index 64c94fa230fb1..bb3589a75f721 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php @@ -96,7 +96,7 @@ public function execute() $this->messageManager->addSuccessMessage(__('You saved the customer group.')); $resultRedirect->setPath('customer/group'); } catch (\Exception $e) { - $this->messageManager->addErrorMessage($e->getMessage()); + $this->messageManager->addError($e->getMessage()); if ($customerGroup != null) { $this->storeCustomerGroupDataToSession( $this->dataObjectProcessor->buildOutputDataArray( From 0bf86e6a094e56ff945fc39a48459cfb574c6b0c Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 21 Aug 2019 23:27:51 +0300 Subject: [PATCH 06/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento_Customer --- .../Customer/Controller/Account/Confirm.php | 4 +- .../Controller/Account/Confirmation.php | 4 +- .../Customer/Controller/Account/LoginPost.php | 1 + .../Controller/Adminhtml/Group/Delete.php | 4 +- .../Adminhtml/Index/AbstractMassAction.php | 1 + .../Controller/Adminhtml/Index/Edit.php | 16 +- .../Controller/Adminhtml/Index/InlineEdit.php | 20 ++- .../Unit/Controller/Account/ConfirmTest.php | 22 +-- .../Controller/Account/CreatePostTest.php | 34 +++-- .../Unit/Controller/Account/LoginPostTest.php | 54 ++++--- .../Unit/Controller/Address/DeleteTest.php | 2 +- .../Controller/Adminhtml/Group/SaveTest.php | 2 +- .../Adminhtml/Index/InlineEditTest.php | 20 ++- .../Controller/Adminhtml/Index/SaveTest.php | 80 ++++++---- .../Observer/AfterAddressSaveObserverTest.php | 138 ++++++++++-------- .../confirmAccountSuccessMessage.phtml | 1 - .../messages/unableDeleteAddressMessage.phtml | 1 - 17 files changed, 239 insertions(+), 165 deletions(-) diff --git a/app/code/Magento/Customer/Controller/Account/Confirm.php b/app/code/Magento/Customer/Controller/Account/Confirm.php index 4f0fb3ff08550..3b19a8b33512a 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirm.php +++ b/app/code/Magento/Customer/Controller/Account/Confirm.php @@ -151,7 +151,9 @@ public function execute() $customerId = $this->getRequest()->getParam('id', false); $key = $this->getRequest()->getParam('key', false); if (empty($customerId) || empty($key)) { - throw new \Exception(__('Bad request.')); + $this->messageManager->addErrorMessage(__('Bad request.')); + $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); + return $resultRedirect->setUrl($this->_redirect->error($url)); } // log in and send greeting email diff --git a/app/code/Magento/Customer/Controller/Account/Confirmation.php b/app/code/Magento/Customer/Controller/Account/Confirmation.php index bd9066dcd464a..aebc0547f3536 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirmation.php +++ b/app/code/Magento/Customer/Controller/Account/Confirmation.php @@ -1,6 +1,5 @@ _customerRepository->getById($customerId); $customerData['account'] = $this->customerMapper->toFlatArray($customer); $customerData['account'][CustomerInterface::ID] = $customerId; - try { - $addresses = $customer->getAddresses(); - foreach ($addresses as $address) { - $customerData['address'][$address->getId()] = $this->addressMapper->toFlatArray($address); - $customerData['address'][$address->getId()]['id'] = $address->getId(); - } - } catch (NoSuchEntityException $e) { - //do nothing + + $addresses = $customer->getAddresses(); + foreach ($addresses as $address) { + $customerData['address'][$address->getId()] = $this->addressMapper->toFlatArray($address); + $customerData['address'][$address->getId()]['id'] = $address->getId(); } } catch (NoSuchEntityException $e) { $this->messageManager->addExceptionMessage($e, __('Something went wrong while editing the customer.')); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php index 41d2c43bdaf75..ba8c84a0ac273 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php @@ -128,10 +128,12 @@ public function execute() $postItems = $this->getRequest()->getParam('items', []); if (!($this->getRequest()->getParam('isAjax') && count($postItems))) { - return $resultJson->setData([ - 'messages' => [__('Please correct the data sent.')], - 'error' => true, - ]); + return $resultJson->setData( + [ + 'messages' => [__('Please correct the data sent.')], + 'error' => true, + ] + ); } foreach (array_keys($postItems) as $customerId) { @@ -147,10 +149,12 @@ public function execute() $this->getEmailNotification()->credentialsChanged($this->getCustomer(), $currentCustomer->getEmail()); } - return $resultJson->setData([ - 'messages' => $this->getErrorMessages(), - 'error' => $this->isErrorExists() - ]); + return $resultJson->setData( + [ + 'messages' => $this->getErrorMessages(), + 'error' => $this->isErrorExists() + ] + ); } /** diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php index 0684594d510d7..335d1068206b3 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php @@ -255,10 +255,12 @@ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $ad $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap([ - ['id', false, $customerId], - ['key', false, $key], - ]); + ->willReturnMap( + [ + ['id', false, $customerId], + ['key', false, $key], + ] + ); $this->customerRepositoryMock->expects($this->any()) ->method('getById') @@ -372,11 +374,13 @@ public function testSuccessRedirect( $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap([ - ['id', false, $customerId], - ['key', false, $key], - ['back_url', false, $backUrl], - ]); + ->willReturnMap( + [ + ['id', false, $customerId], + ['key', false, $key], + ['back_url', false, $backUrl], + ] + ); $this->customerRepositoryMock->expects($this->any()) ->method('getById') diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php index ac52c395d6787..faf55347dba78 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php @@ -346,11 +346,13 @@ public function testSuccessMessage( $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap([ - ['password', null, $password], - ['password_confirmation', null, $password], - ['is_subscribed', false, true], - ]); + ->willReturnMap( + [ + ['password', null, $password], + ['password_confirmation', null, $password], + ['is_subscribed', false, true], + ] + ); $this->customerMock->expects($this->once()) ->method('setAddresses') @@ -477,11 +479,13 @@ public function testSuccessRedirect( $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap([ - ['password', null, $password], - ['password_confirmation', null, $password], - ['is_subscribed', false, true], - ]); + ->willReturnMap( + [ + ['password', null, $password], + ['password_confirmation', null, $password], + ['is_subscribed', false, true], + ] + ); $this->customerMock->expects($this->once()) ->method('setAddresses') @@ -508,10 +512,12 @@ public function testSuccessRedirect( $this->urlMock->expects($this->any()) ->method('getUrl') - ->willReturnMap([ - ['*/*/index', ['_secure' => true], $successUrl], - ['*/*/create', ['_secure' => true], $successUrl], - ]); + ->willReturnMap( + [ + ['*/*/index', ['_secure' => true], $successUrl], + ['*/*/create', ['_secure' => true], $successUrl], + ] + ); $this->redirectMock->expects($this->once()) ->method('success') ->with($this->equalTo($successUrl)) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php index 51b84d807dc13..fd70a55ad7def 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php @@ -93,12 +93,14 @@ protected function setUp() $this->session = $this->getMockBuilder(\Magento\Customer\Model\Session::class) ->disableOriginalConstructor() - ->setMethods([ - 'isLoggedIn', - 'setCustomerDataAsLoggedIn', - 'regenerateId', - 'setUsername', - ]) + ->setMethods( + [ + 'isLoggedIn', + 'setCustomerDataAsLoggedIn', + 'regenerateId', + 'setUsername', + ] + ) ->getMock(); $this->accountManagement = $this->getMockBuilder(\Magento\Customer\Api\AccountManagementInterface::class) @@ -253,10 +255,12 @@ public function testExecuteSuccessCustomRedirect() $this->request->expects($this->once()) ->method('getPost') ->with('login') - ->willReturn([ - 'username' => $username, - 'password' => $password, - ]); + ->willReturn( + [ + 'username' => $username, + 'password' => $password, + ] + ); $customerMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class) ->getMockForAbstractClass(); @@ -335,10 +339,12 @@ public function testExecuteSuccess() $this->request->expects($this->once()) ->method('getPost') ->with('login') - ->willReturn([ - 'username' => $username, - 'password' => $password, - ]); + ->willReturn( + [ + 'username' => $username, + 'password' => $password, + ] + ); $customerMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class) ->getMockForAbstractClass(); @@ -426,10 +432,12 @@ public function testExecuteWithException( $this->request->expects($this->once()) ->method('getPost') ->with('login') - ->willReturn([ - 'username' => $username, - 'password' => $password, - ]); + ->willReturn( + [ + 'username' => $username, + 'password' => $password, + ] + ); $exception = new $exceptionData['exception'](__($exceptionData['message'])); @@ -488,10 +496,12 @@ protected function prepareContext() $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) ->disableOriginalConstructor() - ->setMethods([ - 'isPost', - 'getPost', - ]) + ->setMethods( + [ + 'isPost', + 'getPost', + ] + ) ->getMock(); $this->resultRedirect = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php index 7424b0f649fdc..3634aaf469f9b 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php @@ -183,7 +183,7 @@ public function testExecuteWithException() ->willReturn(34); $exception = new \Exception('Exception'); $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addComplexErrorMessage') ->with(__('We can\'t delete the address right now.')) ->willThrowException($exception); $this->messageManager->expects($this->once()) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php index c9f885315b0ef..b0b8075325f8b 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php @@ -175,7 +175,7 @@ public function testExecuteWithTaxClassAndException() ->with('customer/group') ->willThrowException($exception); $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with('Exception'); $this->dataObjectProcessorMock->expects($this->once()) ->method('buildOutputDataArray') diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php index c198eb3a212fa..769c77dfcb4ea 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php @@ -291,10 +291,12 @@ protected function prepareMocksForErrorMessagesProcessing() ->willReturn('Error text'); $this->resultJson->expects($this->once()) ->method('setData') - ->with([ - 'messages' => ['Error text'], - 'error' => true, - ]) + ->with( + [ + 'messages' => ['Error text'], + 'error' => true, + ] + ) ->willReturnSelf(); } @@ -340,10 +342,12 @@ public function testExecuteWithoutItems() $this->resultJson ->expects($this->once()) ->method('setData') - ->with([ - 'messages' => [__('Please correct the data sent.')], - 'error' => true, - ]) + ->with( + [ + 'messages' => [__('Please correct the data sent.')], + 'error' => true, + ] + ) ->willReturnSelf(); $this->assertSame($this->resultJson, $this->controller->execute()); } diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php index 5f34583c855c1..9724ac13dde8c 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php @@ -338,10 +338,12 @@ public function testExecuteWithExistentCustomer() $this->requestMock->expects($this->atLeastOnce()) ->method('getPostValue') - ->willReturnMap([ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ]); + ->willReturnMap( + [ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ] + ); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -542,10 +544,12 @@ public function testExecuteWithNewCustomer() $this->requestMock->expects($this->any()) ->method('getPostValue') - ->willReturnMap([ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ]); + ->willReturnMap( + [ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ] + ); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -723,10 +727,12 @@ public function testExecuteWithNewCustomerAndValidationException() $this->requestMock->expects($this->any()) ->method('getPostValue') - ->willReturnMap([ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ]); + ->willReturnMap( + [ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ] + ); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -812,10 +818,12 @@ public function testExecuteWithNewCustomerAndValidationException() $this->sessionMock->expects($this->once()) ->method('setCustomerFormData') - ->with([ - 'customer' => $extractedData, - 'subscription' => $subscription, - ]); + ->with( + [ + 'customer' => $extractedData, + 'subscription' => $subscription, + ] + ); /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) @@ -870,10 +878,12 @@ public function testExecuteWithNewCustomerAndLocalizedException() $this->requestMock->expects($this->any()) ->method('getPostValue') - ->willReturnMap([ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ]); + ->willReturnMap( + [ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ] + ); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -959,10 +969,12 @@ public function testExecuteWithNewCustomerAndLocalizedException() $this->sessionMock->expects($this->once()) ->method('setCustomerFormData') - ->with([ - 'customer' => $extractedData, - 'subscription' => $subscription, - ]); + ->with( + [ + 'customer' => $extractedData, + 'subscription' => $subscription, + ] + ); /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) @@ -1017,10 +1029,12 @@ public function testExecuteWithNewCustomerAndException() $this->requestMock->expects($this->any()) ->method('getPostValue') - ->willReturnMap([ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ]); + ->willReturnMap( + [ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ] + ); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -1107,10 +1121,12 @@ public function testExecuteWithNewCustomerAndException() $this->sessionMock->expects($this->once()) ->method('setCustomerFormData') - ->with([ - 'customer' => $extractedData, - 'subscription' => $subscription, - ]); + ->with( + [ + 'customer' => $extractedData, + 'subscription' => $subscription, + ] + ); /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) diff --git a/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php b/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php index 4501b611aa11f..79766178a7670 100644 --- a/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php +++ b/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php @@ -210,9 +210,11 @@ public function testAfterAddressSaveRestricted( $observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class) ->disableOriginalConstructor() - ->setMethods([ - 'getCustomerAddress', - ]) + ->setMethods( + [ + 'getCustomerAddress', + ] + ) ->getMock(); $observer->expects($this->once()) ->method('getCustomerAddress') @@ -225,10 +227,12 @@ public function testAfterAddressSaveRestricted( $this->registry->expects($this->any()) ->method('registry') - ->willReturnMap([ - [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, $processedFlag], - [BeforeAddressSaveObserver::VIV_CURRENTLY_SAVED_ADDRESS, $registeredAddressId], - ]); + ->willReturnMap( + [ + [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, $processedFlag], + [BeforeAddressSaveObserver::VIV_CURRENTLY_SAVED_ADDRESS, $registeredAddressId], + ] + ); $this->helperAddress->expects($this->any()) ->method('getTaxCalculationAddressType') @@ -266,11 +270,13 @@ public function testAfterAddressSaveException() $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class) ->disableOriginalConstructor() - ->setMethods([ - 'getCustomer', - 'getForceProcess', - 'getVatId', - ]) + ->setMethods( + [ + 'getCustomer', + 'getForceProcess', + 'getVatId', + ] + ) ->getMock(); $address->expects($this->any()) ->method('getCustomer') @@ -284,9 +290,11 @@ public function testAfterAddressSaveException() $observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class) ->disableOriginalConstructor() - ->setMethods([ - 'getCustomerAddress', - ]) + ->setMethods( + [ + 'getCustomerAddress', + ] + ) ->getMock(); $observer->expects($this->once()) ->method('getCustomerAddress') @@ -303,10 +311,12 @@ public function testAfterAddressSaveException() ->willReturn(false); $this->registry->expects($this->any()) ->method('register') - ->willReturnMap([ - [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, true, false, $this->registry], - [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, false, true, $this->registry], - ]); + ->willReturnMap( + [ + [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, true, false, $this->registry], + [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, false, true, $this->registry], + ] + ); $this->model->execute($observer); } @@ -336,13 +346,15 @@ public function testAfterAddressSaveDefaultGroup( $customer = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) ->disableOriginalConstructor() - ->setMethods([ - 'getStore', - 'getDisableAutoGroupChange', - 'getGroupId', - 'setGroupId', - 'save', - ]) + ->setMethods( + [ + 'getStore', + 'getDisableAutoGroupChange', + 'getGroupId', + 'setGroupId', + 'save', + ] + ) ->getMock(); $customer->expects($this->exactly(2)) ->method('getStore') @@ -363,12 +375,14 @@ public function testAfterAddressSaveDefaultGroup( $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class) ->disableOriginalConstructor() - ->setMethods([ - 'getCustomer', - 'getForceProcess', - 'getVatId', - 'getCountry', - ]) + ->setMethods( + [ + 'getCustomer', + 'getForceProcess', + 'getVatId', + 'getCountry', + ] + ) ->getMock(); $address->expects($this->once()) ->method('getCustomer') @@ -385,9 +399,11 @@ public function testAfterAddressSaveDefaultGroup( $observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class) ->disableOriginalConstructor() - ->setMethods([ - 'getCustomerAddress', - ]) + ->setMethods( + [ + 'getCustomerAddress', + ] + ) ->getMock(); $observer->expects($this->once()) ->method('getCustomerAddress') @@ -457,10 +473,12 @@ public function testAfterAddressSaveNewGroup( $validationResult = $this->getMockBuilder(\Magento\Framework\DataObject::class) ->disableOriginalConstructor() - ->setMethods([ - 'getIsValid', - 'getRequestSuccess', - ]) + ->setMethods( + [ + 'getIsValid', + 'getRequestSuccess', + ] + ) ->getMock(); $validationResult->expects($this->any()) ->method('getIsValid') @@ -471,13 +489,15 @@ public function testAfterAddressSaveNewGroup( $customer = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) ->disableOriginalConstructor() - ->setMethods([ - 'getStore', - 'getDisableAutoGroupChange', - 'getGroupId', - 'setGroupId', - 'save', - ]) + ->setMethods( + [ + 'getStore', + 'getDisableAutoGroupChange', + 'getGroupId', + 'setGroupId', + 'save', + ] + ) ->getMock(); $customer->expects($this->exactly(2)) ->method('getStore') @@ -503,14 +523,16 @@ public function testAfterAddressSaveNewGroup( $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class) ->disableOriginalConstructor() - ->setMethods([ - 'getCustomer', - 'getForceProcess', - 'getVatId', - 'getCountryId', - 'getCountry', - 'setVatValidationResult', - ]) + ->setMethods( + [ + 'getCustomer', + 'getForceProcess', + 'getVatId', + 'getCountryId', + 'getCountry', + 'setVatValidationResult', + ] + ) ->getMock(); $address->expects($this->any()) ->method('getCustomer') @@ -534,9 +556,11 @@ public function testAfterAddressSaveNewGroup( $observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class) ->disableOriginalConstructor() - ->setMethods([ - 'getCustomerAddress', - ]) + ->setMethods( + [ + 'getCustomerAddress', + ] + ) ->getMock(); $observer->expects($this->once()) ->method('getCustomerAddress') diff --git a/app/code/Magento/Customer/view/frontend/templates/messages/confirmAccountSuccessMessage.phtml b/app/code/Magento/Customer/view/frontend/templates/messages/confirmAccountSuccessMessage.phtml index 3356c1248b37e..a2edb20e967c6 100644 --- a/app/code/Magento/Customer/view/frontend/templates/messages/confirmAccountSuccessMessage.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/messages/confirmAccountSuccessMessage.phtml @@ -6,5 +6,4 @@ /** @var \Magento\Framework\View\Element\Template $block */ ?> - escapeHtml(__('You must confirm your account. Please check your email for the confirmation link or click here for a new link.', $block->getData('url')), ['a']); diff --git a/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml b/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml index c49a1d4e46420..a5313078e13cc 100644 --- a/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml @@ -6,5 +6,4 @@ /** @var \Magento\Framework\View\Element\Template $block */ ?> - escapeHtml(__('We can\'t delete the address right now.')); From 60823ed12471599b895a700c0c3724a5b6d87572 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Thu, 22 Aug 2019 10:12:58 +0300 Subject: [PATCH 07/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento_Customer --- app/code/Magento/Customer/Controller/Account/Confirm.php | 4 +++- app/code/Magento/Customer/Controller/Account/EditPost.php | 2 ++ .../Customer/Test/Unit/Controller/Account/ConfirmTest.php | 2 +- .../Customer/Test/Unit/Controller/Address/DeleteTest.php | 6 +++--- .../messages/customerAlreadyExistsErrorMessage.phtml | 1 - 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Customer/Controller/Account/Confirm.php b/app/code/Magento/Customer/Controller/Account/Confirm.php index 3b19a8b33512a..6809442bbc929 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirm.php +++ b/app/code/Magento/Customer/Controller/Account/Confirm.php @@ -24,7 +24,9 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Confirm extends \Magento\Customer\Controller\AbstractAccount +class Confirm + extends \Magento\Customer\Controller\AbstractAccount + implements \Magento\Framework\App\Action\Action\ActionInterface { /** * @var \Magento\Framework\App\Config\ScopeConfigInterface diff --git a/app/code/Magento/Customer/Controller/Account/EditPost.php b/app/code/Magento/Customer/Controller/Account/EditPost.php index d2300b7b490c5..0203226fc2e3a 100644 --- a/app/code/Magento/Customer/Controller/Account/EditPost.php +++ b/app/code/Magento/Customer/Controller/Account/EditPost.php @@ -345,9 +345,11 @@ private function processChangeEmailRequest(\Magento\Customer\Api\Data\CustomerIn $this->getRequest()->getPost('current_password') ); } catch (InvalidEmailOrPasswordException $e) { + // @codingStandardsIgnoreStart throw new InvalidEmailOrPasswordException( __("The password doesn't match this account. Verify the password and try again.") ); + // @codingStandardsIgnoreEnd } } } diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php index 335d1068206b3..61efd9d562b45 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php @@ -205,7 +205,7 @@ public function testNoCustomerIdInRequest($customerId, $key) $exception = new \Exception('Bad request.'); $this->messageManagerMock->expects($this->once()) - ->method('addExceptionMessage') + ->method('addException') ->with($this->equalTo($exception), $this->equalTo('There was an error confirming the account')); $testUrl = 'http://example.com'; diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php index 3634aaf469f9b..046c023d35c64 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php @@ -184,10 +184,10 @@ public function testExecuteWithException() $exception = new \Exception('Exception'); $this->messageManager->expects($this->once()) ->method('addComplexErrorMessage') - ->with(__('We can\'t delete the address right now.')) - ->willThrowException($exception); + ->with('unableDeleteAddressMessage') + ->willReturnSelf(); $this->messageManager->expects($this->once()) - ->method('addExceptionMessage') + ->method('addException') ->with($exception, __('We can\'t delete the address right now.')); $this->resultRedirect->expects($this->once()) ->method('setPath') diff --git a/app/code/Magento/Customer/view/frontend/templates/messages/customerAlreadyExistsErrorMessage.phtml b/app/code/Magento/Customer/view/frontend/templates/messages/customerAlreadyExistsErrorMessage.phtml index 27ffc1433a368..32982551b5b16 100644 --- a/app/code/Magento/Customer/view/frontend/templates/messages/customerAlreadyExistsErrorMessage.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/messages/customerAlreadyExistsErrorMessage.phtml @@ -6,5 +6,4 @@ /** @var \Magento\Framework\View\Element\Template $block */ ?> - escapeHtml(__('There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account.', $block->getData('url')), ['a']); From 5b360cb19ff4bc8c3ad6c75d98dcb92044eba97d Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Sun, 25 Aug 2019 07:19:30 +0300 Subject: [PATCH 08/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento/Customer/Controller/Account/CreatePost.php --- .../Customer/Controller/Account/Confirm.php | 14 +- .../Controller/Account/Confirmation.php | 10 +- .../Controller/Account/CreatePost.php | 49 +++--- .../Customer/Controller/Account/EditPost.php | 10 +- .../Customer/Controller/Account/LoginPost.php | 7 +- .../Controller/Account/ResetPasswordPost.php | 12 +- .../Customer/Controller/Address/Delete.php | 4 +- .../Adminhtml/Customer/InvalidateToken.php | 6 +- .../Controller/Adminhtml/Group/Delete.php | 10 +- .../Controller/Adminhtml/Group/Save.php | 2 +- .../Customer/Controller/Adminhtml/Index.php | 4 +- .../Adminhtml/Index/AbstractMassAction.php | 3 +- .../Controller/Adminhtml/Index/Delete.php | 6 +- .../Controller/Adminhtml/Index/Edit.php | 18 +-- .../Controller/Adminhtml/Index/InlineEdit.php | 26 ++-- .../Adminhtml/Index/MassAssignGroup.php | 2 +- .../Controller/Adminhtml/Index/MassDelete.php | 2 +- .../Adminhtml/Index/MassSubscribe.php | 2 +- .../Adminhtml/Index/MassUnsubscribe.php | 2 +- .../Adminhtml/Index/ResetPassword.php | 6 +- .../Controller/Adminhtml/Index/Save.php | 7 +- .../Controller/Adminhtml/Locks/Unlock.php | 4 +- .../Observer/AfterAddressSaveObserver.php | 6 +- .../StorefrontClearAllCompareProductsTest.xml | 1 + .../Unit/Controller/Account/ConfirmTest.php | 26 ++-- .../Controller/Account/CreatePostTest.php | 38 ++--- .../Unit/Controller/Account/LoginPostTest.php | 64 ++++---- .../Unit/Controller/Address/DeleteTest.php | 8 +- .../Controller/Adminhtml/Group/SaveTest.php | 2 +- .../Adminhtml/Index/InlineEditTest.php | 24 ++- .../Adminhtml/Index/MassAssignGroupTest.php | 4 +- .../Adminhtml/Index/MassDeleteTest.php | 4 +- .../Adminhtml/Index/MassSubscribeTest.php | 4 +- .../Adminhtml/Index/MassUnsubscribeTest.php | 4 +- .../Adminhtml/Index/NewsletterTest.php | 2 +- .../Adminhtml/Index/ResetPasswordTest.php | 6 +- .../Controller/Adminhtml/Index/SaveTest.php | 92 +++++------ .../Controller/Adminhtml/Locks/UnlockTest.php | 4 +- .../Observer/AfterAddressSaveObserverTest.php | 144 ++++++++---------- app/code/Magento/Customer/etc/frontend/di.xml | 26 +--- .../messages/unableDeleteAddressMessage.phtml | 9 -- 41 files changed, 281 insertions(+), 393 deletions(-) delete mode 100644 app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml diff --git a/app/code/Magento/Customer/Controller/Account/Confirm.php b/app/code/Magento/Customer/Controller/Account/Confirm.php index 6809442bbc929..2b3cb9aa61ab5 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirm.php +++ b/app/code/Magento/Customer/Controller/Account/Confirm.php @@ -24,9 +24,7 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Confirm - extends \Magento\Customer\Controller\AbstractAccount - implements \Magento\Framework\App\Action\Action\ActionInterface +class Confirm extends \Magento\Customer\Controller\AbstractAccount { /** * @var \Magento\Framework\App\Config\ScopeConfigInterface @@ -153,9 +151,7 @@ public function execute() $customerId = $this->getRequest()->getParam('id', false); $key = $this->getRequest()->getParam('key', false); if (empty($customerId) || empty($key)) { - $this->messageManager->addErrorMessage(__('Bad request.')); - $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); - return $resultRedirect->setUrl($this->_redirect->error($url)); + throw new \Exception(__('Bad request.')); } // log in and send greeting email @@ -167,13 +163,13 @@ public function execute() $metadata->setPath('/'); $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata); } - $this->messageManager->addSuccessMessage($this->getSuccessMessage()); + $this->messageManager->addSuccess($this->getSuccessMessage()); $resultRedirect->setUrl($this->getSuccessRedirect()); return $resultRedirect; } catch (StateException $e) { - $this->messageManager->addExceptionMessage($e, __('This confirmation key is invalid or has expired.')); + $this->messageManager->addException($e, __('This confirmation key is invalid or has expired.')); } catch (\Exception $e) { - $this->messageManager->addExceptionMessage($e, __('There was an error confirming the account')); + $this->messageManager->addException($e, __('There was an error confirming the account')); } $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); diff --git a/app/code/Magento/Customer/Controller/Account/Confirmation.php b/app/code/Magento/Customer/Controller/Account/Confirmation.php index aebc0547f3536..a3e2db0207630 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirmation.php +++ b/app/code/Magento/Customer/Controller/Account/Confirmation.php @@ -1,5 +1,6 @@ storeManager->getStore()->getWebsiteId() ); - $this->messageManager->addSuccessMessage(__('Please check your email for confirmation key.')); + $this->messageManager->addSuccess(__('Please check your email for confirmation key.')); } catch (InvalidTransitionException $e) { - $this->messageManager->addSuccessMessage(__('This email does not require confirmation.')); + $this->messageManager->addSuccess(__('This email does not require confirmation.')); } catch (\Exception $e) { - $this->messageManager->addExceptionMessage($e, __('Wrong email.')); + $this->messageManager->addException($e, __('Wrong email.')); $resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]); return $resultRedirect; } diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index 6c65d8c8d282c..a2be0f68b56cb 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Customer\Controller\Account; use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository; @@ -349,33 +351,34 @@ public function execute() $confirmation = $this->getRequest()->getParam('password_confirmation'); $redirectUrl = $this->session->getBeforeAuthUrl(); $this->checkPasswordConfirmation($password, $confirmation); + + $extensionAttributes = $customer->getExtensionAttributes(); + $extensionAttributes->setIsSubscribed($this->getRequest()->getParam('is_subscribed', false)); + $customer->setExtensionAttributes($extensionAttributes); + $customer = $this->accountManagement ->createAccount($customer, $password, $redirectUrl); - if ($this->getRequest()->getParam('is_subscribed', false)) { - $extensionAttributes = $customer->getExtensionAttributes(); - $extensionAttributes->setIsSubscribed(true); - $customer->setExtensionAttributes($extensionAttributes); - $this->customerRepository->save($customer); - } $this->_eventManager->dispatch( 'customer_register_success', ['account_controller' => $this, 'customer' => $customer] ); $confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) { - $this->messageManager->addComplexSuccessMessage( - 'confirmAccountSuccessMessage', - [ - 'url' => $this->customerUrl->getEmailConfirmationUrl($customer->getEmail()), - ] + $email = $this->customerUrl->getEmailConfirmationUrl($customer->getEmail()); + // @codingStandardsIgnoreStart + $this->messageManager->addSuccess( + __( + 'You must confirm your account. Please check your email for the confirmation link or click here for a new link.', + $email + ) ); - + // @codingStandardsIgnoreEnd $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); $resultRedirect->setUrl($this->_redirect->success($url)); } else { $this->session->setCustomerDataAsLoggedIn($customer); - $this->messageManager->addSuccessMessage($this->getSuccessMessage()); + $this->messageManager->addSuccess($this->getSuccessMessage()); $requestedRedirect = $this->accountRedirect->getRedirectCookie(); if (!$this->scopeConfig->getValue('customer/startup/redirect_dashboard') && $requestedRedirect) { $resultRedirect->setUrl($this->_redirect->success($requestedRedirect)); @@ -392,21 +395,23 @@ public function execute() return $resultRedirect; } catch (StateException $e) { - $this->messageManager->addComplexErrorMessage( - 'customerAlreadyExistsErrorMessage', - [ - 'url' => $this->urlModel->getUrl('customer/account/forgotpassword'), - ] + $url = $this->urlModel->getUrl('customer/account/forgotpassword'); + // @codingStandardsIgnoreStart + $message = __( + 'There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account.', + $url ); + // @codingStandardsIgnoreEnd + $this->messageManager->addError($message); } catch (InputException $e) { - $this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage())); + $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage())); foreach ($e->getErrors() as $error) { - $this->messageManager->addErrorMessage($this->escaper->escapeHtml($error->getMessage())); + $this->messageManager->addError($this->escaper->escapeHtml($error->getMessage())); } } catch (LocalizedException $e) { - $this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage())); + $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage())); } catch (\Exception $e) { - $this->messageManager->addExceptionMessage($e, __('We can\'t save the customer.')); + $this->messageManager->addException($e, __('We can\'t save the customer.')); } $this->session->setCustomerFormData($this->getRequest()->getPostValue()); diff --git a/app/code/Magento/Customer/Controller/Account/EditPost.php b/app/code/Magento/Customer/Controller/Account/EditPost.php index 0203226fc2e3a..4eb41cedea29a 100644 --- a/app/code/Magento/Customer/Controller/Account/EditPost.php +++ b/app/code/Magento/Customer/Controller/Account/EditPost.php @@ -216,7 +216,7 @@ public function execute() $isPasswordChanged ); $this->dispatchSuccessEvent($customerCandidateDataObject); - $this->messageManager->addSuccessMessage(__('You saved the account information.')); + $this->messageManager->addSuccess(__('You saved the account information.')); return $resultRedirect->setPath('customer/account'); } catch (InvalidEmailOrPasswordException $e) { $this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage())); @@ -227,7 +227,7 @@ public function execute() ); $this->session->logout(); $this->session->start(); - $this->messageManager->addErrorMessage($message); + $this->messageManager->addError($message); return $resultRedirect->setPath('customer/account/login'); } catch (InputException $e) { $this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage())); @@ -235,9 +235,9 @@ public function execute() $this->messageManager->addErrorMessage($this->escaper->escapeHtml($error->getMessage())); } } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addErrorMessage($e->getMessage()); + $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { - $this->messageManager->addExceptionMessage($e, __('We can\'t save the customer.')); + $this->messageManager->addException($e, __('We can\'t save the customer.')); } $this->session->setCustomerFormData($this->getRequest()->getPostValue()); @@ -345,11 +345,9 @@ private function processChangeEmailRequest(\Magento\Customer\Api\Data\CustomerIn $this->getRequest()->getPost('current_password') ); } catch (InvalidEmailOrPasswordException $e) { - // @codingStandardsIgnoreStart throw new InvalidEmailOrPasswordException( __("The password doesn't match this account. Verify the password and try again.") ); - // @codingStandardsIgnoreEnd } } } diff --git a/app/code/Magento/Customer/Controller/Account/LoginPost.php b/app/code/Magento/Customer/Controller/Account/LoginPost.php index 046ae5c70276f..04051fbbf366b 100644 --- a/app/code/Magento/Customer/Controller/Account/LoginPost.php +++ b/app/code/Magento/Customer/Controller/Account/LoginPost.php @@ -26,7 +26,6 @@ use Magento\Framework\Phrase; /** - * Class LoginPost * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class LoginPost extends AbstractAccount implements CsrfAwareActionInterface, HttpPostActionInterface @@ -218,17 +217,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->addErrorMessage( + $this->messageManager->addError( __('An unspecified error occurred. Please contact us for assistance.') ); } finally { if (isset($message)) { - $this->messageManager->addErrorMessage($message); + $this->messageManager->addError($message); $this->session->setUsername($login['username']); } } } else { - $this->messageManager->addErrorMessage(__('A login and a password are required.')); + $this->messageManager->addError(__('A login and a password are required.')); } } diff --git a/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php b/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php index a127f2acf538f..27a00f86dd95d 100644 --- a/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php +++ b/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php @@ -73,13 +73,13 @@ public function execute() $passwordConfirmation = (string)$this->getRequest()->getPost('password_confirmation'); if ($password !== $passwordConfirmation) { - $this->messageManager->addErrorMessage(__("New Password and Confirm New Password values didn't match.")); + $this->messageManager->addError(__("New Password and Confirm New Password values didn't match.")); $resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]); return $resultRedirect; } if (iconv_strlen($password) <= 0) { - $this->messageManager->addErrorMessage(__('Please enter a new password.')); + $this->messageManager->addError(__('Please enter a new password.')); $resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]); return $resultRedirect; @@ -92,17 +92,17 @@ public function execute() $password ); $this->session->unsRpToken(); - $this->messageManager->addSuccessMessage(__('You updated your password.')); + $this->messageManager->addSuccess(__('You updated your password.')); $resultRedirect->setPath('*/*/login'); return $resultRedirect; } catch (InputException $e) { - $this->messageManager->addErrorMessage($e->getMessage()); + $this->messageManager->addError($e->getMessage()); foreach ($e->getErrors() as $error) { - $this->messageManager->addErrorMessage($error->getMessage()); + $this->messageManager->addError($error->getMessage()); } } catch (\Exception $exception) { - $this->messageManager->addErrorMessage(__('Something went wrong while saving the new password.')); + $this->messageManager->addError(__('Something went wrong while saving the new password.')); } $resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]); diff --git a/app/code/Magento/Customer/Controller/Address/Delete.php b/app/code/Magento/Customer/Controller/Address/Delete.php index 9df06c69d4a88..a30e15db4b3f8 100644 --- a/app/code/Magento/Customer/Controller/Address/Delete.php +++ b/app/code/Magento/Customer/Controller/Address/Delete.php @@ -27,9 +27,9 @@ public function execute() $address = $this->_addressRepository->getById($addressId); if ($address->getCustomerId() === $this->_getSession()->getCustomerId()) { $this->_addressRepository->deleteById($addressId); - $this->messageManager->addSuccessMessage(__('You deleted the address.')); + $this->messageManager->addSuccess(__('You deleted the address.')); } else { - $this->messageManager->addComplexErrorMessage('unableDeleteAddressMessage'); + $this->messageManager->addError(__('We can\'t delete the address right now.')); } } catch (\Exception $other) { $this->messageManager->addException($other, __('We can\'t delete the address right now.')); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php b/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php index 7747d80595cdc..b69410ecbfce7 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php @@ -139,14 +139,14 @@ public function execute() if ($customerId = $this->getRequest()->getParam('customer_id')) { try { $this->tokenService->revokeCustomerAccessToken($customerId); - $this->messageManager->addSuccessMessage(__('You have revoked the customer\'s tokens.')); + $this->messageManager->addSuccess(__('You have revoked the customer\'s tokens.')); $resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]); } catch (\Exception $e) { - $this->messageManager->addErrorMessage($e->getMessage()); + $this->messageManager->addError($e->getMessage()); $resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]); } } else { - $this->messageManager->addErrorMessage(__('We can\'t find a customer to revoke.')); + $this->messageManager->addError(__('We can\'t find a customer to revoke.')); $resultRedirect->setPath('customer/index/index'); } return $resultRedirect; diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php index 661ef1cace69b..ab32ea08a44aa 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php @@ -1,5 +1,6 @@ groupRepository->deleteById($id); - $this->messageManager->addSuccessMessage(__('You deleted the customer group.')); + $this->messageManager->addSuccess(__('You deleted the customer group.')); } catch (NoSuchEntityException $e) { - $this->messageManager->addErrorMessage(__('The customer group no longer exists.')); + $this->messageManager->addError(__('The customer group no longer exists.')); return $resultRedirect->setPath('customer/*/'); } catch (\Exception $e) { - $this->messageManager->addErrorMessage($e->getMessage()); + $this->messageManager->addError($e->getMessage()); return $resultRedirect->setPath('customer/group/edit', ['id' => $id]); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php index bb3589a75f721..5ffce4cbcd989 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php @@ -93,7 +93,7 @@ public function execute() $this->groupRepository->save($customerGroup); - $this->messageManager->addSuccessMessage(__('You saved the customer group.')); + $this->messageManager->addSuccess(__('You saved the customer group.')); $resultRedirect->setPath('customer/group'); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index.php b/app/code/Magento/Customer/Controller/Adminhtml/Index.php index ffae1e9f8bf1e..a0317a51260da 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index.php @@ -311,7 +311,7 @@ protected function _addSessionErrorMessages($messages) protected function actUponMultipleCustomers(callable $singleAction, $customerIds) { if (!is_array($customerIds)) { - $this->messageManager->addErrorMessage(__('Please select customer(s).')); + $this->messageManager->addError(__('Please select customer(s).')); return 0; } $customersUpdated = 0; @@ -320,7 +320,7 @@ protected function actUponMultipleCustomers(callable $singleAction, $customerIds $singleAction($customerId); $customersUpdated++; } catch (\Exception $exception) { - $this->messageManager->addErrorMessage($exception->getMessage()); + $this->messageManager->addError($exception->getMessage()); } } return $customersUpdated; diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/AbstractMassAction.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/AbstractMassAction.php index e2bde42351d45..e26b49aaebe7a 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/AbstractMassAction.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/AbstractMassAction.php @@ -64,7 +64,7 @@ public function execute() $collection = $this->filter->getCollection($this->collectionFactory->create()); return $this->massAction($collection); } catch (\Exception $e) { - $this->messageManager->addErrorMessage($e->getMessage()); + $this->messageManager->addError($e->getMessage()); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath($this->redirectUrl); @@ -73,7 +73,6 @@ 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 diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php index 4b2f2614948cf..ab39ca098162f 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php @@ -31,7 +31,7 @@ public function execute() $formKeyIsValid = $this->_formKeyValidator->validate($this->getRequest()); $isPost = $this->getRequest()->isPost(); if (!$formKeyIsValid || !$isPost) { - $this->messageManager->addErrorMessage(__('Customer could not be deleted.')); + $this->messageManager->addError(__('Customer could not be deleted.')); return $resultRedirect->setPath('customer/index'); } @@ -39,9 +39,9 @@ public function execute() if (!empty($customerId)) { try { $this->_customerRepository->deleteById($customerId); - $this->messageManager->addSuccessMessage(__('You deleted the customer.')); + $this->messageManager->addSuccess(__('You deleted the customer.')); } catch (\Exception $exception) { - $this->messageManager->addErrorMessage($exception->getMessage()); + $this->messageManager->addError($exception->getMessage()); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php index 3d7f75884057f..25b4ddd4e1732 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php @@ -9,9 +9,6 @@ use Magento\Customer\Api\Data\CustomerInterface; use Magento\Framework\Exception\NoSuchEntityException; -/** - * Class Edit - */ class Edit extends \Magento\Customer\Controller\Adminhtml\Index implements HttpGetActionInterface { /** @@ -36,14 +33,17 @@ public function execute() $customer = $this->_customerRepository->getById($customerId); $customerData['account'] = $this->customerMapper->toFlatArray($customer); $customerData['account'][CustomerInterface::ID] = $customerId; - - $addresses = $customer->getAddresses(); - foreach ($addresses as $address) { - $customerData['address'][$address->getId()] = $this->addressMapper->toFlatArray($address); - $customerData['address'][$address->getId()]['id'] = $address->getId(); + try { + $addresses = $customer->getAddresses(); + foreach ($addresses as $address) { + $customerData['address'][$address->getId()] = $this->addressMapper->toFlatArray($address); + $customerData['address'][$address->getId()]['id'] = $address->getId(); + } + } catch (NoSuchEntityException $e) { + //do nothing } } catch (NoSuchEntityException $e) { - $this->messageManager->addExceptionMessage($e, __('Something went wrong while editing the customer.')); + $this->messageManager->addException($e, __('Something went wrong while editing the customer.')); $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('customer/*/index'); return $resultRedirect; diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php index ba8c84a0ac273..7220de0356817 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php @@ -128,12 +128,10 @@ public function execute() $postItems = $this->getRequest()->getParam('items', []); if (!($this->getRequest()->getParam('isAjax') && count($postItems))) { - return $resultJson->setData( - [ - 'messages' => [__('Please correct the data sent.')], - 'error' => true, - ] - ); + return $resultJson->setData([ + 'messages' => [__('Please correct the data sent.')], + 'error' => true, + ]); } foreach (array_keys($postItems) as $customerId) { @@ -149,12 +147,10 @@ public function execute() $this->getEmailNotification()->credentialsChanged($this->getCustomer(), $currentCustomer->getEmail()); } - return $resultJson->setData( - [ - 'messages' => $this->getErrorMessages(), - 'error' => $this->isErrorExists() - ] - ); + return $resultJson->setData([ + 'messages' => $this->getErrorMessages(), + 'error' => $this->isErrorExists() + ]); } /** @@ -238,13 +234,13 @@ protected function saveCustomer(CustomerInterface $customer) $this->disableAddressValidation($customer); $this->customerRepository->save($customer); } catch (\Magento\Framework\Exception\InputException $e) { - $this->getMessageManager()->addErrorMessage($this->getErrorWithCustomerId($e->getMessage())); + $this->getMessageManager()->addError($this->getErrorWithCustomerId($e->getMessage())); $this->logger->critical($e); } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->getMessageManager()->addErrorMessage($this->getErrorWithCustomerId($e->getMessage())); + $this->getMessageManager()->addError($this->getErrorWithCustomerId($e->getMessage())); $this->logger->critical($e); } catch (\Exception $e) { - $this->getMessageManager()->addErrorMessage($this->getErrorWithCustomerId('We can\'t save the customer.')); + $this->getMessageManager()->addError($this->getErrorWithCustomerId('We can\'t save the customer.')); $this->logger->critical($e); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php index f55c81da7e0b9..5a9c52bf9b1c0 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php @@ -60,7 +60,7 @@ protected function massAction(AbstractCollection $collection) } if ($customersUpdated) { - $this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated)); + $this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php index 85286573bc5e7..edaeea6a15eb2 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php @@ -58,7 +58,7 @@ protected function massAction(AbstractCollection $collection) } if ($customersDeleted) { - $this->messageManager->addSuccessMessage(__('A total of %1 record(s) were deleted.', $customersDeleted)); + $this->messageManager->addSuccess(__('A total of %1 record(s) were deleted.', $customersDeleted)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php index e072c5cb4cd49..25c56ac60c14b 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php @@ -64,7 +64,7 @@ protected function massAction(AbstractCollection $collection) } if ($customersUpdated) { - $this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated)); + $this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php index e52c9a772ed2d..4b40722ba9ab2 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php @@ -64,7 +64,7 @@ protected function massAction(AbstractCollection $collection) } if ($customersUpdated) { - $this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated)); + $this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php index 3b9370c32bf6d..1e4fa91cbf899 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php @@ -44,9 +44,7 @@ public function execute() \Magento\Customer\Model\AccountManagement::EMAIL_REMINDER, $customer->getWebsiteId() ); - $this->messageManager->addSuccessMessage( - __('The customer will receive an email with a link to reset password.') - ); + $this->messageManager->addSuccess(__('The customer will receive an email with a link to reset password.')); } catch (NoSuchEntityException $exception) { $resultRedirect->setPath('customer/index'); return $resultRedirect; @@ -59,7 +57,7 @@ public function execute() } catch (SecurityViolationException $exception) { $this->messageManager->addErrorMessage($exception->getMessage()); } catch (\Exception $exception) { - $this->messageManager->addExceptionMessage( + $this->messageManager->addException( $exception, __('Something went wrong while resetting customer password.') ); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php index 3ee33af9ec073..38ed688a835bc 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php @@ -354,7 +354,7 @@ public function execute() $this->_getSession()->unsCustomerFormData(); // Done Saving customer, finish save action $this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId); - $this->messageManager->addSuccessMessage(__('You saved the customer.')); + $this->messageManager->addSuccess(__('You saved the customer.')); $returnToEdit = (bool)$this->getRequest()->getParam('back', false); } catch (\Magento\Framework\Validator\Exception $exception) { $messages = $exception->getMessages(); @@ -378,10 +378,7 @@ public function execute() $this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData()); $returnToEdit = true; } catch (\Exception $exception) { - $this->messageManager->addExceptionMessage( - $exception, - __('Something went wrong while saving the customer.') - ); + $this->messageManager->addException($exception, __('Something went wrong while saving the customer.')); $this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData()); $returnToEdit = true; } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Locks/Unlock.php b/app/code/Magento/Customer/Controller/Adminhtml/Locks/Unlock.php index 2747ba1a665fd..1fd06a3182948 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Locks/Unlock.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Locks/Unlock.php @@ -55,10 +55,10 @@ public function execute() // unlock customer if ($customerId) { $this->authentication->unlock($customerId); - $this->getMessageManager()->addSuccessMessage(__('Customer has been unlocked successfully.')); + $this->getMessageManager()->addSuccess(__('Customer has been unlocked successfully.')); } } catch (\Exception $e) { - $this->messageManager->addErrorMessage($e->getMessage()); + $this->messageManager->addError($e->getMessage()); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ diff --git a/app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php b/app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php index 8677abfa89904..41311abee5da8 100644 --- a/app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php +++ b/app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php @@ -255,7 +255,7 @@ protected function addValidMessage($customerAddress, $validationResult) : (string)__('You will not be charged tax.'); } - $this->messageManager->addSuccessMessage(implode(' ', $message)); + $this->messageManager->addSuccess(implode(' ', $message)); return $this; } @@ -280,7 +280,7 @@ protected function addInvalidMessage($customerAddress) $message[] = (string)__('You will be charged tax.'); } - $this->messageManager->addErrorMessage(implode(' ', $message)); + $this->messageManager->addError(implode(' ', $message)); return $this; } @@ -307,7 +307,7 @@ protected function addErrorMessage($customerAddress) $email = $this->scopeConfig->getValue('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE); $message[] = (string)__('If you believe this is an error, please contact us at %1', $email); - $this->messageManager->addErrorMessage(implode(' ', $message)); + $this->messageManager->addError(implode(' ', $message)); return $this; } diff --git a/app/code/Magento/Customer/Test/Mftf/Test/StorefrontClearAllCompareProductsTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontClearAllCompareProductsTest.xml index d7372b07de14b..ada3adbfeb83b 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/StorefrontClearAllCompareProductsTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontClearAllCompareProductsTest.xml @@ -116,6 +116,7 @@ + diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php index 61efd9d562b45..01fc465d4ae84 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php @@ -255,12 +255,10 @@ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $ad $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap( - [ - ['id', false, $customerId], - ['key', false, $key], - ] - ); + ->willReturnMap([ + ['id', false, $customerId], + ['key', false, $key], + ]); $this->customerRepositoryMock->expects($this->any()) ->method('getById') @@ -283,7 +281,7 @@ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $ad ->willReturnSelf(); $this->messageManagerMock->expects($this->any()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with($this->stringContains($successMessage)) ->willReturnSelf(); @@ -374,13 +372,11 @@ public function testSuccessRedirect( $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap( - [ - ['id', false, $customerId], - ['key', false, $key], - ['back_url', false, $backUrl], - ] - ); + ->willReturnMap([ + ['id', false, $customerId], + ['key', false, $key], + ['back_url', false, $backUrl], + ]); $this->customerRepositoryMock->expects($this->any()) ->method('getById') @@ -403,7 +399,7 @@ public function testSuccessRedirect( ->willReturnSelf(); $this->messageManagerMock->expects($this->any()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with($this->stringContains($successMessage)) ->willReturnSelf(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php index faf55347dba78..f8f47eedba3ef 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php @@ -346,13 +346,11 @@ public function testSuccessMessage( $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap( - [ - ['password', null, $password], - ['password_confirmation', null, $password], - ['is_subscribed', false, true], - ] - ); + ->willReturnMap([ + ['password', null, $password], + ['password_confirmation', null, $password], + ['is_subscribed', false, true], + ]); $this->customerMock->expects($this->once()) ->method('setAddresses') @@ -373,7 +371,7 @@ public function testSuccessMessage( ->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with($this->stringContains($successMessage)) ->will($this->returnSelf()); @@ -479,13 +477,11 @@ public function testSuccessRedirect( $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap( - [ - ['password', null, $password], - ['password_confirmation', null, $password], - ['is_subscribed', false, true], - ] - ); + ->willReturnMap([ + ['password', null, $password], + ['password_confirmation', null, $password], + ['is_subscribed', false, true], + ]); $this->customerMock->expects($this->once()) ->method('setAddresses') @@ -506,18 +502,16 @@ public function testSuccessRedirect( ->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with($this->stringContains($successMessage)) ->will($this->returnSelf()); $this->urlMock->expects($this->any()) ->method('getUrl') - ->willReturnMap( - [ - ['*/*/index', ['_secure' => true], $successUrl], - ['*/*/create', ['_secure' => true], $successUrl], - ] - ); + ->willReturnMap([ + ['*/*/index', ['_secure' => true], $successUrl], + ['*/*/create', ['_secure' => true], $successUrl], + ]); $this->redirectMock->expects($this->once()) ->method('success') ->with($this->equalTo($successUrl)) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php index fd70a55ad7def..762c76b695dee 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php @@ -93,14 +93,12 @@ protected function setUp() $this->session = $this->getMockBuilder(\Magento\Customer\Model\Session::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'isLoggedIn', - 'setCustomerDataAsLoggedIn', - 'regenerateId', - 'setUsername', - ] - ) + ->setMethods([ + 'isLoggedIn', + 'setCustomerDataAsLoggedIn', + 'regenerateId', + 'setUsername', + ]) ->getMock(); $this->accountManagement = $this->getMockBuilder(\Magento\Customer\Api\AccountManagementInterface::class) @@ -224,7 +222,7 @@ public function testExecuteEmptyLoginData() ->willReturn([]); $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with(__('A login and a password are required.')) ->willReturnSelf(); @@ -255,12 +253,10 @@ public function testExecuteSuccessCustomRedirect() $this->request->expects($this->once()) ->method('getPost') ->with('login') - ->willReturn( - [ - 'username' => $username, - 'password' => $password, - ] - ); + ->willReturn([ + 'username' => $username, + 'password' => $password, + ]); $customerMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class) ->getMockForAbstractClass(); @@ -339,12 +335,10 @@ public function testExecuteSuccess() $this->request->expects($this->once()) ->method('getPost') ->with('login') - ->willReturn( - [ - 'username' => $username, - 'password' => $password, - ] - ); + ->willReturn([ + 'username' => $username, + 'password' => $password, + ]); $customerMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class) ->getMockForAbstractClass(); @@ -432,12 +426,10 @@ public function testExecuteWithException( $this->request->expects($this->once()) ->method('getPost') ->with('login') - ->willReturn( - [ - 'username' => $username, - 'password' => $password, - ] - ); + ->willReturn([ + 'username' => $username, + 'password' => $password, + ]); $exception = new $exceptionData['exception'](__($exceptionData['message'])); @@ -496,12 +488,10 @@ protected function prepareContext() $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'isPost', - 'getPost', - ] - ) + ->setMethods([ + 'isPost', + 'getPost', + ]) ->getMock(); $this->resultRedirect = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) @@ -561,7 +551,7 @@ protected function mockExceptions($exception, $username) $url ); $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with($message) ->willReturnSelf(); @@ -573,7 +563,7 @@ protected function mockExceptions($exception, $username) case \Magento\Framework\Exception\AuthenticationException::class: $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with( __( 'The account sign-in was incorrect or your account is disabled temporarily. ' @@ -590,7 +580,7 @@ protected function mockExceptions($exception, $username) case '\Exception': $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with(__('An unspecified error occurred. Please contact us for assistance.')) ->willReturnSelf(); break; @@ -601,7 +591,7 @@ protected function mockExceptions($exception, $username) . 'Please wait and try again later.' ); $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with($message) ->willReturnSelf(); $this->session->expects($this->once()) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php index 046c023d35c64..4064b8586257d 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php @@ -146,7 +146,7 @@ public function testExecute() ->method('deleteById') ->with($addressId); $this->messageManager->expects($this->once()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with(__('You deleted the address.')); $this->resultRedirect->expects($this->once()) ->method('setPath') @@ -183,9 +183,9 @@ public function testExecuteWithException() ->willReturn(34); $exception = new \Exception('Exception'); $this->messageManager->expects($this->once()) - ->method('addComplexErrorMessage') - ->with('unableDeleteAddressMessage') - ->willReturnSelf(); + ->method('addError') + ->with(__('We can\'t delete the address right now.')) + ->willThrowException($exception); $this->messageManager->expects($this->once()) ->method('addException') ->with($exception, __('We can\'t delete the address right now.')); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php index b0b8075325f8b..5f7064d5b124b 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Group/SaveTest.php @@ -167,7 +167,7 @@ public function testExecuteWithTaxClassAndException() ->method('save') ->with($this->group); $this->messageManager->expects($this->once()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with(__('You saved the customer group.')); $exception = new \Exception('Exception'); $this->resultRedirect->expects($this->at(0)) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php index 769c77dfcb4ea..45e64f6557d51 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php @@ -291,12 +291,10 @@ protected function prepareMocksForErrorMessagesProcessing() ->willReturn('Error text'); $this->resultJson->expects($this->once()) ->method('setData') - ->with( - [ - 'messages' => ['Error text'], - 'error' => true, - ] - ) + ->with([ + 'messages' => ['Error text'], + 'error' => true, + ]) ->willReturnSelf(); } @@ -342,12 +340,10 @@ public function testExecuteWithoutItems() $this->resultJson ->expects($this->once()) ->method('setData') - ->with( - [ - 'messages' => [__('Please correct the data sent.')], - 'error' => true, - ] - ) + ->with([ + 'messages' => [__('Please correct the data sent.')], + 'error' => true, + ]) ->willReturnSelf(); $this->assertSame($this->resultJson, $this->controller->execute()); } @@ -370,7 +366,7 @@ public function testExecuteLocalizedException() ->with($this->customerData) ->willThrowException($exception); $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with('[Customer ID: 12] Exception message'); $this->logger->expects($this->once()) ->method('critical') @@ -398,7 +394,7 @@ public function testExecuteException() ->with($this->customerData) ->willThrowException($exception); $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with('[Customer ID: 12] We can\'t save the customer.'); $this->logger->expects($this->once()) ->method('critical') diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassAssignGroupTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassAssignGroupTest.php index 4157359959ae4..10144bdc318c1 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassAssignGroupTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassAssignGroupTest.php @@ -170,7 +170,7 @@ public function testExecute() ->willReturnMap([[10, $customerMock], [11, $customerMock], [12, $customerMock]]); $this->messageManagerMock->expects($this->once()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with(__('A total of %1 record(s) were updated.', count($customersIds))); $this->resultRedirectMock->expects($this->any()) @@ -199,7 +199,7 @@ public function testExecuteWithException() ->willThrowException(new \Exception('Some message.')); $this->messageManagerMock->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with('Some message.'); $this->massAction->execute(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassDeleteTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassDeleteTest.php index b436b5b137c78..190ff2c06618f 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassDeleteTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassDeleteTest.php @@ -155,7 +155,7 @@ public function testExecute() ->willReturnMap([[10, true], [11, true], [12, true]]); $this->messageManagerMock->expects($this->once()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with(__('A total of %1 record(s) were deleted.', count($customersIds))); $this->resultRedirectMock->expects($this->any()) @@ -179,7 +179,7 @@ public function testExecuteWithException() ->willThrowException(new \Exception('Some message.')); $this->messageManagerMock->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with('Some message.'); $this->massAction->execute(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassSubscribeTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassSubscribeTest.php index 33e578224400b..daf9c64fe7b7b 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassSubscribeTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassSubscribeTest.php @@ -171,7 +171,7 @@ public function testExecute() ->willReturnMap([[10, true], [11, true], [12, true]]); $this->messageManagerMock->expects($this->once()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with(__('A total of %1 record(s) were updated.', count($customersIds))); $this->resultRedirectMock->expects($this->any()) @@ -195,7 +195,7 @@ public function testExecuteWithException() ->willThrowException(new \Exception('Some message.')); $this->messageManagerMock->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with('Some message.'); $this->massAction->execute(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassUnsubscribeTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassUnsubscribeTest.php index 971efc0e490bc..05624661a2de4 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassUnsubscribeTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassUnsubscribeTest.php @@ -171,7 +171,7 @@ public function testExecute() ->willReturnMap([[10, true], [11, true], [12, true]]); $this->messageManagerMock->expects($this->once()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with(__('A total of %1 record(s) were updated.', count($customersIds))); $this->resultRedirectMock->expects($this->any()) @@ -195,7 +195,7 @@ public function testExecuteWithException() ->willThrowException(new \Exception('Some message.')); $this->messageManagerMock->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with('Some message.'); $this->massAction->execute(); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/NewsletterTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/NewsletterTest.php index 5ec39360000cb..d2f8b8776081e 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/NewsletterTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/NewsletterTest.php @@ -150,7 +150,7 @@ protected function setUp() $this->messageManager = $this->getMockBuilder( \Magento\Framework\Message\Manager::class )->disableOriginalConstructor()->setMethods( - ['addSuccessMessage', 'addMessageMessage', 'addExceptionMessage'] + ['addSuccess', 'addMessage', 'addException'] )->getMock(); $contextArgs = [ diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php index 67ac60e6b9057..66e5b57eaa424 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php @@ -141,7 +141,7 @@ protected function setUp() $this->messageManager = $this->getMockBuilder( \Magento\Framework\Message\Manager::class )->disableOriginalConstructor()->setMethods( - ['addSuccessMessage', 'addMessage', 'addExceptionMessage', 'addErrorMessage'] + ['addSuccess', 'addMessage', 'addException', 'addErrorMessage'] )->getMock(); $this->resultRedirectFactoryMock = $this->getMockBuilder( @@ -442,7 +442,7 @@ public function testResetPasswordActionException() $this->messageManager->expects( $this->once() )->method( - 'addExceptionMessage' + 'addException' )->with( $this->equalTo($exception), $this->equalTo('Something went wrong while resetting customer password.') @@ -502,7 +502,7 @@ public function testResetPasswordActionSendEmail() $this->messageManager->expects( $this->once() )->method( - 'addSuccessMessage' + 'addSuccess' )->with( $this->equalTo('The customer will receive an email with a link to reset password.') ); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php index 9724ac13dde8c..57f384d32d980 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php @@ -338,12 +338,10 @@ public function testExecuteWithExistentCustomer() $this->requestMock->expects($this->atLeastOnce()) ->method('getPostValue') - ->willReturnMap( - [ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ] - ); + ->willReturnMap([ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ]); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -477,7 +475,7 @@ public function testExecuteWithExistentCustomer() ->with(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId); $this->messageManagerMock->expects($this->once()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with(__('You saved the customer.')) ->willReturnSelf(); @@ -544,12 +542,10 @@ public function testExecuteWithNewCustomer() $this->requestMock->expects($this->any()) ->method('getPostValue') - ->willReturnMap( - [ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ] - ); + ->willReturnMap([ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ]); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -666,7 +662,7 @@ public function testExecuteWithNewCustomer() ->with(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId); $this->messageManagerMock->expects($this->once()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with(__('You saved the customer.')) ->willReturnSelf(); @@ -727,12 +723,10 @@ public function testExecuteWithNewCustomerAndValidationException() $this->requestMock->expects($this->any()) ->method('getPostValue') - ->willReturnMap( - [ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ] - ); + ->willReturnMap([ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ]); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -810,7 +804,7 @@ public function testExecuteWithNewCustomerAndValidationException() ->method('register'); $this->messageManagerMock->expects($this->never()) - ->method('addSuccessMessage'); + ->method('addSuccess'); $this->messageManagerMock->expects($this->once()) ->method('addMessage') @@ -818,12 +812,10 @@ public function testExecuteWithNewCustomerAndValidationException() $this->sessionMock->expects($this->once()) ->method('setCustomerFormData') - ->with( - [ - 'customer' => $extractedData, - 'subscription' => $subscription, - ] - ); + ->with([ + 'customer' => $extractedData, + 'subscription' => $subscription, + ]); /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) @@ -878,12 +870,10 @@ public function testExecuteWithNewCustomerAndLocalizedException() $this->requestMock->expects($this->any()) ->method('getPostValue') - ->willReturnMap( - [ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ] - ); + ->willReturnMap([ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ]); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -961,7 +951,7 @@ public function testExecuteWithNewCustomerAndLocalizedException() ->method('register'); $this->messageManagerMock->expects($this->never()) - ->method('addSuccessMessage'); + ->method('addSuccess'); $this->messageManagerMock->expects($this->once()) ->method('addMessage') @@ -969,12 +959,10 @@ public function testExecuteWithNewCustomerAndLocalizedException() $this->sessionMock->expects($this->once()) ->method('setCustomerFormData') - ->with( - [ - 'customer' => $extractedData, - 'subscription' => $subscription, - ] - ); + ->with([ + 'customer' => $extractedData, + 'subscription' => $subscription, + ]); /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) @@ -1029,12 +1017,10 @@ public function testExecuteWithNewCustomerAndException() $this->requestMock->expects($this->any()) ->method('getPostValue') - ->willReturnMap( - [ - [null, null, $postValue], - [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], - ] - ); + ->willReturnMap([ + [null, null, $postValue], + [CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, null, $postValue['customer']], + ]); $this->requestMock->expects($this->atLeastOnce()) ->method('getPost') ->willReturnMap( @@ -1113,20 +1099,18 @@ public function testExecuteWithNewCustomerAndException() ->method('register'); $this->messageManagerMock->expects($this->never()) - ->method('addSuccessMessage'); + ->method('addSuccess'); $this->messageManagerMock->expects($this->once()) - ->method('addExceptionMessage') + ->method('addException') ->with($exception, __('Something went wrong while saving the customer.')); $this->sessionMock->expects($this->once()) ->method('setCustomerFormData') - ->with( - [ - 'customer' => $extractedData, - 'subscription' => $subscription, - ] - ); + ->with([ + 'customer' => $extractedData, + 'subscription' => $subscription, + ]); /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Locks/UnlockTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Locks/UnlockTest.php index 55b4092af7141..c92d4ed7812ba 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Locks/UnlockTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Locks/UnlockTest.php @@ -118,7 +118,7 @@ public function testExecute() ->with($this->equalTo('customer_id')) ->will($this->returnValue($customerId)); $this->authenticationMock->expects($this->once())->method('unlock')->with($customerId); - $this->messageManagerMock->expects($this->once())->method('addSuccessMessage'); + $this->messageManagerMock->expects($this->once())->method('addSuccess'); $this->redirectMock->expects($this->once()) ->method('setPath') ->with($this->equalTo('customer/index/edit')) @@ -141,7 +141,7 @@ public function testExecuteWithException() ->method('unlock') ->with($customerId) ->willThrowException(new \Exception($phrase)); - $this->messageManagerMock->expects($this->once())->method('addErrorMessage'); + $this->messageManagerMock->expects($this->once())->method('addError'); $this->controller->execute(); } } diff --git a/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php b/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php index 79766178a7670..8592d1bda66c1 100644 --- a/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php +++ b/app/code/Magento/Customer/Test/Unit/Observer/AfterAddressSaveObserverTest.php @@ -210,11 +210,9 @@ public function testAfterAddressSaveRestricted( $observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getCustomerAddress', - ] - ) + ->setMethods([ + 'getCustomerAddress', + ]) ->getMock(); $observer->expects($this->once()) ->method('getCustomerAddress') @@ -227,12 +225,10 @@ public function testAfterAddressSaveRestricted( $this->registry->expects($this->any()) ->method('registry') - ->willReturnMap( - [ - [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, $processedFlag], - [BeforeAddressSaveObserver::VIV_CURRENTLY_SAVED_ADDRESS, $registeredAddressId], - ] - ); + ->willReturnMap([ + [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, $processedFlag], + [BeforeAddressSaveObserver::VIV_CURRENTLY_SAVED_ADDRESS, $registeredAddressId], + ]); $this->helperAddress->expects($this->any()) ->method('getTaxCalculationAddressType') @@ -270,13 +266,11 @@ public function testAfterAddressSaveException() $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getCustomer', - 'getForceProcess', - 'getVatId', - ] - ) + ->setMethods([ + 'getCustomer', + 'getForceProcess', + 'getVatId', + ]) ->getMock(); $address->expects($this->any()) ->method('getCustomer') @@ -290,11 +284,9 @@ public function testAfterAddressSaveException() $observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getCustomerAddress', - ] - ) + ->setMethods([ + 'getCustomerAddress', + ]) ->getMock(); $observer->expects($this->once()) ->method('getCustomerAddress') @@ -311,12 +303,10 @@ public function testAfterAddressSaveException() ->willReturn(false); $this->registry->expects($this->any()) ->method('register') - ->willReturnMap( - [ - [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, true, false, $this->registry], - [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, false, true, $this->registry], - ] - ); + ->willReturnMap([ + [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, true, false, $this->registry], + [AfterAddressSaveObserver::VIV_PROCESSED_FLAG, false, true, $this->registry], + ]); $this->model->execute($observer); } @@ -346,15 +336,13 @@ public function testAfterAddressSaveDefaultGroup( $customer = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getStore', - 'getDisableAutoGroupChange', - 'getGroupId', - 'setGroupId', - 'save', - ] - ) + ->setMethods([ + 'getStore', + 'getDisableAutoGroupChange', + 'getGroupId', + 'setGroupId', + 'save', + ]) ->getMock(); $customer->expects($this->exactly(2)) ->method('getStore') @@ -375,14 +363,12 @@ public function testAfterAddressSaveDefaultGroup( $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getCustomer', - 'getForceProcess', - 'getVatId', - 'getCountry', - ] - ) + ->setMethods([ + 'getCustomer', + 'getForceProcess', + 'getVatId', + 'getCountry', + ]) ->getMock(); $address->expects($this->once()) ->method('getCustomer') @@ -399,11 +385,9 @@ public function testAfterAddressSaveDefaultGroup( $observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getCustomerAddress', - ] - ) + ->setMethods([ + 'getCustomerAddress', + ]) ->getMock(); $observer->expects($this->once()) ->method('getCustomerAddress') @@ -473,12 +457,10 @@ public function testAfterAddressSaveNewGroup( $validationResult = $this->getMockBuilder(\Magento\Framework\DataObject::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getIsValid', - 'getRequestSuccess', - ] - ) + ->setMethods([ + 'getIsValid', + 'getRequestSuccess', + ]) ->getMock(); $validationResult->expects($this->any()) ->method('getIsValid') @@ -489,15 +471,13 @@ public function testAfterAddressSaveNewGroup( $customer = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getStore', - 'getDisableAutoGroupChange', - 'getGroupId', - 'setGroupId', - 'save', - ] - ) + ->setMethods([ + 'getStore', + 'getDisableAutoGroupChange', + 'getGroupId', + 'setGroupId', + 'save', + ]) ->getMock(); $customer->expects($this->exactly(2)) ->method('getStore') @@ -523,16 +503,14 @@ public function testAfterAddressSaveNewGroup( $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getCustomer', - 'getForceProcess', - 'getVatId', - 'getCountryId', - 'getCountry', - 'setVatValidationResult', - ] - ) + ->setMethods([ + 'getCustomer', + 'getForceProcess', + 'getVatId', + 'getCountryId', + 'getCountry', + 'setVatValidationResult', + ]) ->getMock(); $address->expects($this->any()) ->method('getCustomer') @@ -556,11 +534,9 @@ public function testAfterAddressSaveNewGroup( $observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getCustomerAddress', - ] - ) + ->setMethods([ + 'getCustomerAddress', + ]) ->getMock(); $observer->expects($this->once()) ->method('getCustomerAddress') @@ -599,7 +575,7 @@ public function testAfterAddressSaveNewGroup( if ($resultValidMessage) { $this->messageManager->expects($this->once()) - ->method('addSuccessMessage') + ->method('addSuccess') ->with($resultValidMessage) ->willReturnSelf(); } @@ -609,7 +585,7 @@ public function testAfterAddressSaveNewGroup( ->with($vatId) ->willReturn($vatId); $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with($resultInvalidMessage) ->willReturnSelf(); } @@ -619,7 +595,7 @@ public function testAfterAddressSaveNewGroup( ->with('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE) ->willReturn('admin@example.com'); $this->messageManager->expects($this->once()) - ->method('addErrorMessage') + ->method('addError') ->with($resultErrorMessage) ->willReturnSelf(); } diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index e43bc4af1fcae..c31742519e581 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -77,28 +77,4 @@ - - - - - \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE - - Magento_Customer::messages/customerAlreadyExistsErrorMessage.phtml - - - - \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE - - Magento_Customer::messages/confirmAccountSuccessMessage.phtml - - - - \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE - - Magento_Customer::messages/unableDeleteAddressMessage.phtml - - - - - - + \ No newline at end of file diff --git a/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml b/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml deleted file mode 100644 index a5313078e13cc..0000000000000 --- a/app/code/Magento/Customer/view/frontend/templates/messages/unableDeleteAddressMessage.phtml +++ /dev/null @@ -1,9 +0,0 @@ - -escapeHtml(__('We can\'t delete the address right now.')); From d12a2ab560aab2290df06cac5047be3edbb09991 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Sun, 25 Aug 2019 08:13:11 +0300 Subject: [PATCH 09/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento/Customer/Controller/Account/CreatePost.php --- .../Controller/Account/CreatePost.php | 78 ++++++++++++++----- .../Controller/Account/CreatePostTest.php | 38 +++++---- app/code/Magento/Customer/etc/frontend/di.xml | 32 +++++++- ...tomerVatBillingAddressSuccessMessage.phtml | 9 +++ ...omerVatShippingAddressSuccessMessage.phtml | 9 +++ 5 files changed, 129 insertions(+), 37 deletions(-) create mode 100644 app/code/Magento/Customer/view/frontend/templates/messages/customerVatBillingAddressSuccessMessage.phtml create mode 100644 app/code/Magento/Customer/view/frontend/templates/messages/customerVatShippingAddressSuccessMessage.phtml diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index a2be0f68b56cb..2145d7dba0049 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -21,6 +21,7 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Message\MessageInterface; use Magento\Framework\Phrase; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\AccountManagementInterface; @@ -118,6 +119,11 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht */ protected $session; + /** + * @var StoreManagerInterface + */ + protected $storeManager; + /** * @var AccountRedirect */ @@ -365,20 +371,19 @@ public function execute() ); $confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) { - $email = $this->customerUrl->getEmailConfirmationUrl($customer->getEmail()); - // @codingStandardsIgnoreStart - $this->messageManager->addSuccess( - __( - 'You must confirm your account. Please check your email for the confirmation link or click here for a new link.', - $email - ) + $this->messageManager->addComplexSuccessMessage( + 'confirmAccountSuccessMessage', + [ + 'url' => $this->customerUrl->getEmailConfirmationUrl($customer->getEmail()), + ] ); - // @codingStandardsIgnoreEnd $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); $resultRedirect->setUrl($this->_redirect->success($url)); } else { $this->session->setCustomerDataAsLoggedIn($customer); - $this->messageManager->addSuccess($this->getSuccessMessage()); + + $this->messageManager->addMessage($this->getMessageManagerSuccessMessage()); + $requestedRedirect = $this->accountRedirect->getRedirectCookie(); if (!$this->scopeConfig->getValue('customer/startup/redirect_dashboard') && $requestedRedirect) { $resultRedirect->setUrl($this->_redirect->success($requestedRedirect)); @@ -395,23 +400,21 @@ public function execute() return $resultRedirect; } catch (StateException $e) { - $url = $this->urlModel->getUrl('customer/account/forgotpassword'); - // @codingStandardsIgnoreStart - $message = __( - 'There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account.', - $url + $this->messageManager->addComplexErrorMessage( + 'customerAlreadyExistsErrorMessage', + [ + 'url' => $this->urlModel->getUrl('customer/account/forgotpassword'), + ] ); - // @codingStandardsIgnoreEnd - $this->messageManager->addError($message); } catch (InputException $e) { - $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage())); + $this->messageManager->addErrorMessage($e->getMessage()); foreach ($e->getErrors() as $error) { - $this->messageManager->addError($this->escaper->escapeHtml($error->getMessage())); + $this->messageManager->addErrorMessage($error->getMessage()); } } catch (LocalizedException $e) { - $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage())); + $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { - $this->messageManager->addException($e, __('We can\'t save the customer.')); + $this->messageManager->addExceptionMessage($e, __('We can\'t save the customer.')); } $this->session->setCustomerFormData($this->getRequest()->getPostValue()); @@ -437,6 +440,8 @@ protected function checkPasswordConfirmation($password, $confirmation) /** * Retrieve success message * + * @deprecated + * @see getMessageManagerSuccessMessage() * @return string */ protected function getSuccessMessage() @@ -462,4 +467,37 @@ protected function getSuccessMessage() } return $message; } + + /** + * Retrieve success message manager message + * + * @return MessageInterface + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + protected function getMessageManagerSuccessMessage(): MessageInterface + { + if ($this->addressHelper->isVatValidationEnabled()) { + if ($this->addressHelper->getTaxCalculationAddressType() == Address::TYPE_SHIPPING) { + $identifier = 'customerVatShippingAddressSuccessMessage'; + } else { + $identifier = 'customerVatBillingAddressSuccessMessage'; + } + + $message = $this->messageManager + ->createMessage(MessageInterface::TYPE_SUCCESS, $identifier) + ->setData( + [ + 'url' => $this->urlModel->getUrl('customer/address/edit'), + ] + ); + } else { + $message = $this->messageManager + ->createMessage(MessageInterface::TYPE_SUCCESS) + ->setText( + __('Thank you for registering with %1.', $this->storeManager->getStore()->getFrontendName()) + ); + } + + return $message; + } } diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php index f8f47eedba3ef..faf55347dba78 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php @@ -346,11 +346,13 @@ public function testSuccessMessage( $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap([ - ['password', null, $password], - ['password_confirmation', null, $password], - ['is_subscribed', false, true], - ]); + ->willReturnMap( + [ + ['password', null, $password], + ['password_confirmation', null, $password], + ['is_subscribed', false, true], + ] + ); $this->customerMock->expects($this->once()) ->method('setAddresses') @@ -371,7 +373,7 @@ public function testSuccessMessage( ->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with($this->stringContains($successMessage)) ->will($this->returnSelf()); @@ -477,11 +479,13 @@ public function testSuccessRedirect( $this->requestMock->expects($this->any()) ->method('getParam') - ->willReturnMap([ - ['password', null, $password], - ['password_confirmation', null, $password], - ['is_subscribed', false, true], - ]); + ->willReturnMap( + [ + ['password', null, $password], + ['password_confirmation', null, $password], + ['is_subscribed', false, true], + ] + ); $this->customerMock->expects($this->once()) ->method('setAddresses') @@ -502,16 +506,18 @@ public function testSuccessRedirect( ->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any()) - ->method('addSuccess') + ->method('addSuccessMessage') ->with($this->stringContains($successMessage)) ->will($this->returnSelf()); $this->urlMock->expects($this->any()) ->method('getUrl') - ->willReturnMap([ - ['*/*/index', ['_secure' => true], $successUrl], - ['*/*/create', ['_secure' => true], $successUrl], - ]); + ->willReturnMap( + [ + ['*/*/index', ['_secure' => true], $successUrl], + ['*/*/create', ['_secure' => true], $successUrl], + ] + ); $this->redirectMock->expects($this->once()) ->method('success') ->with($this->equalTo($successUrl)) diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index c31742519e581..3b9675178c052 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -77,4 +77,34 @@ - \ No newline at end of file + + + + + \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE + + Magento_Customer::messages/customerAlreadyExistsErrorMessage.phtml + + + + \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE + + Magento_Customer::messages/confirmAccountSuccessMessage.phtml + + + + \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE + + Magento_Customer::messages/customerVatShippingAddressSuccessMessage.phtml + + + + \Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE + + Magento_Customer::messages/customerVatBillingAddressSuccessMessage.phtml + + + + + + diff --git a/app/code/Magento/Customer/view/frontend/templates/messages/customerVatBillingAddressSuccessMessage.phtml b/app/code/Magento/Customer/view/frontend/templates/messages/customerVatBillingAddressSuccessMessage.phtml new file mode 100644 index 0000000000000..294412cbc706d --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/templates/messages/customerVatBillingAddressSuccessMessage.phtml @@ -0,0 +1,9 @@ + +escapeHtml(__('If you are a registered VAT customer, please click here to enter your billing address for proper VAT calculation.', $block->getData('url')), ['a']); diff --git a/app/code/Magento/Customer/view/frontend/templates/messages/customerVatShippingAddressSuccessMessage.phtml b/app/code/Magento/Customer/view/frontend/templates/messages/customerVatShippingAddressSuccessMessage.phtml new file mode 100644 index 0000000000000..72dbf3f5e03d4 --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/templates/messages/customerVatShippingAddressSuccessMessage.phtml @@ -0,0 +1,9 @@ + +escapeHtml(__('If you are a registered VAT customer, please click here to enter your shipping address for proper VAT calculation.', $block->getData('url')), ['a']); From dd344523c67bf0af3d1f8e6a43af62a8e993bf26 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Sun, 25 Aug 2019 14:36:48 +0300 Subject: [PATCH 10/10] magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento/Customer/Controller/Account/CreatePost.php --- app/code/Magento/Customer/Controller/Account/CreatePost.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index 2145d7dba0049..57b670684411e 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -474,7 +474,7 @@ protected function getSuccessMessage() * @return MessageInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ - protected function getMessageManagerSuccessMessage(): MessageInterface + private function getMessageManagerSuccessMessage(): MessageInterface { if ($this->addressHelper->isVatValidationEnabled()) { if ($this->addressHelper->getTaxCalculationAddressType() == Address::TYPE_SHIPPING) {