Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Replacing deprecated methods for tests. #17872

Merged
merged 7 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function setUp()
false,
true,
true,
['addSuccess']
['addSuccessMessage']
);
$this->categoryRepository = $this->createMock(\Magento\Catalog\Api\CategoryRepositoryInterface::class);
$context->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function setUp()
false,
true,
true,
['addSuccess', 'getMessages']
['addSuccessMessage', 'getMessages']
);

$this->save = $this->objectManager->getObject(
Expand Down Expand Up @@ -392,7 +392,7 @@ public function testExecute($categoryId, $storeId, $parentId)
$categoryMock->expects($this->once())
->method('save');
$this->messageManagerMock->expects($this->once())
->method('addSuccess')
->method('addSuccessMessage')
->with(__('You saved the category.'));
$categoryMock->expects($this->at(1))
->method('getId')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function prepareContext()
$messageManager = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)
->setMethods([])
->disableOriginalConstructor()->getMock();
$messageManager->expects($this->any())->method('addError')->willReturn(true);
$messageManager->expects($this->any())->method('addErrorMessage')->willReturn(true);
$this->context = $this->getMockBuilder(\Magento\Backend\App\Action\Context::class)
->setMethods(['getRequest', 'getObjectManager', 'getMessageManager', 'getResultRedirectFactory'])
->disableOriginalConstructor()->getMock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ public function testExecuteThatProductIdsAreObtainedFromAttributeHelper()
['inventory', [], [7]],
]));

$this->messageManager->expects($this->never())->method('addError');
$this->messageManager->expects($this->never())->method('addException');
$this->messageManager->expects($this->never())->method('addErrorMessage');
$this->messageManager->expects($this->never())->method('addExceptionMessage');

$this->object->execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ public function execute()
if (count($template->getSystemConfigPathsWhereCurrentlyUsed()) == 0) {
$template->delete();
// display success message
$this->messageManager->addSuccess(__('You deleted the email template.'));
$this->messageManager->addSuccessMessage(__('You deleted the email template.'));
$this->_objectManager->get(\Magento\Framework\App\ReinitableConfig::class)->reinit();
// go to grid
$this->_redirect('adminhtml/*/');
return;
}
// display error message
$this->messageManager->addError(__('The email template is currently being used.'));
$this->messageManager->addErrorMessage(__('The email template is currently being used.'));
// redirect to edit form
$this->_redirect('adminhtml/*/edit', ['id' => $template->getId()]);
return;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(
$this->messageManager->addErrorMessage(
__('We can\'t delete email template data right now. Please review log and try again.')
);
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
Expand All @@ -52,7 +52,7 @@ public function execute()
}
}
// display error message
$this->messageManager->addError(__('We can\'t find an email template to delete.'));
$this->messageManager->addErrorMessage(__('We can\'t find an email template to delete.'));
// go to grid
$this->_redirect('adminhtml/*/');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function execute()
$this->_view->renderLayout();
$this->getResponse()->setHeader('Content-Security-Policy', "script-src 'none'");
} catch (\Exception $e) {
$this->messageManager->addError(__('An error occurred. The email template can not be opened for preview.'));
$this->messageManager->addErrorMessage(
__('An error occurred. The email template can not be opened for preview.')
);
$this->_redirect('adminhtml/*/');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function execute()

$template = $this->_initTemplate('id');
if (!$template->getId() && $id) {
$this->messageManager->addError(__('This email template no longer exists.'));
$this->messageManager->addErrorMessage(__('This email template no longer exists.'));
$this->_redirect('adminhtml/*/');
return;
}
Expand Down Expand Up @@ -55,7 +55,7 @@ public function execute()

$template->save();
$this->_objectManager->get(\Magento\Backend\Model\Session::class)->setFormData(false);
$this->messageManager->addSuccess(__('You saved the email template.'));
$this->messageManager->addSuccessMessage(__('You saved the email template.'));
$this->_redirect('adminhtml/*');
} catch (\Exception $e) {
$this->_objectManager->get(
Expand All @@ -64,7 +64,7 @@ public function execute()
'email_template_form_data',
$request->getParams()
);
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
$this->_forward('new');
}
}
Expand Down
10 changes: 6 additions & 4 deletions app/code/Magento/Search/Controller/Adminhtml/Synonyms/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ public function execute()
/** @var \Magento\Search\Model\SynonymGroup $synGroupModel */
$synGroupModel = $this->synGroupRepository->get($id);
$this->synGroupRepository->delete($synGroupModel);
$this->messageManager->addSuccess(__('The synonym group has been deleted.'));
$this->messageManager->addSuccessMessage(__('The synonym group has been deleted.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
$this->logger->error($e);
} catch (\Exception $e) {
$this->messageManager->addError(__('An error was encountered while performing delete operation.'));
$this->messageManager->addErrorMessage(
__('An error was encountered while performing delete operation.')
);
$this->logger->error($e);
}
} else {
$this->messageManager->addError(__('We can\'t find a synonym group to delete.'));
$this->messageManager->addErrorMessage(__('We can\'t find a synonym group to delete.'));
}

return $resultRedirect->setPath('*/*/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function execute()

// 2. Initial checking
if ($groupId && (!$synGroup->getGroupId())) {
$this->messageManager->addError(__('This synonyms group no longer exists.'));
$this->messageManager->addErrorMessage(__('This synonyms group no longer exists.'));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('*/*/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ public function execute()
$this->synGroupRepository->delete($synonymGroup);
$deletedItems++;
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
}
}
if ($deletedItems != 0) {
if ($collectionSize != $deletedItems) {
$this->messageManager->addError(
$this->messageManager->addErrorMessage(
__('Failed to delete %1 synonym group(s).', $collectionSize - $deletedItems)
);
}

$this->messageManager->addSuccess(
$this->messageManager->addSuccessMessage(
__('A total of %1 synonym group(s) have been deleted.', $deletedItems)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function execute()
$synGroup = $this->synGroupRepository->get($synGroupId);

if (!$synGroup->getGroupId() && $synGroupId) {
$this->messageManager->addError(__('This synonym group no longer exists.'));
$this->messageManager->addErrorMessage(__('This synonym group no longer exists.'));
return $resultRedirect->setPath('*/*/');
}

Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ public function execute()
$model = $this->_objectManager->create(\Magento\Search\Model\Query::class);
$model->setId($id);
$model->delete();
$this->messageManager->addSuccess(__('You deleted the search.'));
$this->messageManager->addSuccessMessage(__('You deleted the search.'));
$resultRedirect->setPath('search/*/');
return $resultRedirect;
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
$resultRedirect->setPath('search/*/edit', ['id' => $this->getRequest()->getParam('id')]);
return $resultRedirect;
}
}
$this->messageManager->addError(__('We can\'t find a search term to delete.'));
$this->messageManager->addErrorMessage(__('We can\'t find a search term to delete.'));
$resultRedirect->setPath('search/*/');
return $resultRedirect;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function execute()
if ($id) {
$model->load($id);
if (!$model->getId()) {
$this->messageManager->addError(__('This search no longer exists.'));
$this->messageManager->addErrorMessage(__('This search no longer exists.'));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('search/*');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ public function execute()
{
$searchIds = $this->getRequest()->getParam('search');
if (!is_array($searchIds)) {
$this->messageManager->addError(__('Please select searches.'));
$this->messageManager->addErrorMessage(__('Please select searches.'));
} else {
try {
foreach ($searchIds as $searchId) {
$model = $this->_objectManager->create(\Magento\Search\Model\Query::class)->load($searchId);
$model->delete();
}
$this->messageManager->addSuccess(__('Total of %1 record(s) were deleted.', count($searchIds)));
$this->messageManager->addSuccessMessage(__('Total of %1 record(s) were deleted.', count($searchIds)));
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
}
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
Expand Down
9 changes: 6 additions & 3 deletions app/code/Magento/Search/Controller/Adminhtml/Term/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ public function execute()
$model->addData($data);
$model->setIsProcessed(0);
$model->save();
$this->messageManager->addSuccess(__('You saved the search term.'));
$this->messageManager->addSuccessMessage(__('You saved the search term.'));
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
return $this->proceedToEdit($data);
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while saving the search query.'));
$this->messageManager->addExceptionMessage(
$e,
__('Something went wrong while saving the search query.')
);
return $this->proceedToEdit($data);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public function testDeleteAction()
$this->repository->expects($this->once())->method('get')->with(10)->willReturn($this->synonymGroupMock);

$this->messageManagerMock->expects($this->once())
->method('addSuccess')
->method('addSuccessMessage')
->with(__('The synonym group has been deleted.'));

$this->messageManagerMock->expects($this->never())->method('addError');
$this->messageManagerMock->expects($this->never())->method('addErrorMessage');

$this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();

Expand All @@ -124,10 +124,10 @@ public function testDeleteActionNoId()
->willReturn(null);

$this->messageManagerMock->expects($this->once())
->method('addError')
->method('addErrorMessage')
->with(__('We can\'t find a synonym group to delete.'));
$this->messageManagerMock->expects($this->never())
->method('addSuccess');
->method('addSuccessMessage');

$this->resultRedirectMock->expects($this->once())
->method('setPath')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function setUp()
->getMockForAbstractClass();
$this->messageManager = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)
->disableOriginalConstructor()
->setMethods(['addSuccess', 'addError'])
->setMethods(['addSuccessMessage', 'addErrorMessage'])
->getMockForAbstractClass();
$this->pageFactory = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class)
->setMethods([])
Expand Down Expand Up @@ -107,7 +107,7 @@ public function testExecute()
$this->createQuery(0, 1);
$this->createQuery(1, 2);
$this->messageManager->expects($this->once())
->method('addSuccess')
->method('addSuccessMessage')
->will($this->returnSelf());
$this->resultRedirectMock->expects($this->once())
->method('setPath')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function setUp()

$this->messageManager = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)
->disableOriginalConstructor()
->setMethods(['addSuccess', 'addError', 'addException'])
->setMethods(['addSuccessMessage', 'addErrorMessage', 'addExceptionMessage'])
->getMockForAbstractClass();
$this->context->expects($this->any())
->method('getMessageManager')
Expand Down Expand Up @@ -143,7 +143,7 @@ public function testExecuteLoadQueryQueryId()
$this->query->expects($this->once())->method('getId')->willReturn(false);
$this->query->expects($this->once())->method('load')->with($queryId);

$this->messageManager->expects($this->once())->method('addSuccess');
$this->messageManager->expects($this->once())->method('addSuccessMessage');

$this->redirect->expects($this->once())->method('setPath')->willReturnSelf();
$this->assertSame($this->redirect, $this->controller->execute());
Expand All @@ -161,7 +161,7 @@ public function testExecuteLoadQueryQueryIdQueryText()
$this->query->expects($this->once())->method('loadByQueryText')->with($queryText);
$this->query->expects($this->any())->method('getId')->willReturn($queryId);

$this->messageManager->expects($this->once())->method('addSuccess');
$this->messageManager->expects($this->once())->method('addSuccessMessage');

$this->redirect->expects($this->once())->method('setPath')->willReturnSelf();
$this->assertSame($this->redirect, $this->controller->execute());
Expand All @@ -180,7 +180,7 @@ public function testExecuteLoadQueryQueryIdQueryText2()
$this->query->expects($this->any())->method('getId')->willReturn(false);
$this->query->expects($this->once())->method('load')->with($queryId);

$this->messageManager->expects($this->once())->method('addSuccess');
$this->messageManager->expects($this->once())->method('addSuccessMessage');

$this->redirect->expects($this->once())->method('setPath')->willReturnSelf();
$this->assertSame($this->redirect, $this->controller->execute());
Expand All @@ -199,7 +199,7 @@ public function testExecuteLoadQueryQueryIdQueryTextException()
$this->query->expects($this->once())->method('loadByQueryText')->with($queryText);
$this->query->expects($this->any())->method('getId')->willReturn($anotherQueryId);

$this->messageManager->expects($this->once())->method('addError');
$this->messageManager->expects($this->once())->method('addErrorMessage');
$this->session->expects($this->once())->method('setPageData');
$this->redirect->expects($this->once())->method('setPath')->willReturnSelf();
$this->assertSame($this->redirect, $this->controller->execute());
Expand All @@ -216,7 +216,7 @@ public function testExecuteException()
$this->query->expects($this->once())->method('setStoreId');
$this->query->expects($this->once())->method('loadByQueryText')->willThrowException(new \Exception());

$this->messageManager->expects($this->once())->method('addException');
$this->messageManager->expects($this->once())->method('addExceptionMessage');
$this->session->expects($this->once())->method('setPageData');
$this->redirect->expects($this->once())->method('setPath')->willReturnSelf();
$this->assertSame($this->redirect, $this->controller->execute());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function execute()
{
try {
$this->sessionsManager->logoutOtherUserSessions();
$this->messageManager->addSuccess(__('All other open sessions for this account were terminated.'));
$this->messageManager->addSuccessMessage(__('All other open sessions for this account were terminated.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __("We couldn't logout because of an error."));
$this->messageManager->addExceptionMessage($e, __("We couldn't logout because of an error."));
}
$this->_redirect('*/*/activity');
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Security/Model/Plugin/AuthSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function addUserLogoutNotification()
$this->sessionsManager->getCurrentSession()->getStatus()
);
} elseif ($message = $this->sessionsManager->getLogoutReasonMessage()) {
$this->messageManager->addError($message);
$this->messageManager->addErrorMessage($message);
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Security/Model/Plugin/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function beforeExecute(Login $login)
{
$logoutReasonCode = $this->securityCookie->getLogoutReasonCookie();
if ($this->isLoginForm($login) && $logoutReasonCode >= 0) {
$this->messageManager->addError(
$this->messageManager->addErrorMessage(
$this->sessionsManager->getLogoutReasonMessageByStatus($logoutReasonCode)
);
$this->securityCookie->deleteLogoutReasonCookie();
Expand Down
Loading