diff --git a/app/code/Magento/Catalog/Controller/Product/View.php b/app/code/Magento/Catalog/Controller/Product/View.php index 2fcf61900f3ff..0a06c8d0b9e0a 100644 --- a/app/code/Magento/Catalog/Controller/Product/View.php +++ b/app/code/Magento/Catalog/Controller/Product/View.php @@ -18,7 +18,7 @@ class View extends \Magento\Catalog\Controller\Product protected $viewHelper; /** - * @var \Magento\Framework\Controller\Result\Redirect + * @var \Magento\Framework\Controller\Result\RedirectFactory */ protected $resultRedirectFactory; diff --git a/app/code/Magento/Catalog/Helper/Product/Composite.php b/app/code/Magento/Catalog/Helper/Product/Composite.php index cb29ce5f7e883..eca50adc3e225 100644 --- a/app/code/Magento/Catalog/Helper/Product/Composite.php +++ b/app/code/Magento/Catalog/Helper/Product/Composite.php @@ -7,7 +7,7 @@ use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\App\Helper\Context; -use Magento\Framework\App\ViewInterface; +use Magento\Framework\View\Result\LayoutFactory; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Catalog\Helper\Product; use Magento\Store\Model\StoreManagerInterface; @@ -43,9 +43,9 @@ class Composite extends \Magento\Framework\App\Helper\AbstractHelper protected $_storeManager; /** - * @var ViewInterface + * @var \Magento\Framework\View\Result\LayoutFactory */ - protected $_view; + protected $resultLayoutFactory; /** * @var ProductRepositoryInterface @@ -62,7 +62,7 @@ class Composite extends \Magento\Framework\App\Helper\AbstractHelper * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param Product $catalogProduct * @param Registry $coreRegistry - * @param ViewInterface $view + * @param LayoutFactory $resultLayoutFactory * @param ProductRepositoryInterface $productRepository * @param CustomerRepositoryInterface $customerRepository */ @@ -71,14 +71,14 @@ public function __construct( StoreManagerInterface $storeManager, Product $catalogProduct, Registry $coreRegistry, - ViewInterface $view, + LayoutFactory $resultLayoutFactory, ProductRepositoryInterface $productRepository, CustomerRepositoryInterface $customerRepository ) { $this->_storeManager = $storeManager; $this->_coreRegistry = $coreRegistry; $this->_catalogProduct = $catalogProduct; - $this->_view = $view; + $this->resultLayoutFactory = $resultLayoutFactory; $this->productRepository = $productRepository; $this->customerRepository = $customerRepository; parent::__construct($context); @@ -87,15 +87,13 @@ public function __construct( /** * Init layout of product configuration update result * - * @return $this + * @return \Magento\Framework\View\Result\Layout */ protected function _initUpdateResultLayout() { - $this->_view->getLayout()->getUpdate()->addHandle('CATALOG_PRODUCT_COMPOSITE_UPDATE_RESULT'); - $this->_view->loadLayoutUpdates(); - $this->_view->generateLayoutXml(); - $this->_view->generateLayoutBlocks(); - return $this; + $resultLayout = $this->resultLayoutFactory->create(); + $resultLayout->addHandle('CATALOG_PRODUCT_COMPOSITE_UPDATE_RESULT'); + return $resultLayout; } /** @@ -103,14 +101,12 @@ protected function _initUpdateResultLayout() * when single configuration submitted * * @param \Magento\Framework\Object $updateResult - * @return void + * @return \Magento\Framework\View\Result\Layout */ public function renderUpdateResult(\Magento\Framework\Object $updateResult) { $this->_coreRegistry->register('composite_update_result', $updateResult); - - $this->_initUpdateResultLayout(); - $this->_view->renderLayout(); + return $this->_initUpdateResultLayout(); } /** @@ -121,24 +117,18 @@ public function renderUpdateResult(\Magento\Framework\Object $updateResult) * * @param bool $isOk * @param string $productType - * @return $this + * @return \Magento\Framework\View\Result\Layout */ protected function _initConfigureResultLayout($isOk, $productType) { - $update = $this->_view->getLayout()->getUpdate(); + $resultLayout = $this->resultLayoutFactory->create(); if ($isOk) { - $update->addHandle( - 'CATALOG_PRODUCT_COMPOSITE_CONFIGURE' - )->addHandle( - 'catalog_product_view_type_' . $productType - ); + $resultLayout->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE') + ->addHandle('catalog_product_view_type_' . $productType); } else { - $update->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE_ERROR'); + $resultLayout->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE_ERROR'); } - $this->_view->loadLayoutUpdates(); - $this->_view->generateLayoutXml(); - $this->_view->generateLayoutBlocks(); - return $this; + return $resultLayout; } /** @@ -149,7 +139,7 @@ protected function _initConfigureResultLayout($isOk, $productType) * - 'error' = true, and 'message' to show * * @param \Magento\Framework\Object $configureResult - * @return void + * @return \Magento\Framework\View\Result\Layout */ public function renderConfigureResult(\Magento\Framework\Object $configureResult) { @@ -194,7 +184,6 @@ public function renderConfigureResult(\Magento\Framework\Object $configureResult $this->_coreRegistry->register('composite_configure_result_error_message', $e->getMessage()); } - $this->_initConfigureResultLayout($isOk, $productType); - $this->_view->renderLayout(); + return $this->_initConfigureResultLayout($isOk, $productType); } } diff --git a/app/code/Magento/Customer/Controller/Account.php b/app/code/Magento/Customer/Controller/Account.php index 672fa9bded4fc..15b3136eb5427 100644 --- a/app/code/Magento/Customer/Controller/Account.php +++ b/app/code/Magento/Customer/Controller/Account.php @@ -8,6 +8,8 @@ use Magento\Customer\Model\Session; use Magento\Framework\App\Action\Context; use Magento\Framework\App\RequestInterface; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; /** * Customer account controller @@ -40,15 +42,31 @@ class Account extends \Magento\Framework\App\Action\Action /** @var Session */ protected $session; + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @var PageFactory + */ + protected $resultPageFactory; + /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory */ public function __construct( Context $context, - Session $customerSession + Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory ) { $this->session = $customerSession; + $this->resultRedirectFactory = $resultRedirectFactory; + $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } diff --git a/app/code/Magento/Customer/Controller/Account/Confirm.php b/app/code/Magento/Customer/Controller/Account/Confirm.php index b18a485c4f0e7..a42a81c43f858 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirm.php +++ b/app/code/Magento/Customer/Controller/Account/Confirm.php @@ -10,6 +10,8 @@ use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Api\CustomerRepositoryInterface; @@ -46,16 +48,22 @@ class Confirm extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param ScopeConfigInterface $scopeConfig * @param StoreManagerInterface $storeManager * @param AccountManagementInterface $customerAccountManagement * @param CustomerRepositoryInterface $customerRepository * @param Address $addressHelper * @param UrlFactory $urlFactory + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, AccountManagementInterface $customerAccountManagement, @@ -69,19 +77,22 @@ public function __construct( $this->customerRepository = $customerRepository; $this->addressHelper = $addressHelper; $this->urlModel = $urlFactory->create(); - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** * Confirm customer account by id and confirmation key * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + if ($this->_getSession()->isLoggedIn()) { - $this->_redirect('*/*/'); - return; + $resultRedirect->setPath('*/*/'); + return $resultRedirect; } try { $customerId = $this->getRequest()->getParam('id', false); @@ -96,8 +107,8 @@ public function execute() $this->_getSession()->setCustomerDataAsLoggedIn($customer); $this->messageManager->addSuccess($this->getSuccessMessage()); - $this->getResponse()->setRedirect($this->getSuccessRedirect()); - return; + $resultRedirect->setUrl($this->getSuccessRedirect()); + return $resultRedirect; } catch (StateException $e) { $this->messageManager->addException($e, __('This confirmation key is invalid or has expired.')); } catch (\Exception $e) { @@ -105,8 +116,8 @@ public function execute() } // die unhappy $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); - $this->getResponse()->setRedirect($this->_redirect->error($url)); - return; + $resultRedirect->setUrl($this->_redirect->error($url)); + return $resultRedirect; } /** diff --git a/app/code/Magento/Customer/Controller/Account/Confirmation.php b/app/code/Magento/Customer/Controller/Account/Confirmation.php index f3e0380b3629c..ba7ee81e3eaf8 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirmation.php +++ b/app/code/Magento/Customer/Controller/Account/Confirmation.php @@ -8,9 +8,10 @@ use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\AccountManagementInterface; -use Magento\Framework\UrlFactory; use Magento\Framework\Exception\State\InvalidTransitionException; class Confirmation extends \Magento\Customer\Controller\Account @@ -21,44 +22,47 @@ class Confirmation extends \Magento\Customer\Controller\Account /** @var AccountManagementInterface */ protected $customerAccountManagement; - /** @var \Magento\Framework\UrlInterface */ - protected $urlModel; - /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param StoreManagerInterface $storeManager * @param AccountManagementInterface $customerAccountManagement - * @param UrlFactory $urlFactory */ public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, StoreManagerInterface $storeManager, - AccountManagementInterface $customerAccountManagement, - UrlFactory $urlFactory + AccountManagementInterface $customerAccountManagement ) { $this->storeManager = $storeManager; $this->customerAccountManagement = $customerAccountManagement; - $this->urlModel = $urlFactory->create(); - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** * Send confirmation link to specified email * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function execute() { if ($this->_getSession()->isLoggedIn()) { - $this->_redirect('*/*/'); - return; + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('*/*/'); + return $resultRedirect; } // try to confirm by email $email = $this->getRequest()->getPost('email'); if ($email) { + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + try { $this->customerAccountManagement->resendConfirmation( $email, @@ -69,26 +73,20 @@ public function execute() $this->messageManager->addSuccess(__('This email does not require confirmation.')); } catch (\Exception $e) { $this->messageManager->addException($e, __('Wrong email.')); - $this->getResponse()->setRedirect( - $this->urlModel->getUrl('*/*/*', ['email' => $email, '_secure' => true]) - ); - return; + $resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]); + return $resultRedirect; } $this->_getSession()->setUsername($email); - $this->getResponse()->setRedirect($this->urlModel->getUrl('*/*/index', ['_secure' => true])); - return; + $resultRedirect->setPath('*/*/index', ['_secure' => true]); + return $resultRedirect; } - // output form - $this->_view->loadLayout(); - - $this->_view->getLayout()->getBlock( - 'accountConfirmation' - )->setEmail( + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->getBlock('accountConfirmation')->setEmail( $this->getRequest()->getParam('email', $email) ); - - $this->_view->getLayout()->initMessages(); - $this->_view->renderLayout(); + $resultPage->getLayout()->initMessages(); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Account/Create.php b/app/code/Magento/Customer/Controller/Account/Create.php index b0054e21a3c73..215f1a0198d18 100644 --- a/app/code/Magento/Customer/Controller/Account/Create.php +++ b/app/code/Magento/Customer/Controller/Account/Create.php @@ -8,6 +8,8 @@ use Magento\Customer\Model\Registration; use Magento\Customer\Model\Session; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; class Create extends \Magento\Customer\Controller\Account @@ -18,31 +20,38 @@ class Create extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param Registration $registration */ public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, Registration $registration ) { $this->registration = $registration; - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** * Customer register form page * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function execute() { if ($this->_getSession()->isLoggedIn() || !$this->registration->isAllowed()) { - $this->_redirect('*/*'); - return; + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('*/*'); + return $resultRedirect; } - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); - $this->_view->renderLayout(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->initMessages(); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Account/CreatePassword.php b/app/code/Magento/Customer/Controller/Account/CreatePassword.php index b75da9b3c619d..69f5eb09d5100 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePassword.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePassword.php @@ -8,6 +8,8 @@ use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Model\Session; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; class CreatePassword extends \Magento\Customer\Controller\Account @@ -18,21 +20,25 @@ class CreatePassword extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param AccountManagementInterface $customerAccountManagement */ public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, AccountManagementInterface $customerAccountManagement ) { $this->customerAccountManagement = $customerAccountManagement; - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** * Resetting password handler * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function execute() { @@ -40,19 +46,18 @@ public function execute() $customerId = (int)$this->getRequest()->getParam('id'); try { $this->customerAccountManagement->validateResetPasswordLinkToken($customerId, $resetPasswordToken); - $this->_view->loadLayout(); - // Pass received parameters to the reset forgotten password form - $this->_view->getLayout()->getBlock( - 'resetPassword' - )->setCustomerId( - $customerId - )->setResetPasswordLinkToken( - $resetPasswordToken - ); - $this->_view->renderLayout(); + + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->getBlock('resetPassword')->setCustomerId($customerId) + ->setResetPasswordLinkToken($resetPasswordToken); + return $resultPage; } catch (\Exception $exception) { $this->messageManager->addError(__('Your password reset link has expired.')); - $this->_redirect('*/*/forgotpassword'); + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('*/*/forgotpassword'); + return $resultRedirect; } } } diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index 69910d49243df..65668fdc4ed68 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -6,11 +6,12 @@ */ namespace Magento\Customer\Controller\Account; -use Magento\Customer\Model\AccountManagement; use Magento\Customer\Api\Data\AddressInterface; use Magento\Customer\Model\Url; use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\AccountManagementInterface; @@ -79,8 +80,10 @@ class CreatePost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param StoreManagerInterface $storeManager + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param ScopeConfigInterface $scopeConfig + * @param StoreManagerInterface $storeManager * @param AccountManagementInterface $accountManagement * @param Address $addressHelper * @param UrlFactory $urlFactory @@ -99,6 +102,8 @@ class CreatePost extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, AccountManagementInterface $accountManagement, @@ -128,7 +133,7 @@ public function __construct( $this->escaper = $escaper; $this->customerExtractor = $customerExtractor; $this->urlModel = $urlFactory->create(); - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** @@ -183,15 +188,17 @@ protected function extractAddress() */ public function execute() { + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if ($this->_getSession()->isLoggedIn() || !$this->registration->isAllowed()) { - $this->_redirect('*/*/'); - return; + $resultRedirect->setPath('*/*/'); + return $resultRedirect; } if (!$this->getRequest()->isPost()) { $url = $this->urlModel->getUrl('*/*/create', ['_secure' => true]); - $this->getResponse()->setRedirect($this->_redirect->error($url)); - return; + $resultRedirect->setUrl($this->_redirect->error($url)); + return $resultRedirect; } $this->_getSession()->regenerateId(); @@ -236,14 +243,14 @@ public function execute() ); // @codingStandardsIgnoreEnd $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); - $this->getResponse()->setRedirect($this->_redirect->success($url)); + $resultRedirect->setUrl($this->_redirect->success($url)); } else { $this->_getSession()->setCustomerDataAsLoggedIn($customer); $this->messageManager->addSuccess($this->getSuccessMessage()); - $this->getResponse()->setRedirect($this->getSuccessRedirect()); + $resultRedirect->setUrl($this->getSuccessRedirect()); } - return; + return $resultRedirect; } catch (StateException $e) { $url = $this->urlModel->getUrl('customer/account/forgotpassword'); // @codingStandardsIgnoreStart @@ -264,7 +271,8 @@ public function execute() $this->_getSession()->setCustomerFormData($this->getRequest()->getPost()); $defaultUrl = $this->urlModel->getUrl('*/*/create', ['_secure' => true]); - $this->getResponse()->setRedirect($this->_redirect->error($defaultUrl)); + $resultRedirect->setUrl($this->_redirect->error($defaultUrl)); + return $resultRedirect; } /** diff --git a/app/code/Magento/Customer/Controller/Account/Edit.php b/app/code/Magento/Customer/Controller/Account/Edit.php index 1581bddfb8990..1e81978865503 100644 --- a/app/code/Magento/Customer/Controller/Account/Edit.php +++ b/app/code/Magento/Customer/Controller/Account/Edit.php @@ -9,6 +9,8 @@ use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Api\Data\CustomerDataBuilder; use Magento\Customer\Model\Session; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; class Edit extends \Magento\Customer\Controller\Account @@ -22,31 +24,36 @@ class Edit extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param CustomerRepositoryInterface $customerRepository * @param CustomerDataBuilder $customerBuilder */ public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, CustomerRepositoryInterface $customerRepository, CustomerDataBuilder $customerBuilder ) { $this->customerRepository = $customerRepository; $this->customerBuilder = $customerBuilder; - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** * Forgot customer account information page * - * @return void + * @return \Magento\Framework\View\Result\Page */ public function execute() { - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->initMessages(); - $block = $this->_view->getLayout()->getBlock('customer_edit'); + $block = $resultPage->getLayout()->getBlock('customer_edit'); if ($block) { $block->setRefererUrl($this->_redirect->getRefererUrl()); } @@ -61,8 +68,8 @@ public function execute() $this->_getSession()->setCustomerData($customerDataObject); $this->_getSession()->setChangePassword($this->getRequest()->getParam('changepass') == 1); - $this->_view->getPage()->getConfig()->getTitle()->set(__('Account Information')); - $this->_view->getLayout()->getBlock('messages')->setEscapeMessageFlag(true); - $this->_view->renderLayout(); + $resultPage->getConfig()->getTitle()->set(__('Account Information')); + $resultPage->getLayout()->getBlock('messages')->setEscapeMessageFlag(true); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Account/EditPost.php b/app/code/Magento/Customer/Controller/Account/EditPost.php index fc910ab648bdd..52948a1104b8a 100644 --- a/app/code/Magento/Customer/Controller/Account/EditPost.php +++ b/app/code/Magento/Customer/Controller/Account/EditPost.php @@ -12,6 +12,8 @@ use Magento\Customer\Api\Data\CustomerDataBuilder; use Magento\Customer\Model\CustomerExtractor; use Magento\Customer\Model\Session; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; use Magento\Framework\Exception\AuthenticationException; use Magento\Framework\Exception\InputException; @@ -39,6 +41,8 @@ class EditPost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param AccountManagementInterface $customerAccountManagement * @param CustomerRepositoryInterface $customerRepository * @param CustomerDataBuilder $customerDataBuilder @@ -49,6 +53,8 @@ class EditPost extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, AccountManagementInterface $customerAccountManagement, CustomerRepositoryInterface $customerRepository, CustomerDataBuilder $customerDataBuilder, @@ -60,20 +66,22 @@ public function __construct( $this->customerDataBuilder = $customerDataBuilder; $this->formKeyValidator = $formKeyValidator; $this->customerExtractor = $customerExtractor; - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** * Change customer password action * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if (!$this->formKeyValidator->validate($this->getRequest())) { - $this->_redirect('*/*/edit'); - return; + $resultRedirect->setPath('*/*/edit'); + return $resultRedirect; } if ($this->getRequest()->isPost()) { @@ -123,15 +131,16 @@ public function execute() if ($this->messageManager->getMessages()->getCount() > 0) { $this->_getSession()->setCustomerFormData($this->getRequest()->getPost()); - $this->_redirect('*/*/edit'); - return; + $resultRedirect->setPath('*/*/edit'); + return $resultRedirect; } $this->messageManager->addSuccess(__('The account information has been saved.')); - $this->_redirect('customer/account'); - return; + $resultRedirect->setPath('customer/account'); + return $resultRedirect; } - $this->_redirect('*/*/edit'); + $resultRedirect->setPath('*/*/edit'); + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Account/ForgotPassword.php b/app/code/Magento/Customer/Controller/Account/ForgotPassword.php index ee08cc77da67e..09c27efc64402 100644 --- a/app/code/Magento/Customer/Controller/Account/ForgotPassword.php +++ b/app/code/Magento/Customer/Controller/Account/ForgotPassword.php @@ -11,20 +11,17 @@ class ForgotPassword extends \Magento\Customer\Controller\Account /** * Forgot customer password page * - * @return void + * @return \Magento\Framework\View\Result\Page */ public function execute() { - $this->_view->loadLayout(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->getBlock('forgotPassword')->setEmailValue($this->_getSession()->getForgottenEmail()); - $this->_view->getLayout()->getBlock( - 'forgotPassword' - )->setEmailValue( - $this->_getSession()->getForgottenEmail() - ); $this->_getSession()->unsForgottenEmail(); - $this->_view->getLayout()->initMessages(); - $this->_view->renderLayout(); + $resultPage->getLayout()->initMessages(); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php b/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php index 306b8609f1e24..3b82507dc7f45 100644 --- a/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php +++ b/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php @@ -9,6 +9,8 @@ use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Model\AccountManagement; use Magento\Customer\Model\Session; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; use Magento\Framework\Escaper; use Magento\Framework\Exception\NoSuchEntityException; @@ -24,34 +26,40 @@ class ForgotPasswordPost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param AccountManagementInterface $customerAccountManagement * @param Escaper $escaper */ public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, AccountManagementInterface $customerAccountManagement, Escaper $escaper ) { $this->customerAccountManagement = $customerAccountManagement; $this->escaper = $escaper; - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** * Forgot customer password action * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); $email = (string)$this->getRequest()->getPost('email'); if ($email) { if (!\Zend_Validate::is($email, 'EmailAddress')) { $this->_getSession()->setForgottenEmail($email); $this->messageManager->addError(__('Please correct the email address.')); - $this->_redirect('*/*/forgotpassword'); - return; + $resultRedirect->setPath('*/*/forgotpassword'); + return $resultRedirect; } try { @@ -63,8 +71,8 @@ public function execute() // Do nothing, we don't want anyone to use this action to determine which email accounts are registered. } catch (\Exception $exception) { $this->messageManager->addException($exception, __('Unable to send password reset email.')); - $this->_redirect('*/*/forgotpassword'); - return; + $resultRedirect->setPath('*/*/forgotpassword'); + return $resultRedirect; } $email = $this->escaper->escapeHtml($email); // @codingStandardsIgnoreStart @@ -75,12 +83,12 @@ public function execute() ) ); // @codingStandardsIgnoreEnd - $this->_redirect('*/*/'); - return; + $resultRedirect->setPath('*/*/'); + return $resultRedirect; } else { $this->messageManager->addError(__('Please enter your email.')); - $this->_redirect('*/*/forgotpassword'); - return; + $resultRedirect->setPath('*/*/forgotpassword'); + return $resultRedirect; } } } diff --git a/app/code/Magento/Customer/Controller/Account/Index.php b/app/code/Magento/Customer/Controller/Account/Index.php index 8ce90c1c30bda..d90976a4d55e4 100644 --- a/app/code/Magento/Customer/Controller/Account/Index.php +++ b/app/code/Magento/Customer/Controller/Account/Index.php @@ -11,13 +11,14 @@ class Index extends \Magento\Customer\Controller\Account /** * Default customer account page * - * @return void + * @return \Magento\Framework\View\Result\Page */ public function execute() { - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); - $this->_view->getPage()->getConfig()->getTitle()->set(__('My Account')); - $this->_view->renderLayout(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->initMessages(); + $resultPage->getConfig()->getTitle()->set(__('My Account')); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Account/Login.php b/app/code/Magento/Customer/Controller/Account/Login.php index e065455c8da4a..3b6ceee7cd829 100644 --- a/app/code/Magento/Customer/Controller/Account/Login.php +++ b/app/code/Magento/Customer/Controller/Account/Login.php @@ -11,17 +11,21 @@ class Login extends \Magento\Customer\Controller\Account /** * Customer login form page * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page\ */ public function execute() { if ($this->_getSession()->isLoggedIn()) { - $this->_redirect('*/*/'); - return; + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('*/*/'); + return $resultRedirect; } - $this->getResponse()->setHeader('Login-Required', 'true'); - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); - $this->_view->renderLayout(); + + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setHeader('Login-Required', 'true'); + $resultPage->getLayout()->initMessages(); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Account/LoginPost.php b/app/code/Magento/Customer/Controller/Account/LoginPost.php index 0f95ae878731e..b7948e9f95bee 100644 --- a/app/code/Magento/Customer/Controller/Account/LoginPost.php +++ b/app/code/Magento/Customer/Controller/Account/LoginPost.php @@ -8,6 +8,8 @@ use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\AccountManagementInterface; @@ -43,6 +45,8 @@ class LoginPost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param ScopeConfigInterface $scopeConfig * @param StoreManagerInterface $storeManager * @param AccountManagementInterface $customerAccountManagement @@ -55,6 +59,8 @@ class LoginPost extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, AccountManagementInterface $customerAccountManagement, @@ -68,13 +74,13 @@ public function __construct( $this->urlDecoder = $urlDecoder; $this->customerUrl = $customerHelperData; $this->formKeyValidator = $formKeyValidator; - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** * Define target URL and redirect customer after logging in * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function loginPostRedirect() @@ -121,20 +127,25 @@ protected function loginPostRedirect() $this->_getSession()->setBeforeAuthUrl($this->_getSession()->getAfterAuthUrl(true)); } } - $this->getResponse()->setRedirect($this->_getSession()->getBeforeAuthUrl(true)); + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setUrl($this->_getSession()->getBeforeAuthUrl(true)); + return $resultRedirect; } /** * Login post action * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { if ($this->_getSession()->isLoggedIn() || !$this->formKeyValidator->validate($this->getRequest())) { - $this->_redirect('*/*/'); - return; + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('*/*/'); + return $resultRedirect; } if ($this->getRequest()->isPost()) { @@ -168,6 +179,6 @@ public function execute() } } - $this->loginPostRedirect(); + return $this->loginPostRedirect(); } } diff --git a/app/code/Magento/Customer/Controller/Account/Logout.php b/app/code/Magento/Customer/Controller/Account/Logout.php index b37db50a48df7..2d1fa0c0e1188 100644 --- a/app/code/Magento/Customer/Controller/Account/Logout.php +++ b/app/code/Magento/Customer/Controller/Account/Logout.php @@ -11,17 +11,17 @@ class Logout extends \Magento\Customer\Controller\Account /** * Customer logout action * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { $lastCustomerId = $this->_getSession()->getId(); - $this->_getSession()->logout()->setBeforeAuthUrl( - $this->_redirect->getRefererUrl() - )->setLastCustomerId( - $lastCustomerId - ); + $this->_getSession()->logout()->setBeforeAuthUrl($this->_redirect->getRefererUrl()) + ->setLastCustomerId($lastCustomerId); - $this->_redirect('*/*/logoutSuccess'); + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('*/*/logoutSuccess'); + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Account/LogoutSuccess.php b/app/code/Magento/Customer/Controller/Account/LogoutSuccess.php index 6b0bbba2b85d1..447c061cd10a8 100644 --- a/app/code/Magento/Customer/Controller/Account/LogoutSuccess.php +++ b/app/code/Magento/Customer/Controller/Account/LogoutSuccess.php @@ -11,11 +11,10 @@ class LogoutSuccess extends \Magento\Customer\Controller\Account /** * Logout success page * - * @return void + * @return \Magento\Framework\View\Result\Page */ public function execute() { - $this->_view->loadLayout(); - $this->_view->renderLayout(); + return $this->resultPageFactory->create(); } } diff --git a/app/code/Magento/Customer/Controller/Account/ResetPassword.php b/app/code/Magento/Customer/Controller/Account/ResetPassword.php index ecf2644dbf926..32735a80177b4 100644 --- a/app/code/Magento/Customer/Controller/Account/ResetPassword.php +++ b/app/code/Magento/Customer/Controller/Account/ResetPassword.php @@ -6,17 +6,49 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Customer\Model\Session; +use Magento\Framework\App\Action\Context; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\Controller\Result\ForwardFactory; + class ResetPassword extends \Magento\Customer\Controller\Account { + /** + * @var ForwardFactory + */ + protected $resultForwardFactory; + + /** + * @param Context $context + * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory + * @param ForwardFactory $resultForwardFactory + */ + public function __construct( + Context $context, + Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, + ForwardFactory $resultForwardFactory + ) { + $this->resultForwardFactory = $resultForwardFactory; + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + } + /** * Display reset forgotten password form * * User is redirected on this action when he clicks on the corresponding link in password reset confirmation email * - * @return void + * @return \Magento\Framework\Controller\Result\Forward */ public function execute() { - $this->_forward('createPassword'); + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('createPassword'); + return $resultForward; } } diff --git a/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php b/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php index 3e78a691406c0..b8055dc7354e7 100644 --- a/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php +++ b/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php @@ -10,6 +10,8 @@ use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\Context; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\View\Result\PageFactory; class ResetPasswordPost extends \Magento\Customer\Controller\Account { @@ -22,18 +24,22 @@ class ResetPasswordPost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession + * @param RedirectFactory $resultRedirectFactory + * @param PageFactory $resultPageFactory * @param AccountManagementInterface $accountManagement * @param CustomerRepositoryInterface $customerRepository */ public function __construct( Context $context, Session $customerSession, + RedirectFactory $resultRedirectFactory, + PageFactory $resultPageFactory, AccountManagementInterface $accountManagement, CustomerRepositoryInterface $customerRepository ) { $this->accountManagement = $accountManagement; $this->customerRepository = $customerRepository; - parent::__construct($context, $customerSession); + parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); } /** @@ -41,10 +47,12 @@ public function __construct( * * Used to handle data received from reset forgotten password form * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); $resetPasswordToken = (string)$this->getRequest()->getQuery('token'); $customerId = (int)$this->getRequest()->getQuery('id'); $password = (string)$this->getRequest()->getPost('password'); @@ -52,24 +60,25 @@ public function execute() if ($password !== $passwordConfirmation) { $this->messageManager->addError(__("New Password and Confirm New Password values didn't match.")); - return; + $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]); + return $resultRedirect; } if (iconv_strlen($password) <= 0) { $this->messageManager->addError(__('New password field cannot be empty.')); - $this->_redirect('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]); - return; + $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]); + return $resultRedirect; } try { $customerEmail = $this->customerRepository->getById($customerId)->getEmail(); $this->accountManagement->resetPassword($customerEmail, $resetPasswordToken, $password); $this->messageManager->addSuccess(__('Your password has been updated.')); - $this->_redirect('*/*/login'); - return; + $resultRedirect->setPath('*/*/login'); + return $resultRedirect; } catch (\Exception $exception) { $this->messageManager->addError(__('There was an error saving the new password.')); - $this->_redirect('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]); - return; + $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]); + return $resultRedirect; } } } diff --git a/app/code/Magento/Customer/Controller/Address.php b/app/code/Magento/Customer/Controller/Address.php index 9c8061000abed..edea47dcc253a 100644 --- a/app/code/Magento/Customer/Controller/Address.php +++ b/app/code/Magento/Customer/Controller/Address.php @@ -49,6 +49,21 @@ class Address extends \Magento\Framework\App\Action\Action */ protected $_dataProcessor; + /** + * @var \Magento\Framework\Controller\Result\Redirect + */ + protected $resultRedirectFactory; + + /** + * @var \Magento\Framework\Controller\Result\ForwardFactory + */ + protected $resultForwardFactory; + + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $resultPageFactory; + /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Customer\Model\Session $customerSession @@ -58,6 +73,9 @@ class Address extends \Magento\Framework\App\Action\Action * @param \Magento\Customer\Api\Data\AddressDataBuilder $addressDataBuilder * @param \Magento\Customer\Api\Data\RegionDataBuilder $regionDataBuilder * @param \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor + * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory + * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -68,7 +86,10 @@ public function __construct( \Magento\Customer\Api\AddressRepositoryInterface $addressRepository, \Magento\Customer\Api\Data\AddressDataBuilder $addressDataBuilder, \Magento\Customer\Api\Data\RegionDataBuilder $regionDataBuilder, - \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor + \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor, + \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, + \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, + \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { $this->_customerSession = $customerSession; $this->_formKeyValidator = $formKeyValidator; @@ -77,6 +98,9 @@ public function __construct( $this->_addressDataBuilder = $addressDataBuilder; $this->_regionDataBuilder = $regionDataBuilder; $this->_dataProcessor = $dataProcessor; + $this->resultRedirectFactory = $resultRedirectFactory; + $this->resultForwardFactory = $resultForwardFactory; + $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } diff --git a/app/code/Magento/Customer/Controller/Address/Delete.php b/app/code/Magento/Customer/Controller/Address/Delete.php index 6c00862dc7fb7..6c3344487794c 100644 --- a/app/code/Magento/Customer/Controller/Address/Delete.php +++ b/app/code/Magento/Customer/Controller/Address/Delete.php @@ -9,7 +9,7 @@ class Delete extends \Magento\Customer\Controller\Address { /** - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { @@ -28,6 +28,6 @@ public function execute() $this->messageManager->addException($other, __('An error occurred while deleting the address.')); } } - $this->getResponse()->setRedirect($this->_buildUrl('*/*/index')); + return $this->resultRedirectFactory->create()->setPath('*/*/index'); } } diff --git a/app/code/Magento/Customer/Controller/Address/Edit.php b/app/code/Magento/Customer/Controller/Address/Edit.php index feb45b2b19673..0691ffd8ad527 100644 --- a/app/code/Magento/Customer/Controller/Address/Edit.php +++ b/app/code/Magento/Customer/Controller/Address/Edit.php @@ -9,10 +9,14 @@ class Edit extends \Magento\Customer\Controller\Address { /** - * @return void + * Customer address edit action + * + * @return \Magento\Framework\Controller\Result\Forward */ public function execute() { - $this->_forward('form'); + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('form'); } } diff --git a/app/code/Magento/Customer/Controller/Address/Form.php b/app/code/Magento/Customer/Controller/Address/Form.php index f0ae5b1a4348e..8948125c397a6 100644 --- a/app/code/Magento/Customer/Controller/Address/Form.php +++ b/app/code/Magento/Customer/Controller/Address/Form.php @@ -11,16 +11,17 @@ class Form extends \Magento\Customer\Controller\Address /** * Address book form * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); - $navigationBlock = $this->_view->getLayout()->getBlock('customer_account_navigation'); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->initMessages(); + $navigationBlock = $resultPage->getLayout()->getBlock('customer_account_navigation'); if ($navigationBlock) { $navigationBlock->setActive('customer/address'); } - $this->_view->renderLayout(); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Address/FormPost.php b/app/code/Magento/Customer/Controller/Address/FormPost.php index db742e6de340f..2fdf486d56d5c 100644 --- a/app/code/Magento/Customer/Controller/Address/FormPost.php +++ b/app/code/Magento/Customer/Controller/Address/FormPost.php @@ -64,19 +64,19 @@ protected function _extractAddress() /** * Process address form save * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { if (!$this->_formKeyValidator->validate($this->getRequest())) { - $this->_redirect('*/*/'); - return; + return $this->resultRedirectFactory->create()->setPath('*/*/'); } if (!$this->getRequest()->isPost()) { $this->_getSession()->setAddressFormData($this->getRequest()->getPost()); - $this->getResponse()->setRedirect($this->_redirect->error($this->_buildUrl('*/*/edit'))); - return; + return $this->resultRedirectFactory->create()->setUrl( + $this->_redirect->error($this->_buildUrl('*/*/edit')) + ); } try { @@ -84,8 +84,7 @@ public function execute() $this->_addressRepository->save($address); $this->messageManager->addSuccess(__('The address has been saved.')); $url = $this->_buildUrl('*/*/index', ['_secure' => true]); - $this->getResponse()->setRedirect($this->_redirect->success($url)); - return; + return $this->resultRedirectFactory->create()->setUrl($this->_redirect->success($url)); } catch (InputException $e) { $this->messageManager->addError($e->getMessage()); foreach ($e->getErrors() as $error) { @@ -97,6 +96,6 @@ public function execute() $this->_getSession()->setAddressFormData($this->getRequest()->getPost()); $url = $this->_buildUrl('*/*/edit', ['id' => $this->getRequest()->getParam('id')]); - $this->getResponse()->setRedirect($this->_redirect->error($url)); + return $this->resultRedirectFactory->create()->setUrl($this->_redirect->error($url)); } } diff --git a/app/code/Magento/Customer/Controller/Address/Index.php b/app/code/Magento/Customer/Controller/Address/Index.php index 61cd8538040fe..de8e53def1789 100644 --- a/app/code/Magento/Customer/Controller/Address/Index.php +++ b/app/code/Magento/Customer/Controller/Address/Index.php @@ -8,6 +8,9 @@ use Magento\Customer\Api\CustomerRepositoryInterface; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class Index extends \Magento\Customer\Controller\Address { /** @@ -25,6 +28,9 @@ class Index extends \Magento\Customer\Controller\Address * @param \Magento\Customer\Api\Data\RegionDataBuilder $regionDataBuilder * @param \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor * @param CustomerRepositoryInterface $customerRepository + * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory + * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -36,6 +42,9 @@ public function __construct( \Magento\Customer\Api\Data\AddressDataBuilder $addressDataBuilder, \Magento\Customer\Api\Data\RegionDataBuilder $regionDataBuilder, \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor, + \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, + \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, + \Magento\Framework\View\Result\PageFactory $resultPageFactory, CustomerRepositoryInterface $customerRepository ) { $this->customerRepository = $customerRepository; @@ -47,29 +56,32 @@ public function __construct( $addressRepository, $addressDataBuilder, $regionDataBuilder, - $dataProcessor + $dataProcessor, + $resultRedirectFactory, + $resultForwardFactory, + $resultPageFactory ); } /** * Customer addresses list * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $addresses = $this->customerRepository->getById($this->_getSession()->getCustomerId())->getAddresses(); if (count($addresses)) { - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); - - $block = $this->_view->getLayout()->getBlock('address_book'); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->initMessages(); + $block = $resultPage->getLayout()->getBlock('address_book'); if ($block) { $block->setRefererUrl($this->_redirect->getRefererUrl()); } - $this->_view->renderLayout(); + return $resultPage; } else { - $this->getResponse()->setRedirect($this->_buildUrl('*/*/new')); + return $this->resultRedirectFactory->create()->setPath('*/*/new'); } } } diff --git a/app/code/Magento/Customer/Controller/Address/NewAction.php b/app/code/Magento/Customer/Controller/Address/NewAction.php index 158c5aa8ffbd8..4bfdabbbd5ef1 100644 --- a/app/code/Magento/Customer/Controller/Address/NewAction.php +++ b/app/code/Magento/Customer/Controller/Address/NewAction.php @@ -9,10 +9,12 @@ class NewAction extends \Magento\Customer\Controller\Address { /** - * @return void + * @return \Magento\Framework\Controller\Result\Forward */ public function execute() { - $this->_forward('form'); + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('form'); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Configure.php b/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Configure.php index ce0e635dba964..dbc2461c17013 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Configure.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Configure.php @@ -11,7 +11,7 @@ class Configure extends \Magento\Customer\Controller\Adminhtml\Cart\Product\Comp /** * Ajax handler to response configuration fieldset of composite product in customer's cart * - * @return void + * @return \Magento\Framework\View\Result\Layout */ public function execute() { @@ -38,10 +38,7 @@ public function execute() $configureResult->setMessage($e->getMessage()); } - $this->_objectManager->get( - 'Magento\Catalog\Helper\Product\Composite' - )->renderConfigureResult( - $configureResult - ); + return $this->_objectManager->get('Magento\Catalog\Helper\Product\Composite') + ->renderConfigureResult($configureResult); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Update.php b/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Update.php index 17f8da4b5ff5e..099e121b9de5d 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Update.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Update.php @@ -8,10 +8,29 @@ class Update extends \Magento\Customer\Controller\Adminhtml\Cart\Product\Composite\Cart { + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Quote\Model\QuoteRepository $quoteRepository + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Quote\Model\QuoteRepository $quoteRepository, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + ) { + parent::__construct($context, $quoteRepository); + $this->resultRedirectFactory = $resultRedirectFactory; + } + /** * IFrame handler for submitted configuration for quote item * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { @@ -32,6 +51,6 @@ public function execute() $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); $this->_objectManager->get('Magento\Backend\Model\Session')->setCompositeProductResult($updateResult); - $this->_redirect('catalog/product/showUpdateResult'); + return $this->resultRedirectFactory->create()->setPath('catalog/product/showUpdateResult'); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php b/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php index de0d676fc3090..f0eb7f4708124 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php @@ -15,25 +15,26 @@ class InvalidateToken extends \Magento\Customer\Controller\Adminhtml\Index /** * Reset customer's tokens handler * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { + $resultRedirect = $this->resultRedirectFactory->create(); if ($customerId = $this->getRequest()->getParam('customer_id')) { try { /** @var \Magento\Integration\Service\V1\CustomerTokenService $tokenService */ $tokenService = $this->_objectManager->get('Magento\Integration\Service\V1\CustomerTokenService'); $tokenService->revokeCustomerAccessToken($customerId); $this->messageManager->addSuccess(__('You have revoked the customer\'s tokens.')); - $this->_redirect('customer/index/edit', ['id' => $customerId, '_current' => true]); - return; + $resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); - $this->_redirect('customer/index/edit', ['id' => $customerId, '_current' => true]); - return; + $resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]); } + } else { + $this->messageManager->addError(__('We can\'t find a customer to revoke.')); + $resultRedirect->setPath('customer/index/index'); } - $this->messageManager->addError(__('We can\'t find a customer to revoke.')); - $this->_redirect('customer/index/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group.php b/app/code/Magento/Customer/Controller/Adminhtml/Group.php index b2466e88d2a4a..2bce1f64866b5 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group.php @@ -30,6 +30,21 @@ class Group extends \Magento\Backend\App\Action */ protected $groupDataBuilder; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory + */ + protected $resultForwardFactory; + + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $resultPageFactory; + /** * Initialize Group Controller * @@ -37,17 +52,26 @@ class Group extends \Magento\Backend\App\Action * @param \Magento\Framework\Registry $coreRegistry * @param GroupRepositoryInterface $groupRepository * @param GroupDataBuilder $groupDataBuilder + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, GroupRepositoryInterface $groupRepository, - GroupDataBuilder $groupDataBuilder + GroupDataBuilder $groupDataBuilder, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { $this->_coreRegistry = $coreRegistry; $this->groupRepository = $groupRepository; $this->groupDataBuilder = $groupDataBuilder; parent::__construct($context); + $this->resultRedirectFactory = $resultRedirectFactory; + $this->resultForwardFactory = $resultForwardFactory; + $this->resultPageFactory = $resultPageFactory; } /** diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php index 37189e6c0277d..60cbfe172b0e6 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php @@ -13,27 +13,25 @@ class Delete extends \Magento\Customer\Controller\Adminhtml\Group /** * Delete customer group. * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $id = $this->getRequest()->getParam('id'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if ($id) { try { $this->groupRepository->deleteById($id); $this->messageManager->addSuccess(__('The customer group has been deleted.')); - $this->getResponse()->setRedirect($this->getUrl('customer/group')); - return; } catch (NoSuchEntityException $e) { $this->messageManager->addError(__('The customer group no longer exists.')); - $this->getResponse()->setRedirect($this->getUrl('customer/*/')); - return; + return $resultRedirect->setPath('customer/*/'); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); - $this->getResponse()->setRedirect($this->getUrl('customer/group/edit', ['id' => $id])); - return; + return $resultRedirect->setPath('customer/group/edit', ['id' => $id]); } } - $this->_redirect('customer/group'); + return $resultRedirect->setPath('customer/group'); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Edit.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Edit.php index 34731bda7e84e..303d2f4f1afff 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Edit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Edit.php @@ -11,10 +11,10 @@ class Edit extends \Magento\Customer\Controller\Adminhtml\Group /** * Edit customer group action. Forward to new action. * - * @return void + * @return \Magento\Backend\Model\View\Result\Forward */ public function execute() { - $this->_forward('new'); + return $this->resultForwardFactory->create()->forward('new'); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Index.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Index.php index 733a2ea1349f2..290e77238ff11 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Index.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Index.php @@ -11,15 +11,16 @@ class Index extends \Magento\Customer\Controller\Adminhtml\Group /** * Customer groups list. * - * @return void + * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Customer::customer_group'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Customer Groups')); - $this->_addBreadcrumb(__('Customers'), __('Customers')); - $this->_addBreadcrumb(__('Customer Groups'), __('Customer Groups')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Customer::customer_group'); + $resultPage->getConfig()->getTitle()->prepend(__('Customer Groups')); + $resultPage->addBreadcrumb(__('Customers'), __('Customers')); + $resultPage->addBreadcrumb(__('Customer Groups'), __('Customer Groups')); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/NewAction.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/NewAction.php index 6768a6f9a603d..e6a03ff92e455 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/NewAction.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/NewAction.php @@ -26,36 +26,32 @@ protected function _initGroup() /** * Edit or create customer group. * - * @return void + * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { $groupId = $this->_initGroup(); - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Customer::customer_group'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Customer Groups')); - $this->_addBreadcrumb(__('Customers'), __('Customers')); - $this->_addBreadcrumb(__('Customer Groups'), __('Customer Groups'), $this->getUrl('customer/group')); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Customer::customer_group'); + $resultPage->getConfig()->getTitle()->prepend(__('Customer Groups')); + $resultPage->addBreadcrumb(__('Customers'), __('Customers')); + $resultPage->addBreadcrumb(__('Customer Groups'), __('Customer Groups'), $this->getUrl('customer/group')); if (is_null($groupId)) { - $this->_addBreadcrumb(__('New Group'), __('New Customer Groups')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('New Customer Group')); + $resultPage->addBreadcrumb(__('New Group'), __('New Customer Groups')); + $resultPage->getConfig()->getTitle()->prepend(__('New Customer Group')); } else { - $this->_addBreadcrumb(__('Edit Group'), __('Edit Customer Groups')); - $this->_view->getPage()->getConfig()->getTitle()->prepend( + $resultPage->addBreadcrumb(__('Edit Group'), __('Edit Customer Groups')); + $resultPage->getConfig()->getTitle()->prepend( $this->groupRepository->getById($groupId)->getCode() ); } - $this->_view->getLayout()->addBlock( - 'Magento\Customer\Block\Adminhtml\Group\Edit', - 'group', - 'content' - )->setEditMode( - (bool)$groupId - ); + $resultPage->getLayout()->addBlock('Magento\Customer\Block\Adminhtml\Group\Edit', 'group', 'content') + ->setEditMode((bool)$groupId); - $this->_view->renderLayout(); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php index 65a62c888ce02..3017f3f0acf33 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php @@ -23,6 +23,9 @@ class Save extends \Magento\Customer\Controller\Adminhtml\Group * @param \Magento\Framework\Registry $coreRegistry * @param GroupRepositoryInterface $groupRepository * @param GroupDataBuilder $groupDataBuilder + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @param \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor */ public function __construct( @@ -30,10 +33,21 @@ public function __construct( \Magento\Framework\Registry $coreRegistry, GroupRepositoryInterface $groupRepository, GroupDataBuilder $groupDataBuilder, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor ) { $this->dataObjectProcessor = $dataObjectProcessor; - parent::__construct($context, $coreRegistry, $groupRepository, $groupDataBuilder); + parent::__construct( + $context, + $coreRegistry, + $groupRepository, + $groupDataBuilder, + $resultRedirectFactory, + $resultForwardFactory, + $resultPageFactory + ); } /** @@ -54,7 +68,7 @@ protected function storeCustomerGroupDataToSession($customerGroupData) /** * Create or save customer group. * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward */ public function execute() { @@ -64,6 +78,7 @@ public function execute() $customerGroup = null; if ($taxClass) { $id = $this->getRequest()->getParam('id'); + $resultRedirect = $this->resultRedirectFactory->create(); try { if (!is_null($id)) { $this->groupDataBuilder->populate($this->groupRepository->getById((int)$id)); @@ -79,8 +94,7 @@ public function execute() $this->groupRepository->save($customerGroup); $this->messageManager->addSuccess(__('The customer group has been saved.')); - $this->getResponse()->setRedirect($this->getUrl('customer/group')); - return; + $resultRedirect->setPath('customer/group'); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); if ($customerGroup != null) { @@ -91,11 +105,11 @@ public function execute() ) ); } - $this->getResponse()->setRedirect($this->getUrl('customer/group/edit', ['id' => $id])); - return; + $resultRedirect->setPath('customer/group/edit', ['id' => $id]); } + return $resultRedirect; } else { - $this->_forward('new'); + return $this->resultForwardFactory->create()->forward('new'); } } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index.php b/app/code/Magento/Customer/Controller/Adminhtml/Index.php index 8423bfdc412ce..b91163b110e92 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index.php @@ -112,6 +112,36 @@ class Index extends \Magento\Backend\App\Action */ protected $dataObjectProcessor; + /** + * @var \Magento\Framework\View\LayoutFactory + */ + protected $layoutFactory; + + /** + * @var \Magento\Framework\View\Result\LayoutFactory + */ + protected $resultLayoutFactory; + + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $resultPageFactory; + + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory + */ + protected $resultForwardFactory; + + /** + * @var \Magento\Framework\Controller\Result\JSONFactory + */ + protected $resultJsonFactory; + /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry @@ -132,6 +162,12 @@ class Index extends \Magento\Backend\App\Action * @param \Magento\Customer\Model\Customer\Mapper $customerMapper * @param \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor * @param ObjectFactory $objectFactory + * @param \Magento\Framework\View\LayoutFactory $layoutFactory + * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -154,7 +190,13 @@ public function __construct( AddressDataBuilder $addressDataBuilder, \Magento\Customer\Model\Customer\Mapper $customerMapper, \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor, - ObjectFactory $objectFactory + ObjectFactory $objectFactory, + \Magento\Framework\View\LayoutFactory $layoutFactory, + \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, + \Magento\Framework\View\Result\PageFactory $resultPageFactory, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory ) { $this->_coreRegistry = $coreRegistry; $this->_fileFactory = $fileFactory; @@ -174,6 +216,12 @@ public function __construct( $this->customerMapper = $customerMapper; $this->dataObjectProcessor = $dataObjectProcessor; $this->_objectFactory = $objectFactory; + $this->layoutFactory = $layoutFactory; + $this->resultLayoutFactory = $resultLayoutFactory; + $this->resultPageFactory = $resultPageFactory; + $this->resultRedirectFactory = $resultRedirectFactory; + $this->resultForwardFactory = $resultForwardFactory; + $this->resultJsonFactory = $resultJsonFactory; parent::__construct($context); } @@ -200,11 +248,12 @@ protected function _initCustomer($idFieldName = 'id') /** * Prepare customer default title * + * @param \Magento\Backend\Model\View\Result\Page $resultPage * @return void */ - protected function prepareDefaultCustomerTitle() + protected function prepareDefaultCustomerTitle(\Magento\Backend\Model\View\Result\Page $resultPage) { - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Customers')); + $resultPage->getConfig()->getTitle()->prepend(__('Customers')); } /** diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Cart.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Cart.php index b3290cf642e09..3050408cda037 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Cart.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Cart.php @@ -1,6 +1,5 @@ _view->loadLayout(); - $this->prepareDefaultCustomerTitle(); - $this->_view->getLayout()->getBlock('admin.customer.view.edit.cart')->setWebsiteId($websiteId); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + $resultLayout->getLayout()->getBlock('admin.customer.view.edit.cart')->setWebsiteId($websiteId); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Carts.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Carts.php index e6db441e65f86..37cb09d45a64a 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Carts.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Carts.php @@ -1,6 +1,5 @@ _initCustomer(); - $this->_view->loadLayout(); - $this->prepareDefaultCustomerTitle(); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php index 572aece265c34..d6d46cb468d66 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php @@ -1,6 +1,5 @@ messageManager->addError($exception->getMessage()); } } - $this->_redirect('customer/index'); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('customer/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php index a2b4fb1717ce6..5df2f25292602 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php @@ -1,6 +1,5 @@ messageManager->addException($e, __('An error occurred while editing the customer.')); - $this->_redirect('customer/*/index'); - return; + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('customer/*/index'); + return $resultRedirect; } } $customerData['customer_id'] = $customerId; @@ -116,20 +116,15 @@ public function execute() $this->_getSession()->setCustomerData($customerData); - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Customer::customer_manage'); - $this->prepareDefaultCustomerTitle(); - - $this->_setActiveMenu('Magento_Customer::customer'); + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Customer::customer_manage'); + $this->prepareDefaultCustomerTitle($resultPage); + $resultPage->setActiveMenu('Magento_Customer::customer'); if ($isExistingCustomer) { - $this->_view->getPage()->getConfig()->getTitle()->prepend($this->_viewHelper->getCustomerName($customer)); + $resultPage->getConfig()->getTitle()->prepend($this->_viewHelper->getCustomerName($customer)); } else { - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('New Customer')); + $resultPage->getConfig()->getTitle()->prepend(__('New Customer')); } - /** - * Set active menu item - */ - - $this->_view->renderLayout(); + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Grid.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Grid.php index 71dcb70b950d8..e5839fccd0e92 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Grid.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Grid.php @@ -1,6 +1,5 @@ _view->loadLayout(false); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Index.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Index.php index 26adfdb442057..b238a8287e70f 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Index.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Index.php @@ -1,6 +1,5 @@ getRequest()->getQuery('ajax')) { - $this->_forward('grid'); - return; + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('grid'); + return $resultForward; } - $this->_view->loadLayout(); - + $resultPage = $this->resultPageFactory->create(); /** * Set active menu item */ - $this->_setActiveMenu('Magento_Customer::customer_manage'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Customers')); + $resultPage->setActiveMenu('Magento_Customer::customer_manage'); + $resultPage->getConfig()->getTitle()->prepend(__('Customers')); /** * Add breadcrumb item */ - $this->_addBreadcrumb(__('Customers'), __('Customers')); - $this->_addBreadcrumb(__('Manage Customers'), __('Manage Customers')); + $resultPage->addBreadcrumb(__('Customers'), __('Customers')); + $resultPage->addBreadcrumb(__('Manage Customers'), __('Manage Customers')); - $this->_view->renderLayout(); $this->_getSession()->unsCustomerData(); + + return $resultPage; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/LastOrders.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/LastOrders.php index 09fd26723f311..eb9e594860d22 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/LastOrders.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/LastOrders.php @@ -1,6 +1,5 @@ _initCustomer(); - $this->_view->loadLayout(); - $this->prepareDefaultCustomerTitle(); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php index 7710417f5263e..0be3ef717be17 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php @@ -1,6 +1,5 @@ messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); } - $this->_redirect('customer/*/index'); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('customer/*/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php index 8547c57873b9e..0f5a813facadd 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php @@ -1,6 +1,5 @@ messageManager->addSuccess(__('A total of %1 record(s) were deleted.', $customersDeleted)); } - $this->_redirect('customer/*/index'); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('customer/*/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php index 4ba559a8d02c2..55d165504c551 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php @@ -1,6 +1,5 @@ messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); } - $this->_redirect('customer/*/index'); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('customer/*/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php index 498d89cc66766..abfc94844b33d 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php @@ -1,6 +1,5 @@ messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); } - $this->_redirect('customer/*/index'); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('customer/*/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/NewAction.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/NewAction.php index 08c150c491f13..d3bdd1eadfd8e 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/NewAction.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/NewAction.php @@ -1,6 +1,5 @@ _forward('edit'); + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('edit'); + return $resultForward; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Newsletter.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Newsletter.php index 05d7f186a396e..cd0db70daa4b2 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Newsletter.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Newsletter.php @@ -1,6 +1,5 @@ loadByCustomerId($customerId); $this->_coreRegistry->register('subscriber', $subscriber); - $this->_view->loadLayout(); - $this->prepareDefaultCustomerTitle(); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Orders.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Orders.php index 0088a069fdbb2..649c0c649ec8a 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Orders.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Orders.php @@ -1,6 +1,5 @@ _initCustomer(); - $this->_view->loadLayout(); - $this->prepareDefaultCustomerTitle(); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/ProductReviews.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/ProductReviews.php index 940513e5092e2..b6a2e0072a064 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/ProductReviews.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/ProductReviews.php @@ -1,6 +1,5 @@ _initCustomer(); - $this->_view->loadLayout(); - $this->prepareDefaultCustomerTitle(); - $this->_view->getLayout()->getBlock('admin.customer.reviews')->setCustomerId( - $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID) - ) + $resultLayout = $this->resultLayoutFactory->create(); + $block = $resultLayout->getLayout()->getBlock('admin.customer.reviews'); + $block->setCustomerId($this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID)) ->setUseAjax(true); - $this->_view->renderLayout(); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php index 0dc6b4a8fb789..296032afbee6a 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php @@ -1,6 +1,5 @@ resultRedirectFactory->create(); $customerId = (int)$this->getRequest()->getParam('customer_id', 0); if (!$customerId) { - return $this->_redirect('customer/index'); + $resultRedirect->setPath('customer/index'); + return $resultRedirect; } try { @@ -31,7 +32,8 @@ public function execute() ); $this->messageManager->addSuccess(__('Customer will receive an email with a link to reset password.')); } catch (NoSuchEntityException $exception) { - return $this->_redirect('customer/index'); + $resultRedirect->setPath('customer/index'); + return $resultRedirect; } catch (\Magento\Framework\Model\Exception $exception) { $messages = $exception->getMessages(\Magento\Framework\Message\MessageInterface::TYPE_ERROR); if (!count($messages)) { @@ -44,7 +46,10 @@ public function execute() __('An error occurred while resetting customer password.') ); } - - $this->_redirect('customer/*/edit', ['id' => $customerId, '_current' => true]); + $resultRedirect->setPath( + 'customer/*/edit', + ['id' => $customerId, '_current' => true] + ); + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php index 558c60781c860..34635d0940667 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php @@ -1,6 +1,5 @@ resultRedirectFactory->create(); if ($returnToEdit) { if ($customerId) { - $this->_redirect('customer/*/edit', ['id' => $customerId, '_current' => true]); + $resultRedirect->setPath( + 'customer/*/edit', + ['id' => $customerId, '_current' => true] + ); } else { - $this->_redirect('customer/*/new', ['_current' => true]); + $resultRedirect->setPath( + 'customer/*/new', + ['_current' => true] + ); } } else { - $this->_redirect('customer/index'); + $resultRedirect->setPath('customer/index'); } + return $resultRedirect; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php index de2ad486e6b3d..74e7ef270f2f9 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php @@ -1,6 +1,5 @@ _validateCustomerAddress($response); } - + $resultJson = $this->resultJsonFactory->create(); if ($response->getError()) { - $this->_view->getLayout()->initMessages(); - $response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml()); + $layout = $this->layoutFactory->create(); + $layout->initMessages(); + $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml()); } - $this->getResponse()->representJson($response->toJson()); + $resultJson->setData($response); + return $resultJson; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/ViewCart.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/ViewCart.php index 7ea501df11fca..9dc52176624af 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/ViewCart.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/ViewCart.php @@ -1,6 +1,5 @@ _initCustomer(); - $this->_view->loadLayout(); - $this->prepareDefaultCustomerTitle(); - $this->_view->getLayout()->getBlock('admin.customer.view.cart')->setWebsiteId( + $resultLayout = $this->resultLayoutFactory->create(); + $resultLayout->getLayout()->getBlock('admin.customer.view.cart')->setWebsiteId( (int)$this->getRequest()->getParam('website_id') ); - $this->_view->renderLayout(); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/ViewWishlist.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/ViewWishlist.php index fa2c9232fcfb0..b4ba61be29f66 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/ViewWishlist.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/ViewWishlist.php @@ -1,6 +1,5 @@ _initCustomer(); - $this->_view->loadLayout(); - $this->prepareDefaultCustomerTitle(); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php index b3c3e4688de55..0c4ff34bbd453 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php @@ -1,6 +1,5 @@ urlDecoder = $urlDecoder; } @@ -157,11 +174,7 @@ public function execute() $this->getResponse() ->setHttpResponseCode(200) ->setHeader('Pragma', 'public', true) - ->setHeader( - 'Content-type', - $contentType, - true - ) + ->setHeader('Content-type', $contentType, true) ->setHeader('Content-Length', $contentLength) ->setHeader('Last-Modified', date('r', $contentModify)) ->clearBody(); @@ -170,13 +183,9 @@ public function execute() echo $directory->readFile($fileName); } else { $name = pathinfo($path, PATHINFO_BASENAME); - $this->_fileFactory->create( - $name, - ['type' => 'filename', 'value' => $fileName], - DirectoryList::MEDIA - )->sendResponse(); + $this->_fileFactory->create($name, ['type' => 'filename', 'value' => $fileName], DirectoryList::MEDIA) + ->sendResponse(); } - exit; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Wishlist.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Wishlist.php index 366ae3a342a53..ee767b848796a 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Wishlist.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Wishlist.php @@ -1,6 +1,5 @@ _view->getLayout()->getUpdate()->addHandle(strtolower($this->_request->getFullActionName())); - $this->_view->loadLayoutUpdates(); - $this->prepareDefaultCustomerTitle(); - $this->_view->generateLayoutXml(); - $this->_view->generateLayoutBlocks(); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat.php b/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat.php index 0ad76cbb3f8a9..6f7e6b7da097d 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat.php @@ -19,11 +19,10 @@ class Validatevat extends \Magento\Backend\App\Action */ protected function _validate() { - return $this->_objectManager->get( - 'Magento\Customer\Model\Vat' - )->checkVatNumber( - $this->getRequest()->getParam('country'), - $this->getRequest()->getParam('vat') - ); + return $this->_objectManager->get('Magento\Customer\Model\Vat') + ->checkVatNumber( + $this->getRequest()->getParam('country'), + $this->getRequest()->getParam('vat') + ); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat/Validate.php b/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat/Validate.php index 4f2a85966967c..b20ff74c9039f 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat/Validate.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat/Validate.php @@ -8,14 +8,33 @@ class Validate extends \Magento\Customer\Controller\Adminhtml\System\Config\Validatevat { + /** + * @var \Magento\Framework\Controller\Result\RawFactory + */ + protected $resultRawFactory; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Controller\Result\RawFactory $resultRawFactory + ) { + parent::__construct($context); + $this->resultRawFactory = $resultRawFactory; + } + /** * Check whether vat is valid * - * @return void + * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $result = $this->_validate(); - $this->getResponse()->setBody((int)$result->getIsValid()); + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultRawFactory->create(); + return $resultRaw->setContents((int)$result->getIsValid()); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat/ValidateAdvanced.php b/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat/ValidateAdvanced.php index f6a70f8c7b06e..c267c46b590ef 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat/ValidateAdvanced.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/System/Config/Validatevat/ValidateAdvanced.php @@ -8,16 +8,30 @@ class ValidateAdvanced extends \Magento\Customer\Controller\Adminhtml\System\Config\Validatevat { + /** + * @var \Magento\Framework\Controller\Result\JSONFactory + */ + protected $resultJsonFactory; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory + ) { + parent::__construct($context); + $this->resultJsonFactory = $resultJsonFactory; + } + /** * Retrieve validation result as JSON * - * @return void + * @return \Magento\Framework\Controller\Result\JSON */ public function execute() { - /** @var $coreHelper \Magento\Core\Helper\Data */ - $coreHelper = $this->_objectManager->get('Magento\Core\Helper\Data'); - $result = $this->_validate(); $valid = $result->getIsValid(); $success = $result->getRequestSuccess(); @@ -28,15 +42,15 @@ public function execute() $storeId = (int)$storeId; } - $groupId = $this->_objectManager->get( - 'Magento\Customer\Model\Vat' - )->getCustomerGroupIdBasedOnVatNumber( - $this->getRequest()->getParam('country'), - $result, - $storeId - ); + $groupId = $this->_objectManager->get('Magento\Customer\Model\Vat') + ->getCustomerGroupIdBasedOnVatNumber( + $this->getRequest()->getParam('country'), + $result, + $storeId + ); - $body = $coreHelper->jsonEncode(['valid' => $valid, 'group' => $groupId, 'success' => $success]); - $this->getResponse()->representJson($body); + /** @var \Magento\Framework\Controller\Result\JSON $resultJson */ + $resultJson = $this->resultJsonFactory->create(); + return $resultJson->setData(['valid' => $valid, 'group' => $groupId, 'success' => $success]); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist.php b/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist.php index a8c54cb4459d8..b722ed2f2c5fc 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist.php @@ -46,11 +46,8 @@ protected function _initData() throw new CoreException(__('Please load the wish list item.')); } - $this->_wishlist = $this->_objectManager->create( - 'Magento\Wishlist\Model\Wishlist' - )->load( - $wishlistItem->getWishlistId() - ); + $this->_wishlist = $this->_objectManager->create('Magento\Wishlist\Model\Wishlist') + ->load($wishlistItem->getWishlistId()); $this->_wishlistItem = $wishlistItem; diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Configure.php b/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Configure.php index 4913c4ee82e3d..6b3997dcdeaa2 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Configure.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Configure.php @@ -13,7 +13,7 @@ class Configure extends \Magento\Customer\Controller\Adminhtml\Wishlist\Product\ /** * Ajax handler to response configuration fieldset of composite product in customer's wishlist. * - * @return void + * @return \Magento\Framework\View\Result\Layout */ public function execute() { @@ -32,10 +32,7 @@ public function execute() $configureResult->setMessage($e->getMessage()); } - $this->_objectManager->get( - 'Magento\Catalog\Helper\Product\Composite' - )->renderConfigureResult( - $configureResult - ); + return $this->_objectManager->get('Magento\Catalog\Helper\Product\Composite') + ->renderConfigureResult($configureResult); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Update.php b/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Update.php index d0f049cace153..4a9028ee2968d 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Update.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Update.php @@ -10,10 +10,27 @@ class Update extends \Magento\Customer\Controller\Adminhtml\Wishlist\Product\Composite\Wishlist { + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + ) { + parent::__construct($context); + $this->resultRedirectFactory = $resultRedirectFactory; + } + /** * IFrame handler for submitted configuration for wishlist item. * - * @return false + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { @@ -33,8 +50,6 @@ public function execute() } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); $this->_objectManager->get('Magento\Backend\Model\Session')->setCompositeProductResult($updateResult); - $this->_redirect('catalog/product/showUpdateResult'); - - return false; + return $this->resultRedirectFactory->create()->setPath('catalog/product/showUpdateResult'); } } diff --git a/app/code/Magento/Customer/Controller/Ajax/Login.php b/app/code/Magento/Customer/Controller/Ajax/Login.php index 8541d95c67d9b..52272d69832af 100644 --- a/app/code/Magento/Customer/Controller/Ajax/Login.php +++ b/app/code/Magento/Customer/Controller/Ajax/Login.php @@ -33,6 +33,16 @@ class Login extends \Magento\Framework\App\Action\Action */ protected $helper; + /** + * @var \Magento\Framework\Controller\Result\JSONFactory + */ + protected $resultJsonFactory; + + /** + * @var \Magento\Framework\Controller\Result\RawFactory + */ + protected $resultRawFactory; + /** * Initialize Login controller * @@ -40,17 +50,23 @@ class Login extends \Magento\Framework\App\Action\Action * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Core\Helper\Data $helper * @param AccountManagementInterface $customerAccountManagement + * @param \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory + * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Core\Helper\Data $helper, - AccountManagementInterface $customerAccountManagement + AccountManagementInterface $customerAccountManagement, + \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory, + \Magento\Framework\Controller\Result\RawFactory $resultRawFactory ) { parent::__construct($context); $this->customerSession = $customerSession; $this->helper = $helper; $this->customerAccountManagement = $customerAccountManagement; + $this->resultJsonFactory = $resultJsonFactory; + $this->resultRawFactory = $resultRawFactory; } /** @@ -58,7 +74,7 @@ public function __construct( * * Expects a POST. ex for JSON {"username":"user@magento.com", "password":"userpassword"} * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { @@ -66,15 +82,15 @@ public function execute() $httpBadRequestCode = 400; $httpUnauthorizedCode = 401; + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultRawFactory->create(); try { $credentials = $this->helper->jsonDecode($this->getRequest()->getRawBody()); } catch (\Exception $e) { - $this->getResponse()->setHttpResponseCode($httpBadRequestCode); - return; + return $resultRaw->setHttpResponseCode($httpBadRequestCode); } if (!$credentials || $this->getRequest()->getMethod() !== 'POST' || !$this->getRequest()->isXmlHttpRequest()) { - $this->getResponse()->setHttpResponseCode($httpBadRequestCode); - return; + return $resultRaw->setHttpResponseCode($httpBadRequestCode); } $responseText = null; try { @@ -92,10 +108,12 @@ public function execute() $responseText = __('There was an error validating the username and password.'); } if ($responseText) { - $this->getResponse()->setHttpResponseCode($httpUnauthorizedCode); + return $resultRaw->setHttpResponseCode($httpUnauthorizedCode); } else { $responseText = __('Login successful.'); } - $this->getResponse()->representJson($this->helper->jsonEncode(['message' => $responseText])); + /** @var \Magento\Framework\Controller\Result\JSON $resultJson */ + $resultJson = $this->resultJsonFactory->create(); + return $resultJson->setData(['message' => $responseText]); } } diff --git a/app/code/Magento/Customer/Controller/Ajax/Logout.php b/app/code/Magento/Customer/Controller/Ajax/Logout.php index dcc5ba7a6fb85..a8642fbad22a5 100644 --- a/app/code/Magento/Customer/Controller/Ajax/Logout.php +++ b/app/code/Magento/Customer/Controller/Ajax/Logout.php @@ -21,32 +21,31 @@ class Logout extends \Magento\Framework\App\Action\Action protected $session; /** - * @var \Magento\Core\Helper\Data $helper + * @var \Magento\Framework\Controller\Result\JSONFactory */ - protected $helper; + protected $resultJsonFactory; /** * Initialize Logout controller * * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Core\Helper\Data $helper + * @param \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, - \Magento\Core\Helper\Data $helper + \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory ) { parent::__construct($context); $this->customerSession = $customerSession; - $this->helper = $helper; - + $this->resultJsonFactory = $resultJsonFactory; } /** * Customer logout action * - * @return void + * @return \Magento\Framework\Controller\Result\JSON */ public function execute() { @@ -55,6 +54,8 @@ public function execute() ->setBeforeAuthUrl($this->_redirect->getRefererUrl()) ->setLastCustomerId($lastCustomerId); - $this->getResponse()->representJson($this->helper->jsonEncode(['message' => 'Logout Successful'])); + /** @var \Magento\Framework\Controller\Result\JSON $resultJson */ + $resultJson = $this->resultJsonFactory->create(); + return $resultJson->setData(['message' => 'Logout Successful']); } } diff --git a/app/code/Magento/Customer/Controller/Review.php b/app/code/Magento/Customer/Controller/Review.php new file mode 100644 index 0000000000000..2a667e4c3e77f --- /dev/null +++ b/app/code/Magento/Customer/Controller/Review.php @@ -0,0 +1,37 @@ +resultPageFactory = $resultPageFactory; + } + + /** + * @return \Magento\Framework\View\Result\Page + */ + public function execute() + { + return $this->resultPageFactory->create(); + } +} diff --git a/app/code/Magento/Customer/Controller/Review/Index.php b/app/code/Magento/Customer/Controller/Review/Index.php index fb697115a0c2b..c1424869b06cc 100644 --- a/app/code/Magento/Customer/Controller/Review/Index.php +++ b/app/code/Magento/Customer/Controller/Review/Index.php @@ -6,14 +6,6 @@ */ namespace Magento\Customer\Controller\Review; -class Index extends \Magento\Framework\App\Action\Action +class Index extends \Magento\Customer\Controller\Review { - /** - * @return void - */ - public function execute() - { - $this->_view->loadLayout(); - $this->_view->renderLayout(); - } } diff --git a/app/code/Magento/Customer/Controller/Review/View.php b/app/code/Magento/Customer/Controller/Review/View.php index f648ce1ea74a0..8ee24a903b1af 100644 --- a/app/code/Magento/Customer/Controller/Review/View.php +++ b/app/code/Magento/Customer/Controller/Review/View.php @@ -6,14 +6,6 @@ */ namespace Magento\Customer\Controller\Review; -class View extends \Magento\Framework\App\Action\Action +class View extends \Magento\Customer\Controller\Review { - /** - * @return void - */ - public function execute() - { - $this->_view->loadLayout(); - $this->_view->renderLayout(); - } } diff --git a/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php b/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php index 0b905639bae41..0fe2f97dcd9b2 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php +++ b/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php @@ -7,8 +7,9 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\ResponseInterface; use Magento\Framework\Registry; +use Magento\Framework\Controller\Result\ForwardFactory; +use Magento\Framework\Controller\Result\RedirectFactory; class OrderLoader implements OrderLoaderInterface { @@ -32,37 +33,51 @@ class OrderLoader implements OrderLoaderInterface */ protected $url; + /** + * @var ForwardFactory + */ + protected $resultForwardFactory; + + /** + * @var Redirect + */ + protected $resultRedirectFactory; + /** * @param \Magento\Sales\Model\OrderFactory $orderFactory * @param OrderViewAuthorizationInterface $orderAuthorization * @param Registry $registry * @param \Magento\Framework\UrlInterface $url + * @param ForwardFactory $resultForwardFactory + * @param RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Sales\Model\OrderFactory $orderFactory, OrderViewAuthorizationInterface $orderAuthorization, Registry $registry, - \Magento\Framework\UrlInterface $url + \Magento\Framework\UrlInterface $url, + ForwardFactory $resultForwardFactory, + RedirectFactory $resultRedirectFactory ) { $this->orderFactory = $orderFactory; $this->orderAuthorization = $orderAuthorization; $this->registry = $registry; $this->url = $url; + $this->resultForwardFactory = $resultForwardFactory; + $this->resultRedirectFactory = $resultRedirectFactory; } /** * @param RequestInterface $request - * @param ResponseInterface $response - * @return bool + * @return bool|\Magento\Framework\Controller\Result\Forward|\Magento\Framework\Controller\Result\Redirect */ - public function load(RequestInterface $request, ResponseInterface $response) + public function load(RequestInterface $request) { $orderId = (int)$request->getParam('order_id'); if (!$orderId) { - $request->initForward(); - $request->setActionName('noroute'); - $request->setDispatched(false); - return false; + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('noroute'); } $order = $this->orderFactory->create()->load($orderId); @@ -71,7 +86,8 @@ public function load(RequestInterface $request, ResponseInterface $response) $this->registry->register('current_order', $order); return true; } - $response->setRedirect($this->url->getUrl('*/*/history')); - return false; + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setUrl($this->url->getUrl('*/*/history')); } } diff --git a/app/code/Magento/Sales/Controller/AbstractController/OrderLoaderInterface.php b/app/code/Magento/Sales/Controller/AbstractController/OrderLoaderInterface.php index 4cb55457ed74a..7f4ba313947af 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/OrderLoaderInterface.php +++ b/app/code/Magento/Sales/Controller/AbstractController/OrderLoaderInterface.php @@ -7,7 +7,6 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\ResponseInterface; interface OrderLoaderInterface { @@ -15,8 +14,7 @@ interface OrderLoaderInterface * Load order * * @param RequestInterface $request - * @param ResponseInterface $response - * @return \Magento\Sales\Model\Order + * @return bool|\Magento\Framework\Controller\ResultInterface */ - public function load(RequestInterface $request, ResponseInterface $response); + public function load(RequestInterface $request); } diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintAction.php b/app/code/Magento/Sales/Controller/AbstractController/PrintAction.php index 67758c6d2a2e5..b011b8f60e592 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintAction.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintAction.php @@ -7,6 +7,7 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; abstract class PrintAction extends \Magento\Framework\App\Action\Action { @@ -15,27 +16,41 @@ abstract class PrintAction extends \Magento\Framework\App\Action\Action */ protected $orderLoader; + /** + * @var PageFactory + */ + protected $resultPageFactory; + /** * @param Context $context * @param OrderLoaderInterface $orderLoader + * @param PageFactory $resultPageFactory */ - public function __construct(Context $context, OrderLoaderInterface $orderLoader) - { + public function __construct( + Context $context, + OrderLoaderInterface $orderLoader, + PageFactory $resultPageFactory + ) { $this->orderLoader = $orderLoader; + $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } /** * Print Order Action * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { - if (!$this->orderLoader->load($this->_request, $this->_response)) { - return; + $result = $this->orderLoader->load($this->_request); + if ($result instanceof \Magento\Framework\Controller\ResultInterface) { + return $result; } - $this->_view->loadLayout('print'); - $this->_view->renderLayout(); + + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->addHandle('print'); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php b/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php index f517e235ca0ab..c2ac3856a201e 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php @@ -7,6 +7,8 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\Controller\Result\RedirectFactory; abstract class PrintCreditmemo extends \Magento\Framework\App\Action\Action { @@ -20,25 +22,41 @@ abstract class PrintCreditmemo extends \Magento\Framework\App\Action\Action */ protected $_coreRegistry; + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry + * @param PageFactory $resultPageFactory + * @param RedirectFactory $resultRedirectFactory */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, - \Magento\Framework\Registry $registry + \Magento\Framework\Registry $registry, + PageFactory $resultPageFactory, + RedirectFactory $resultRedirectFactory ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; + $this->resultPageFactory = $resultPageFactory; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } /** * Print Creditmemo Action * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function execute() { @@ -56,14 +74,19 @@ public function execute() if (isset($creditmemo)) { $this->_coreRegistry->register('current_creditmemo', $creditmemo); } - $this->_view->loadLayout('print'); - $this->_view->renderLayout(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->addHandle('print'); + return $resultPage; } else { + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if ($this->_objectManager->get('Magento\Customer\Model\Session')->isLoggedIn()) { - $this->_redirect('*/*/history'); + $resultRedirect->setPath('*/*/history'); } else { - $this->_redirect('sales/guest/form'); + $resultRedirect->setPath('sales/guest/form'); } + return $resultRedirect; } } } diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php index 740cd5c44d767..6757cdde059b1 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php @@ -7,6 +7,8 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\Controller\Result\RedirectFactory; abstract class PrintInvoice extends \Magento\Framework\App\Action\Action { @@ -20,25 +22,41 @@ abstract class PrintInvoice extends \Magento\Framework\App\Action\Action */ protected $_coreRegistry; + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry + * @param PageFactory $resultPageFactory + * @param RedirectFactory $resultRedirectFactory */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, - \Magento\Framework\Registry $registry + \Magento\Framework\Registry $registry, + PageFactory $resultPageFactory, + RedirectFactory $resultRedirectFactory ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; + $this->resultPageFactory = $resultPageFactory; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } /** * Print Invoice Action * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function execute() { @@ -56,14 +74,19 @@ public function execute() if (isset($invoice)) { $this->_coreRegistry->register('current_invoice', $invoice); } - $this->_view->loadLayout('print'); - $this->_view->renderLayout(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->addHandle('print'); + return $resultPage; } else { + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if ($this->_objectManager->get('Magento\Customer\Model\Session')->isLoggedIn()) { - $this->_redirect('*/*/history'); + $resultRedirect->setPath('*/*/history'); } else { - $this->_redirect('sales/guest/form'); + $resultRedirect->setPath('sales/guest/form'); } + return $resultRedirect; } } } diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php index 755f6caf3dcec..c912a736bf9fc 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php @@ -7,6 +7,8 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\Controller\Result\RedirectFactory; abstract class PrintShipment extends \Magento\Framework\App\Action\Action { @@ -20,25 +22,41 @@ abstract class PrintShipment extends \Magento\Framework\App\Action\Action */ protected $_coreRegistry; + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry + * @param PageFactory $resultPageFactory + * @param RedirectFactory $resultRedirectFactory */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, - \Magento\Framework\Registry $registry + \Magento\Framework\Registry $registry, + PageFactory $resultPageFactory, + RedirectFactory $resultRedirectFactory ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; + $this->resultPageFactory = $resultPageFactory; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } /** * Print Shipment Action * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function execute() { @@ -55,14 +73,19 @@ public function execute() if (isset($shipment)) { $this->_coreRegistry->register('current_shipment', $shipment); } - $this->_view->loadLayout('print'); - $this->_view->renderLayout(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->addHandle('print'); + return $resultPage; } else { + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if ($this->_objectManager->get('Magento\Customer\Model\Session')->isLoggedIn()) { - $this->_redirect('*/*/history'); + $resultRedirect->setPath('*/*/history'); } else { - $this->_redirect('sales/guest/form'); + $resultRedirect->setPath('sales/guest/form'); } + return $resultRedirect; } } } diff --git a/app/code/Magento/Sales/Controller/AbstractController/Reorder.php b/app/code/Magento/Sales/Controller/AbstractController/Reorder.php index d8809a2f86743..6cde3d50e0c33 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/Reorder.php +++ b/app/code/Magento/Sales/Controller/AbstractController/Reorder.php @@ -7,6 +7,8 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action; +use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\Registry; abstract class Reorder extends Action\Action { @@ -16,36 +18,47 @@ abstract class Reorder extends Action\Action protected $orderLoader; /** - * @var \Magento\Framework\Registry + * @var Registry */ protected $_coreRegistry; + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + /** * @param Action\Context $context * @param OrderLoaderInterface $orderLoader - * @param \Magento\Framework\Registry $registry + * @param Registry $registry + * @param RedirectFactory $resultRedirectFactory */ public function __construct( Action\Context $context, OrderLoaderInterface $orderLoader, - \Magento\Framework\Registry $registry + Registry $registry, + RedirectFactory $resultRedirectFactory ) { $this->orderLoader = $orderLoader; $this->_coreRegistry = $registry; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } /** * Action for reorder * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { - if (!$this->orderLoader->load($this->_request, $this->_response)) { - return; + $result = $this->orderLoader->load($this->_request); + if ($result instanceof \Magento\Framework\Controller\ResultInterface) { + return $result; } $order = $this->_coreRegistry->registry('current_order'); + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); /* @var $cart \Magento\Checkout\Model\Cart */ $cart = $this->_objectManager->get('Magento\Checkout\Model\Cart'); @@ -59,14 +72,14 @@ public function execute() } else { $this->messageManager->addError($e->getMessage()); } - $this->_redirect('*/*/history'); + return $resultRedirect->setPath('*/*/history'); } catch (\Exception $e) { $this->messageManager->addException($e, __('We cannot add this item to your shopping cart.')); - $this->_redirect('checkout/cart'); + return $resultRedirect->setPath('checkout/cart'); } } $cart->save(); - $this->_redirect('checkout/cart'); + return $resultRedirect->setPath('checkout/cart'); } } diff --git a/app/code/Magento/Sales/Controller/AbstractController/View.php b/app/code/Magento/Sales/Controller/AbstractController/View.php index 84fec5b2f2fbe..ebc5d087cdd83 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/View.php +++ b/app/code/Magento/Sales/Controller/AbstractController/View.php @@ -7,6 +7,7 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action; +use Magento\Framework\View\Result\PageFactory; abstract class View extends Action\Action { @@ -15,34 +16,46 @@ abstract class View extends Action\Action */ protected $orderLoader; + /** + * @var PageFactory + */ + protected $resultPageFactory; + /** * @param Action\Context $context * @param OrderLoaderInterface $orderLoader + * @param PageFactory $resultPageFactory */ - public function __construct(Action\Context $context, OrderLoaderInterface $orderLoader) - { + public function __construct( + Action\Context $context, + OrderLoaderInterface $orderLoader, + PageFactory $resultPageFactory + ) { $this->orderLoader = $orderLoader; + $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } /** * Order view page * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { - if (!$this->orderLoader->load($this->_request, $this->_response)) { - return; + $result = $this->orderLoader->load($this->_request); + if ($result instanceof \Magento\Framework\Controller\ResultInterface) { + return $result; } - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->initMessages(); - $navigationBlock = $this->_view->getLayout()->getBlock('customer_account_navigation'); + $navigationBlock = $resultPage->getLayout()->getBlock('customer_account_navigation'); if ($navigationBlock) { $navigationBlock->setActive('sales/order/history'); } - $this->_view->renderLayout(); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Email.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Email.php index 5adcd72c8ff0f..b1ef2eacce2f8 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Email.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Email.php @@ -1,6 +1,5 @@ resultRedirectFactory = $resultRedirectFactory; + parent::__construct($context); + } + /** * @return bool */ @@ -24,7 +40,7 @@ protected function _isAllowed() /** * Notify user * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { @@ -40,6 +56,8 @@ public function execute() ->notify($creditmemo); $this->messageManager->addSuccess(__('We sent the message.')); - $this->_redirect('sales/order_creditmemo/view', ['creditmemo_id' => $creditmemoId]); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/order_creditmemo/view', ['creditmemo_id' => $creditmemoId]); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Grid.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Grid.php index 6e5fdf6e84d86..3022cf995e632 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Grid.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Grid.php @@ -1,6 +1,5 @@ resultLayoutFactory = $resultLayoutFactory; + parent::__construct($context); + } + /** * @return bool */ @@ -19,11 +35,11 @@ protected function _isAllowed() /** * Creditmemo grid * - * @return void + * @return \Magento\Framework\View\Result\Layout */ public function execute() { - $this->_view->loadLayout(false); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Index.php index ed012b0449b79..4fbd4c7ff5bd5 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Index.php @@ -1,6 +1,5 @@ resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + /** * @return bool */ @@ -19,32 +35,26 @@ protected function _isAllowed() /** * Init layout, menu and breadcrumb * - * @return $this + * @return \Magento\Backend\Model\View\Result\Page */ protected function _initAction() { - $this->_view->loadLayout(); - $this->_setActiveMenu( - 'Magento_Sales::sales_creditmemo' - )->_addBreadcrumb( - __('Sales'), - __('Sales') - )->_addBreadcrumb( - __('Credit Memos'), - __('Credit Memos') - ); - return $this; + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_creditmemo'); + $resultPage->addBreadcrumb(__('Sales'), __('Sales')); + $resultPage->addBreadcrumb(__('Credit Memos'), __('Credit Memos')); + return $resultPage; } /** * Creditmemos grid * - * @return void + * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { - $this->_initAction(); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Credit Memos')); - $this->_view->renderLayout(); + $resultPage = $this->_initAction(); + $resultPage->getConfig()->getTitle()->prepend(__('Credit Memos')); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php index f34b560b1cd66..685b3042c42c0 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php @@ -1,6 +1,5 @@ _fileFactory = $fileFactory; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } @@ -37,7 +44,7 @@ protected function _isAllowed() } /** - * @return ResponseInterface|void + * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect */ public function execute() { @@ -66,6 +73,8 @@ public function execute() 'application/pdf' ); } - return $this->_redirect('sales/*/'); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/PrintAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/PrintAction.php index 887f2f822a079..a3a52d05c8116 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/PrintAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/PrintAction.php @@ -1,6 +1,5 @@ _fileFactory = $fileFactory; + $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } @@ -37,7 +44,7 @@ protected function _isAllowed() } /** - * @return ResponseInterface|void + * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward */ public function execute() { @@ -60,7 +67,9 @@ public function execute() ); } } else { - $this->_forward('noroute'); + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('noroute'); + return $resultForward; } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/View.php index 267d84431bd5b..06e4209173175 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/View.php @@ -1,6 +1,5 @@ resultForwardFactory = $resultForwardFactory; + parent::__construct($context); + } + /** * @return bool */ @@ -19,15 +35,18 @@ protected function _isAllowed() /** * Creditmemo information page * - * @return void - * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @return \Magento\Backend\Model\View\Result\Forward */ public function execute() { - if ($creditmemoId = $this->getRequest()->getParam('creditmemo_id')) { - $this->_forward('view', 'order_creditmemo', null, ['come_from' => 'sales_creditmemo']); + $resultForward = $this->resultForwardFactory->create(); + if ($this->getRequest()->getParam('creditmemo_id')) { + $resultForward->setController('order_creditmemo'); + $resultForward->setParams(['come_from' => 'sales_creditmemo']); + $resultForward->forward('view'); } else { - $this->_forward('noroute'); + $resultForward->forward('noroute'); } + return $resultForward; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Email.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Email.php index a7fb80086b8bb..95d52611b5dc5 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Email.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Email.php @@ -1,6 +1,5 @@ _fileFactory = $fileFactory; + $this->resultLayoutFactory = $resultLayoutFactory; parent::__construct($context); } @@ -43,9 +50,9 @@ protected function _isAllowed() */ public function execute() { - $this->_view->loadLayout(false); $fileName = 'creditmemos.csv'; - $grid = $grid = $this->_view->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export'); + $resultLayout = $this->resultLayoutFactory->create(); + $grid = $resultLayout->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export'); $csvFile = $grid->getCsvFile(); return $this->_fileFactory->create($fileName, $csvFile, DirectoryList::VAR_DIR); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportExcel.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportExcel.php index 643b9e158a2d1..8fe35c3d16a05 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportExcel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportExcel.php @@ -1,6 +1,5 @@ _fileFactory = $fileFactory; + $this->resultLayoutFactory = $resultLayoutFactory; parent::__construct($context); } @@ -43,13 +50,10 @@ protected function _isAllowed() */ public function execute() { - $this->_view->loadLayout(false); $fileName = 'creditmemos.xml'; - $grid = $this->_view->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export'); - return $this->_fileFactory->create( - $fileName, - $grid->getExcelFile($fileName), - DirectoryList::VAR_DIR - ); + $resultLayout = $this->resultLayoutFactory->create(); + $grid = $resultLayout->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export'); + $excelFile = $grid->getExcelFile($fileName); + return $this->_fileFactory->create($fileName, $excelFile, DirectoryList::VAR_DIR); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Grid.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Grid.php index 84d5eca07eb4a..cd2471aada51d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Grid.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/Grid.php @@ -1,6 +1,5 @@ resultForwardFactory = $resultForwardFactory; + $this->resultRedirectFactory = $resultRedirectFactory; + } + /** * Check if email sending is allowed for the current user * @@ -26,24 +51,24 @@ protected function _isAllowed() /** * Notify user * - * @return void + * @return \Magento\Backend\Model\View\Result\Forward|\Magento\Backend\Model\View\Result\Redirect */ public function execute() { $invoiceId = $this->getRequest()->getParam('invoice_id'); if (!$invoiceId) { - return; + return $this->resultForwardFactory->create()->forward('noroute'); } $invoice = $this->_objectManager->create('Magento\Sales\Model\Order\Invoice')->load($invoiceId); if (!$invoice) { - return; + return $this->resultForwardFactory->create()->forward('noroute'); } $this->_objectManager->create('Magento\Sales\Model\Order\InvoiceNotifier') ->notify($invoice); $this->messageManager->addSuccess(__('We sent the message.')); - $this->_redirect( + return $this->resultRedirectFactory->create()->setPath( 'sales/invoice/view', ['order_id' => $invoice->getOrder()->getId(), 'invoice_id' => $invoiceId] ); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Grid.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Grid.php index 19b5feabca569..d448d97138f60 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Grid.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Grid.php @@ -8,6 +8,23 @@ abstract class Grid extends \Magento\Backend\App\Action { + /** + * @var \Magento\Framework\View\Result\LayoutFactory + */ + protected $resultLayoutFactory; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory + ) { + parent::__construct($context); + $this->resultLayoutFactory = $resultLayoutFactory; + } + /** * {@inheritdoc} */ @@ -19,11 +36,10 @@ protected function _isAllowed() /** * Order grid * - * @return void + * @return \Magento\Framework\View\Result\Layout */ public function execute() { - $this->_view->loadLayout(false); - $this->_view->renderLayout(); + return $this->resultLayoutFactory->create(); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Index.php index 0c8de955d7fa7..e88f6089c48b4 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Index.php @@ -8,6 +8,23 @@ abstract class Index extends \Magento\Backend\App\Action { + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $resultPageFactory; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\View\Result\PageFactory $resultPageFactory + ) { + parent::__construct($context); + $this->resultPageFactory = $resultPageFactory; + } + /** * {@inheritdoc} */ @@ -19,32 +36,27 @@ protected function _isAllowed() /** * Init layout, menu and breadcrumb * - * @return $this + * @return \Magento\Backend\Model\View\Result\Page */ protected function _initAction() { - $this->_view->loadLayout(); - $this->_setActiveMenu( - 'Magento_Sales::sales_invoice' - )->_addBreadcrumb( - __('Sales'), - __('Sales') - )->_addBreadcrumb( - __('Invoices'), - __('Invoices') - ); - return $this; + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_invoice') + ->addBreadcrumb(__('Sales'), __('Sales')) + ->addBreadcrumb(__('Invoices'), __('Invoices')); + return $resultPage; } /** * Invoices grid * - * @return void + * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { - $this->_initAction(); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Invoices')); - $this->_view->renderLayout(); + $resultPage = $this->_initAction(); + $resultPage->getConfig()->getTitle()->prepend(__('Invoices')); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php index 636168c3ed1ab..1f8389a86a55c 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php @@ -16,16 +16,24 @@ abstract class Pdfinvoices extends \Magento\Backend\App\Action */ protected $_fileFactory; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory + */ + protected $resultRedirectFactory; + /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + \Magento\Framework\App\Response\Http\FileFactory $fileFactory, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory ) { $this->_fileFactory = $fileFactory; parent::__construct($context); + $this->resultRedirectFactory = $resultRedirectFactory; } /** @@ -43,14 +51,10 @@ public function execute() { $invoicesIds = $this->getRequest()->getPost('invoice_ids'); if (!empty($invoicesIds)) { - $invoices = $this->_objectManager->create( - 'Magento\Sales\Model\Resource\Order\Invoice\Collection' - )->addAttributeToSelect( - '*' - )->addAttributeToFilter( - 'entity_id', - ['in' => $invoicesIds] - )->load(); + $invoices = $this->_objectManager->create('Magento\Sales\Model\Resource\Order\Invoice\Collection') + ->addAttributeToSelect('*') + ->addAttributeToFilter('entity_id', ['in' => $invoicesIds]) + ->load(); if (!isset($pdf)) { $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice')->getPdf($invoices); } else { @@ -66,6 +70,6 @@ public function execute() 'application/pdf' ); } - $this->_redirect('sales/*/'); + return $this->resultRedirectFactory->create()->setPath('sales/*/'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php index d16c7f9bf390e..b642486c7f8ce 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php @@ -16,16 +16,24 @@ abstract class PrintAction extends \Magento\Backend\App\Action */ protected $_fileFactory; + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory + */ + protected $resultForwardFactory; + /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + \Magento\Framework\App\Response\Http\FileFactory $fileFactory, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory ) { $this->_fileFactory = $fileFactory; parent::__construct($context); + $this->resultForwardFactory = $resultForwardFactory; } /** @@ -55,7 +63,7 @@ public function execute() ); } } else { - $this->_forward('noroute'); + return $this->resultForwardFactory->create()->forward('noroute'); } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/View.php index b3143632331c9..53eb15b93933d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/View.php @@ -16,14 +16,24 @@ abstract class View extends \Magento\Backend\App\Action */ protected $registry; + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory + */ + protected $resultForwardFactory; + /** * @param Context $context * @param Registry $registry + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory */ - public function __construct(Context $context, Registry $registry) - { + public function __construct( + Context $context, + Registry $registry, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + ) { $this->registry = $registry; parent::__construct($context); + $this->resultForwardFactory = $resultForwardFactory; } /** @@ -37,15 +47,19 @@ protected function _isAllowed() /** * Invoice information page * - * @return void + * @return \Magento\Backend\Model\View\Result\Forward */ public function execute() { + $resultForward = $this->resultForwardFactory->create(); if ($this->getRequest()->getParam('invoice_id')) { - $this->_forward('view', 'order_invoice', null, ['come_from' => 'invoice']); + $resultForward->setController('order_invoice') + ->setParams(['come_from' => 'invoice']) + ->forward('view'); } else { - $this->_forward('noroute'); + $resultForward->forward('noroute'); } + return $resultForward; } /** diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportCsv.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportCsv.php index 26199ce027a33..d682c410cfb86 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportCsv.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportCsv.php @@ -16,16 +16,24 @@ class ExportCsv extends \Magento\Backend\App\Action */ protected $_fileFactory; + /** + * @var \Magento\Framework\View\Result\LayoutFactory + */ + protected $resultLayoutFactory; + /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + \Magento\Framework\App\Response\Http\FileFactory $fileFactory, + \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory ) { $this->_fileFactory = $fileFactory; parent::__construct($context); + $this->resultLayoutFactory = $resultLayoutFactory; } /** @@ -43,10 +51,11 @@ protected function _isAllowed() */ public function execute() { - $this->_view->loadLayout(); $fileName = 'invoices.csv'; /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */ - $exportBlock = $this->_view->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export'); + $exportBlock = $this->resultLayoutFactory->create() + ->getLayout() + ->getChildBlock('sales.invoice.grid', 'grid.export'); return $this->_fileFactory->create( $fileName, $exportBlock->getCsvFile(), diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportExcel.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportExcel.php index f11bb97aad261..ab6d4519ffb61 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportExcel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportExcel.php @@ -16,16 +16,24 @@ class ExportExcel extends \Magento\Backend\App\Action */ protected $_fileFactory; + /** + * @var \Magento\Framework\View\Result\LayoutFactory + */ + protected $resultLayoutFactory; + /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + \Magento\Framework\App\Response\Http\FileFactory $fileFactory, + \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory ) { $this->_fileFactory = $fileFactory; parent::__construct($context); + $this->resultLayoutFactory = $resultLayoutFactory; } /** @@ -43,9 +51,10 @@ protected function _isAllowed() */ public function execute() { - $this->_view->loadLayout(); $fileName = 'invoices.xml'; - $exportBlock = $this->_view->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export'); + $exportBlock = $this->resultLayoutFactory->create() + ->getLayout() + ->getChildBlock('sales.invoice.grid', 'grid.export'); return $this->_fileFactory->create( $fileName, $exportBlock->getExcelFile($fileName), diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order.php b/app/code/Magento/Sales/Controller/Adminhtml/Order.php index ae425500611ad..3a2d6a0ea4e98 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order.php @@ -39,42 +39,76 @@ class Order extends \Magento\Backend\App\Action */ protected $_translateInline; + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $resultPageFactory; + + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @var \Magento\Framework\Controller\Result\JSONFactory + */ + protected $resultJsonFactory; + + /** + * @var \Magento\Framework\View\Result\LayoutFactory + */ + protected $resultLayoutFactory; + + /** + * @var \Magento\Framework\Controller\Result\RawFactory + */ + protected $resultRawFactory; + /** * @param Action\Context $context * @param \Magento\Framework\Registry $coreRegistry * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory * @param \Magento\Framework\Translate\InlineInterface $translateInline + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + * @param \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory + * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory + * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory */ public function __construct( Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\App\Response\Http\FileFactory $fileFactory, - \Magento\Framework\Translate\InlineInterface $translateInline + \Magento\Framework\Translate\InlineInterface $translateInline, + \Magento\Framework\View\Result\PageFactory $resultPageFactory, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, + \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory, + \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, + \Magento\Framework\Controller\Result\RawFactory $resultRawFactory ) { $this->_coreRegistry = $coreRegistry; $this->_fileFactory = $fileFactory; $this->_translateInline = $translateInline; + $this->resultPageFactory = $resultPageFactory; + $this->resultRedirectFactory = $resultRedirectFactory; + $this->resultJsonFactory = $resultJsonFactory; + $this->resultLayoutFactory = $resultLayoutFactory; + $this->resultRawFactory = $resultRawFactory; parent::__construct($context); } /** * Init layout, menu and breadcrumb * - * @return $this + * @return \Magento\Backend\Model\View\Result\Page */ protected function _initAction() { - $this->_view->loadLayout(); - $this->_setActiveMenu( - 'Magento_Sales::sales_order' - )->_addBreadcrumb( - __('Sales'), - __('Sales') - )->_addBreadcrumb( - __('Orders'), - __('Orders') - ); - return $this; + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_order'); + $resultPage->addBreadcrumb(__('Sales'), __('Sales')); + $resultPage->addBreadcrumb(__('Orders'), __('Orders')); + return $resultPage; } /** @@ -89,7 +123,6 @@ protected function _initOrder() if (!$order->getId()) { $this->messageManager->addError(__('This order no longer exists.')); - $this->_redirect('sales/*/'); $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); return false; } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/AddComment.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/AddComment.php index 6cdc808e9f211..11e69b7893e5a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/AddComment.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/AddComment.php @@ -14,14 +14,13 @@ class AddComment extends \Magento\Sales\Controller\Adminhtml\Order /** * Add order comment action * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $order = $this->_initOrder(); if ($order) { try { - $response = false; $data = $this->getRequest()->getPost('history'); if (empty($data['comment']) && $data['status'] == $order->getDataByKey('status')) { throw new \Magento\Framework\Model\Exception(__('Comment text cannot be empty.')); @@ -44,17 +43,18 @@ public function execute() $orderCommentSender->send($order, $notify, $comment); - $this->_view->loadLayout(); - $this->_view->renderLayout(); + return $this->resultPageFactory->create(); } catch (\Magento\Framework\Model\Exception $e) { $response = ['error' => true, 'message' => $e->getMessage()]; } catch (\Exception $e) { $response = ['error' => true, 'message' => __('We cannot add order history.')]; } if (is_array($response)) { - $response = $this->_objectManager->get('Magento\Core\Helper\Data')->jsonEncode($response); - $this->getResponse()->representJson($response); + $resultJson = $this->resultJsonFactory->create(); + $resultJson->setData($response); + return $resultJson; } } + return $this->resultRedirectFactory->create()->setPath('sales/*/'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Address.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Address.php index 40a3adf8a347a..0b5697e7c48df 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Address.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Address.php @@ -6,13 +6,12 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; - class Address extends \Magento\Sales\Controller\Adminhtml\Order { /** * Edit order address form * - * @return void + * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect */ public function execute() { @@ -20,16 +19,16 @@ public function execute() $address = $this->_objectManager->create('Magento\Sales\Model\Order\Address')->load($addressId); if ($address->getId()) { $this->_coreRegistry->register('order_address', $address); - $this->_view->loadLayout(); + $resultPage = $this->resultPageFactory->create(); // Do not display VAT validation button on edit order address form - $addressFormContainer = $this->_view->getLayout()->getBlock('sales_order_address.form.container'); + $addressFormContainer = $resultPage->getLayout()->getBlock('sales_order_address.form.container'); if ($addressFormContainer) { $addressFormContainer->getChildBlock('form')->setDisplayVatValidationButton(false); } - $this->_view->renderLayout(); + return $resultPage; } else { - $this->_redirect('sales/*/'); + return $this->resultRedirectFactory->create()->setPath('sales/*/'); } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php index 64de4a63ab815..4a03aa4f50533 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php @@ -6,34 +6,33 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; - class AddressSave extends \Magento\Sales\Controller\Adminhtml\Order { /** * Save order address * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $addressId = $this->getRequest()->getParam('address_id'); $address = $this->_objectManager->create('Magento\Sales\Model\Order\Address')->load($addressId); $data = $this->getRequest()->getPost(); + $resultRedirect = $this->resultRedirectFactory->create(); if ($data && $address->getId()) { $address->addData($data); try { $address->save(); $this->messageManager->addSuccess(__('You updated the order address.')); - $this->_redirect('sales/*/view', ['order_id' => $address->getParentId()]); - return; + return $resultRedirect->setPath('sales/*/view', ['order_id' => $address->getParentId()]); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong updating the order address.')); } - $this->_redirect('sales/*/address', ['address_id' => $address->getId()]); + return $resultRedirect->setPath('sales/*/address', ['address_id' => $address->getId()]); } else { - $this->_redirect('sales/*/'); + return $resultRedirect->setPath('sales/*/'); } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php index 3ee46f66b1e7f..95348128c1605 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php @@ -6,17 +6,17 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; - class Cancel extends \Magento\Sales\Controller\Adminhtml\Order { /** * Cancel order * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $order = $this->_initOrder(); + $resultRedirect = $this->resultRedirectFactory->create(); if ($order) { try { $order->cancel()->save(); @@ -27,7 +27,8 @@ public function execute() $this->messageManager->addError(__('You have not canceled the item.')); $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); } - $this->_redirect('sales/order/view', ['order_id' => $order->getId()]); + return $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]); } + return $resultRedirect->setPath('sales/*/'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php index e8c38f303537f..737fa3bfed281 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php @@ -6,24 +6,70 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; +use Magento\Backend\App\Action; class CommentsHistory extends \Magento\Sales\Controller\Adminhtml\Order { + /** + * @var \Magento\Framework\View\LayoutFactory + */ + protected $layoutFactory; + + /** + * @param Action\Context $context + * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @param \Magento\Framework\Translate\InlineInterface $translateInline + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + * @param \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory + * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory + * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory + * @param \Magento\Framework\View\LayoutFactory $layoutFactory + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) + */ + public function __construct( + Action\Context $context, + \Magento\Framework\Registry $coreRegistry, + \Magento\Framework\App\Response\Http\FileFactory $fileFactory, + \Magento\Framework\Translate\InlineInterface $translateInline, + \Magento\Framework\View\Result\PageFactory $resultPageFactory, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, + \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory, + \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, + \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, + \Magento\Framework\View\LayoutFactory $layoutFactory + ) { + $this->layoutFactory = $layoutFactory; + parent::__construct( + $context, + $coreRegistry, + $fileFactory, + $translateInline, + $resultPageFactory, + $resultRedirectFactory, + $resultJsonFactory, + $resultLayoutFactory, + $resultRawFactory + ); + } + /** * Generate order history for ajax request * - * @return void + * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $this->_initOrder(); - - $html = $this->_view->getLayout()->createBlock( - 'Magento\Sales\Block\Adminhtml\Order\View\Tab\History' - )->toHtml(); - + $layout = $this->layoutFactory->create(); + $html = $layout->createBlock('Magento\Sales\Block\Adminhtml\Order\View\Tab\History') + ->toHtml(); $this->_translateInline->processResponseBody($html); - - $this->getResponse()->setBody($html); + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultRawFactory->create(); + $resultRaw->setContents($html); + return $resultRaw; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php index 08ac01a05321a..0cb717d3fc026 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php @@ -6,6 +6,9 @@ namespace Magento\Sales\Controller\Adminhtml\Order; use Magento\Backend\App\Action; +use Magento\Framework\View\Result\PageFactory; +use Magento\Backend\Model\View\Result\RedirectFactory; +use Magento\Backend\Model\View\Result\ForwardFactory; /** * Adminhtml sales orders creation process controller @@ -20,19 +23,43 @@ class Create extends \Magento\Backend\App\Action */ protected $escaper; + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory + */ + protected $resultForwardFactory; + /** * @param Action\Context $context * @param \Magento\Catalog\Helper\Product $productHelper * @param \Magento\Framework\Escaper $escaper + * @param PageFactory $resultPageFactory + * @param RedirectFactory $resultRedirectFactory + * @param ForwardFactory $resultForwardFactory */ public function __construct( Action\Context $context, \Magento\Catalog\Helper\Product $productHelper, - \Magento\Framework\Escaper $escaper + \Magento\Framework\Escaper $escaper, + PageFactory $resultPageFactory, + RedirectFactory $resultRedirectFactory, + ForwardFactory $resultForwardFactory ) { parent::__construct($context); $productHelper->setSkipSaleableCheck(true); $this->escaper = $escaper; + $this->resultPageFactory = $resultPageFactory; + $this->resultRedirectFactory = $resultRedirectFactory; + $this->resultForwardFactory = $resultForwardFactory; } /** diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/AddConfigured.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/AddConfigured.php index 7511db2d01096..c227e3e29e51b 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/AddConfigured.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/AddConfigured.php @@ -1,18 +1,16 @@ setJsVarName($this->getRequest()->getParam('as_js_varname')); $this->_objectManager->get('Magento\Backend\Model\Session')->setCompositeProductResult($updateResult); - $this->_redirect('catalog/product/showUpdateResult'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('catalog/product/showUpdateResult'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Cancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Cancel.php index ef392ae0e94e1..f778a07a85a4f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Cancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Cancel.php @@ -1,27 +1,29 @@ resultRedirectFactory->create(); + if ($orderId = $this->_getSession()->getReordered()) { $this->_getSession()->clearStorage(); - $this->_redirect('sales/order/view', ['order_id' => $orderId]); + $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]); } else { $this->_getSession()->clearStorage(); - $this->_redirect('sales/*'); + $resultRedirect->setPath('sales/*'); } + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ConfigureProductToAdd.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ConfigureProductToAdd.php index 1faa32102d993..3724dfc4c4418 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ConfigureProductToAdd.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ConfigureProductToAdd.php @@ -1,18 +1,16 @@ setCurrentCustomerId($sessionQuote->getCustomerId()); // Render page - $this->_objectManager->get( - 'Magento\Catalog\Helper\Product\Composite' - )->renderConfigureResult( - $configureResult - ); + /** @var \Magento\Catalog\Helper\Product\Composite $helper */ + $helper = $this->_objectManager->get('Magento\Catalog\Helper\Product\Composite'); + return $helper->renderConfigureResult($configureResult); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ConfigureQuoteItems.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ConfigureQuoteItems.php index 25038c8a58553..cb7c4bd4565c3 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ConfigureQuoteItems.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ConfigureQuoteItems.php @@ -1,18 +1,16 @@ setOk(true); - $optionCollection = $this->_objectManager->create( - 'Magento\Quote\Model\Quote\Item\Option' - )->getCollection()->addItemFilter( - [$quoteItemId] - ); + $optionCollection = $this->_objectManager->create('Magento\Quote\Model\Quote\Item\Option') + ->getCollection() + ->addItemFilter([$quoteItemId]); $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem)); $configureResult->setBuyRequest($quoteItem->getBuyRequest()); @@ -48,10 +44,8 @@ public function execute() } // Render page - $this->_objectManager->get( - 'Magento\Catalog\Helper\Product\Composite' - )->renderConfigureResult( - $configureResult - ); + /** @var \Magento\Catalog\Helper\Product\Composite $helper */ + $helper = $this->_objectManager->get('Magento\Catalog\Helper\Product\Composite'); + return $helper->renderConfigureResult($configureResult); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Index.php index e4cc27c5f1da1..055b3fe11f811 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Index.php @@ -1,12 +1,10 @@ _initSession(); - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::sales_order'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Orders')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('New Order')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_order'); + $resultPage->getConfig()->getTitle()->prepend(__('Orders')); + $resultPage->getConfig()->getTitle()->prepend(__('New Order')); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php index 978b1dee0a5b4..23a119fdb8a03 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php @@ -1,18 +1,56 @@ resultRawFactory = $resultRawFactory; + parent::__construct( + $context, + $productHelper, + $escaper, + $resultPageFactory, + $resultRedirectFactory, + $resultForwardFactory + ); + } + /** * Loading page block * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Framework\Controller\Result\Raw */ public function execute() { @@ -30,11 +68,12 @@ public function execute() $asJson = $request->getParam('json'); $block = $request->getParam('block'); - $update = $this->_view->getLayout()->getUpdate(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); if ($asJson) { - $update->addHandle('sales_order_create_load_block_json'); + $resultPage->addHandle('sales_order_create_load_block_json'); } else { - $update->addHandle('sales_order_create_load_block_plain'); + $resultPage->addHandle('sales_order_create_load_block_plain'); } if ($block) { @@ -44,18 +83,15 @@ public function execute() } foreach ($blocks as $block) { - $update->addHandle('sales_order_create_load_block_' . $block); + $resultPage->addHandle('sales_order_create_load_block_' . $block); } } - $this->_view->loadLayoutUpdates(); - $this->_view->generateLayoutXml(); - $this->_view->generateLayoutBlocks(); - $result = $this->_view->getLayout()->renderElement('content'); + + $result = $resultPage->getLayout()->renderElement('content'); if ($request->getParam('as_js_varname')) { $this->_objectManager->get('Magento\Backend\Model\Session')->setUpdateResult($result); - $this->_redirect('sales/*/showUpdateResult'); - } else { - $this->getResponse()->setBody($result); + return $this->resultRedirectFactory->create()->setPath('sales/*/showUpdateResult'); } + return $this->resultRawFactory->create()->setContents($result); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ProcessData.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ProcessData.php index edfcef2f8d5c0..7d550a7d35730 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ProcessData.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ProcessData.php @@ -1,23 +1,21 @@ _initSession(); $this->_processData(); - $this->_forward('index'); + return $this->resultForwardFactory->create()->forward('index'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php index f7b20dec9d530..8a6ec65118647 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php @@ -1,16 +1,14 @@ getRequest()->getParam('order_id'); $order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($orderId); if (!$this->_objectManager->get('Magento\Sales\Helper\Reorder')->canReorder($order)) { - $this->_forward('noroute'); - return; + return $this->resultForwardFactory->create()->forward('noroute'); } + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if ($order->getId()) { $order->setReordered(true); $this->_getSession()->setUseOldShippingMethod(true); $this->_getOrderCreateModel()->initFromOrder($order); - $this->_redirect('sales/*'); + $resultRedirect->setPath('sales/*'); } else { - $this->_redirect('sales/order/'); + $resultRedirect->setPath('sales/order/'); } + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php index 49c7f1ae5ff48..a3dfe5d004feb 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php @@ -1,30 +1,30 @@ resultRedirectFactory->create(); try { // check if the creation of a new customer is allowed if (!$this->_authorization->isAllowed('Magento_Customer::manage') && !$this->_getSession()->getCustomerId() && !$this->_getSession()->getQuote()->getCustomerIsGuest() ) { - $this->_forward('denied'); - return; + return $this->resultForwardFactory->create()->forward('denied'); } $this->_getOrderCreateModel()->getQuote()->setCustomerId($this->_getSession()->getCustomerId()); $this->_processActionData('save'); @@ -41,18 +41,17 @@ public function execute() $this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentData); } - $order = $this->_getOrderCreateModel()->setIsValidate( - true - )->importPostData( - $this->getRequest()->getPost('order') - )->createOrder(); + $order = $this->_getOrderCreateModel() + ->setIsValidate(true) + ->importPostData($this->getRequest()->getPost('order')) + ->createOrder(); $this->_getSession()->clearStorage(); $this->messageManager->addSuccess(__('You created the order.')); if ($this->_authorization->isAllowed('Magento_Sales::actions_view')) { - $this->_redirect('sales/order/view', ['order_id' => $order->getId()]); + $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]); } else { - $this->_redirect('sales/order/index'); + $resultRedirect->setPath('sales/order/index'); } } catch (\Magento\Payment\Model\Info\Exception $e) { $this->_getOrderCreateModel()->saveQuote(); @@ -60,16 +59,17 @@ public function execute() if (!empty($message)) { $this->messageManager->addError($message); } - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); } catch (\Magento\Framework\Model\Exception $e) { $message = $e->getMessage(); if (!empty($message)) { $this->messageManager->addError($message); } - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); } catch (\Exception $e) { $this->messageManager->addException($e, __('Order saving error: %1', $e->getMessage())); - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); } + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php index 2ea9867f5bc21..e06ee1a7c43c7 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php @@ -1,29 +1,67 @@ resultRawFactory = $resultRawFactory; + parent::__construct( + $context, + $productHelper, + $escaper, + $resultPageFactory, + $resultRedirectFactory, + $resultForwardFactory + ); + } + /** * Show item update result from loadBlockAction * to prevent popup alert with resend data question * - * @return void|false + * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultRawFactory->create(); $session = $this->_objectManager->get('Magento\Backend\Model\Session'); if ($session->hasUpdateResult() && is_scalar($session->getUpdateResult())) { - $this->getResponse()->setBody($session->getUpdateResult()); - $session->unsUpdateResult(); - } else { - $session->unsUpdateResult(); - return false; + $resultRaw->setContents($session->getUpdateResult()); } + $session->unsUpdateResult(); + return $resultRaw; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Start.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Start.php index 8b1ed6fe7f4ec..d9fd5c50f5bad 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Start.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Start.php @@ -1,6 +1,5 @@ _getSession()->clearStorage(); - $this->_redirect('sales/*', ['customer_id' => $this->getRequest()->getParam('customer_id')]); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('sales/*', ['customer_id' => $this->getRequest()->getParam('customer_id')]); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/AddComment.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/AddComment.php index 5ac857457ffa0..694132c1b6cba 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/AddComment.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/AddComment.php @@ -1,6 +1,5 @@ creditmemoLoader = $creditmemoLoader; $this->creditmemoSender = $creditmemoSender; + $this->resultPageFactory = $resultPageFactory; + $this->resultJsonFactory = $resultJsonFactory; + $this->resultRawFactory = $resultRawFactory; parent::__construct($context); } @@ -47,7 +70,7 @@ protected function _isAllowed() /** * Add comment to creditmemo history * - * @return void + * @return \Magento\Framework\Controller\Result\Raw|\Magento\Framework\Controller\Result\JSON */ public function execute() { @@ -70,20 +93,21 @@ public function execute() $comment->save(); $this->creditmemoSender->send($creditmemo, !empty($data['is_customer_notified']), $data['comment']); - - $this->_view->loadLayout(); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Credit Memos')); - $response = $this->_view->getLayout()->getBlock('creditmemo_comments')->toHtml(); + $resultPage = $this->resultPageFactory->create(); + $response = $resultPage->getLayout()->getBlock('creditmemo_comments')->toHtml(); } catch (\Magento\Framework\Model\Exception $e) { $response = ['error' => true, 'message' => $e->getMessage()]; } catch (\Exception $e) { $response = ['error' => true, 'message' => __('Cannot add new comment.')]; } if (is_array($response)) { - $response = $this->_objectManager->get('Magento\Core\Helper\Data')->jsonEncode($response); - $this->getResponse()->representJson($response); + $resultJson = $this->resultJsonFactory->create(); + $resultJson->setData($response); + return $resultJson; } else { - $this->getResponse()->setBody($response); + $resultRaw = $this->resultRawFactory->create(); + $resultRaw->setContents($response); + return $resultRaw; } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Cancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Cancel.php index 2ed673c858d47..07a295c9d7ce7 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Cancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Cancel.php @@ -1,6 +1,5 @@ creditmemoLoader = $creditmemoLoader; + $this->resultRedirectFactory = $resultRedirectFactory; + $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } @@ -38,7 +53,7 @@ protected function _isAllowed() /** * Cancel creditmemo action * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward */ public function execute() { @@ -64,9 +79,13 @@ public function execute() } catch (\Exception $e) { $this->messageManager->addError(__('You canceled the credit memo.')); } - $this->_redirect('sales/*/view', ['creditmemo_id' => $creditmemo->getId()]); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/view', ['creditmemo_id' => $creditmemo->getId()]); + return $resultRedirect; } else { - $this->_forward('noroute'); + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('noroute'); + return $resultForward; } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Email.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Email.php index bfca5391844c5..99d8fcab5197e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Email.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Email.php @@ -1,6 +1,5 @@ creditmemoLoader = $creditmemoLoader; + $this->resultPageFactory = $resultPageFactory; + $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } @@ -38,7 +53,7 @@ protected function _isAllowed() /** * Creditmemo create page * - * @return void + * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Forward */ public function execute() { @@ -51,20 +66,21 @@ public function execute() if ($comment = $this->_objectManager->get('Magento\Backend\Model\Session')->getCommentText(true)) { $creditmemo->setCommentText($comment); } - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::sales_order'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Credit Memos')); + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_order'); + $resultPage->getConfig()->getTitle()->prepend(__('Credit Memos')); if ($creditmemo->getInvoice()) { - $this->_view->getPage()->getConfig()->getTitle()->prepend( + $resultPage->getConfig()->getTitle()->prepend( __("New Memo for #%1", $creditmemo->getInvoice()->getIncrementId()) ); } else { - $this->_view->getPage()->getConfig()->getTitle()->prepend(__("New Memo")); + $resultPage->getConfig()->getTitle()->prepend(__("New Memo")); } - - $this->_view->renderLayout(); + return $resultPage; } else { - $this->_forward('noroute'); + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('noroute'); + return $resultForward; } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Pdfcreditmemos.php index 7d168e5581beb..a5b5fce53d043 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Pdfcreditmemos.php @@ -1,6 +1,5 @@ creditmemoLoader = $creditmemoLoader; - parent::__construct($context, $fileFactory); + parent::__construct( + $context, + $fileFactory, + $resultForwardFactory + ); } /** * Create pdf for current creditmemo * - * @return ResponseInterface|void + * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward */ public function execute() { - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Credit Memos')); $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id')); $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id')); $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo')); $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id')); $this->creditmemoLoader->load(); - parent::execute(); + return parent::execute(); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php index 29416472331b4..a505050d95141 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php @@ -1,6 +1,5 @@ creditmemoLoader = $creditmemoLoader; $this->creditmemoSender = $creditmemoSender; + $this->resultRedirectFactory = $resultRedirectFactory; + $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } @@ -49,12 +64,14 @@ protected function _isAllowed() * Save creditmemo * We can save only new creditmemo. Existing creditmemos are not editable * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { + $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPost('creditmemo'); if (!empty($data['comment_text'])) { $this->_getSession()->setCommentText($data['comment_text']); @@ -116,11 +133,12 @@ public function execute() $this->messageManager->addSuccess(__('You created the credit memo.')); $this->_getSession()->getCommentText(true); - $this->_redirect('sales/order/view', ['order_id' => $creditmemo->getOrderId()]); - return; + $resultRedirect->setPath('sales/order/view', ['order_id' => $creditmemo->getOrderId()]); + return $resultRedirect; } else { - $this->_forward('noroute'); - return; + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('noroute'); + return $resultForward; } } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); @@ -129,6 +147,7 @@ public function execute() $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); $this->messageManager->addError(__('Cannot save the credit memo.')); } - $this->_redirect('sales/*/new', ['_current' => true]); + $resultRedirect->setPath('sales/*/new', ['_current' => true]); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php index b9e418f6aecd2..83876b4e643c8 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php @@ -1,6 +1,5 @@ resultRedirectFactory = $resultRedirectFactory; + parent::__construct($context); + } + /** * @return bool */ @@ -19,13 +35,15 @@ protected function _isAllowed() /** * Start create creditmemo action * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { /** * Clear old values for creditmemo qty's */ - $this->_redirect('sales/*/new', ['_current' => true]); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/new', ['_current' => true]); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQty.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQty.php index 04d03cb0fc685..620582eccb7e8 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQty.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQty.php @@ -1,6 +1,5 @@ creditmemoLoader = $creditmemoLoader; + $this->resultPageFactory = $resultPageFactory; + $this->resultJsonFactory = $resultJsonFactory; + $this->resultRawFactory = $resultRawFactory; parent::__construct($context); } @@ -38,7 +61,7 @@ protected function _isAllowed() /** * Update items qty action * - * @return void + * @return \Magento\Framework\Controller\Result\JSON|\Magento\Framework\Controller\Result\Raw */ public function execute() { @@ -48,18 +71,21 @@ public function execute() $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo')); $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id')); $this->creditmemoLoader->load(); - $this->_view->loadLayout(); - $response = $this->_view->getLayout()->getBlock('order_items')->toHtml(); + $resultPage = $this->resultPageFactory->create(); + $response = $resultPage->getLayout()->getBlock('order_items')->toHtml(); } catch (\Magento\Framework\Model\Exception $e) { $response = ['error' => true, 'message' => $e->getMessage()]; } catch (\Exception $e) { $response = ['error' => true, 'message' => __('Cannot update the item\'s quantity.')]; } if (is_array($response)) { - $response = $this->_objectManager->get('Magento\Core\Helper\Data')->jsonEncode($response); - $this->getResponse()->representJson($response); + $resultJson = $this->resultJsonFactory->create(); + $resultJson->setData($response); + return $resultJson; } else { - $this->getResponse()->setBody($response); + $resultRaw = $this->resultRawFactory->create(); + $resultRaw->setContents($response); + return $resultRaw; } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/View.php index 6eaf099fa7b52..486b041554a3b 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/View.php @@ -1,6 +1,5 @@ creditmemoLoader = $creditmemoLoader; + $this->resultPageFactory = $resultPageFactory; + $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } @@ -38,7 +53,7 @@ protected function _isAllowed() /** * Creditmemo information page * - * @return void + * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Forward */ public function execute() { @@ -48,23 +63,22 @@ public function execute() $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id')); $creditmemo = $this->creditmemoLoader->load(); if ($creditmemo) { - $this->_view->loadLayout(); - $this->_view->getLayout()->getBlock( - 'sales_creditmemo_view' - )->updateBackButtonUrl( - $this->getRequest()->getParam('come_from') - ); - $this->_setActiveMenu('Magento_Sales::sales_creditmemo'); + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->getBlock('sales_creditmemo_view') + ->updateBackButtonUrl($this->getRequest()->getParam('come_from')); + $resultPage->setActiveMenu('Magento_Sales::sales_creditmemo'); if ($creditmemo->getInvoice()) { - $this->_view->getPage()->getConfig()->getTitle()->prepend( + $resultPage->getConfig()->getTitle()->prepend( __("View Memo for #%1", $creditmemo->getInvoice()->getIncrementId()) ); } else { - $this->_view->getPage()->getConfig()->getTitle()->prepend(__("View Memo")); + $resultPage->getConfig()->getTitle()->prepend(__("View Memo")); } - $this->_view->renderLayout(); + return $resultPage; } else { - $this->_forward('noroute'); + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('noroute'); + return $resultForward; } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php index 95ab034064a93..eb3ceeb42a540 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php @@ -1,6 +1,5 @@ creditmemoLoader = $creditmemoLoader; + $this->resultRedirectFactory = $resultRedirectFactory; + $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } @@ -38,7 +53,7 @@ protected function _isAllowed() /** * Void creditmemo action * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward */ public function execute() { @@ -64,9 +79,13 @@ public function execute() } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t void the credit memo.')); } - $this->_redirect('sales/*/view', ['creditmemo_id' => $creditmemo->getId()]); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/view', ['creditmemo_id' => $creditmemo->getId()]); + return $resultRedirect; } else { - $this->_forward('noroute'); + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('noroute'); + return $resultForward; } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemos.php index 172a5f71b7143..47634d33a8163 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemos.php @@ -1,23 +1,21 @@ _initOrder(); - $this->_view->loadLayout(false); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Edit/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Edit/Index.php index 886708b3666e9..a40e61cfa89f3 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Edit/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Edit/Index.php @@ -1,6 +1,5 @@ _view->loadLayout(); + $this->_initSession(); - $this->_initSession()->_setActiveMenu('Magento_Sales::sales_order'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Orders')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Edit Order')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_order'); + $resultPage->getConfig()->getTitle()->prepend(__('Orders')); + $resultPage->getConfig()->getTitle()->prepend(__('Edit Order')); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Edit/Start.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Edit/Start.php index 1e50e892e1b90..db163f33467bf 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Edit/Start.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Edit/Start.php @@ -1,6 +1,5 @@ _getSession()->clearStorage(); $orderId = $this->getRequest()->getParam('order_id'); $order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($orderId); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); try { if ($order->getId()) { $this->_getSession()->setUseOldShippingMethod(true); $this->_getOrderCreateModel()->initFromOrder($order); - $this->_redirect('sales/*'); + $resultRedirect->setPath('sales/*'); } else { - $this->_redirect('sales/order/'); + $resultRedirect->setPath('sales/order/'); } } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); - $this->_redirect('sales/order/view', ['order_id' => $orderId]); + $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]); } catch (\Exception $e) { $this->messageManager->addException($e, $e->getMessage()); - $this->_redirect('sales/order/view', ['order_id' => $orderId]); + $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]); } + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Email.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Email.php index c240905d7c244..c310b060b236b 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Email.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Email.php @@ -5,26 +5,19 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; - -/** - * Class Email - * - * @package Magento\Sales\Controller\Adminhtml\Order - */ class Email extends \Magento\Sales\Controller\Adminhtml\Order { /** * Notify user * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $order = $this->_initOrder(); if ($order) { try { - $this->_objectManager->create('Magento\Sales\Model\OrderNotifier') - ->notify($order); + $this->_objectManager->create('Magento\Sales\Model\OrderNotifier')->notify($order); $this->messageManager->addSuccess(__('You sent the order email.')); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); @@ -32,7 +25,8 @@ public function execute() $this->messageManager->addError(__('We couldn\'t send the email order.')); $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); } - $this->_redirect('sales/order/view', ['order_id' => $order->getId()]); + return $this->resultRedirectFactory->create()->setPath('sales/order/view', ['order_id' => $order->getId()]); } + return $this->resultRedirectFactory->create()->setPath('sales/*/'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportCsv.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportCsv.php index f02a513d9a106..6c80caafe4184 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportCsv.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportCsv.php @@ -14,14 +14,15 @@ class ExportCsv extends \Magento\Sales\Controller\Adminhtml\Order /** * Export order grid to CSV format * - * @return ResponseInterface|void + * @return ResponseInterface */ public function execute() { - $this->_view->loadLayout(); $fileName = 'orders.csv'; /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */ - $exportBlock = $this->_view->getLayout()->getChildBlock('sales.order.grid', 'grid.export'); + $exportBlock = $this->resultPageFactory->create() + ->getLayout() + ->getChildBlock('sales.order.grid', 'grid.export'); return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), DirectoryList::VAR_DIR); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportExcel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportExcel.php index 7e01eb106df40..9cb3c880464f2 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportExcel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportExcel.php @@ -14,18 +14,15 @@ class ExportExcel extends \Magento\Sales\Controller\Adminhtml\Order /** * Export order grid to Excel XML format * - * @return ResponseInterface|void + * @return ResponseInterface */ public function execute() { - $this->_view->loadLayout(); $fileName = 'orders.xml'; /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */ - $exportBlock = $this->_view->getLayout()->getChildBlock('sales.order.grid', 'grid.export'); - return $this->_fileFactory->create( - $fileName, - $exportBlock->getExcelFile($fileName), - DirectoryList::VAR_DIR - ); + $exportBlock = $this->resultPageFactory->create() + ->getLayout() + ->getChildBlock('sales.order.grid', 'grid.export'); + return $this->_fileFactory->create($fileName, $exportBlock->getExcelFile($fileName), DirectoryList::VAR_DIR); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Grid.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Grid.php index 21ec8dc28bf51..d16a0ea8cd1d8 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Grid.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Grid.php @@ -1,22 +1,20 @@ _view->loadLayout(false); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Hold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Hold.php index d8239318bfb71..35bd44df57bd9 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Hold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Hold.php @@ -1,22 +1,21 @@ _initOrder(); + $resultRedirect = $this->resultRedirectFactory->create(); if ($order) { try { $order->hold()->save(); @@ -26,7 +25,10 @@ public function execute() } catch (\Exception $e) { $this->messageManager->addError(__('You have not put the order on hold.')); } - $this->_redirect('sales/order/view', ['order_id' => $order->getId()]); + $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]); + return $resultRedirect; } + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Index.php index 01aef35ae1bec..9fc67fd2754f5 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Index.php @@ -1,23 +1,21 @@ _initAction(); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Orders')); - $this->_view->renderLayout(); + $resultPage = $this->_initAction(); + $resultPage->getConfig()->getTitle()->prepend(__('Orders')); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddComment.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddComment.php old mode 100644 new mode 100755 index 05123582711d6..dd2ddd8bd05d9 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddComment.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddComment.php @@ -6,11 +6,15 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; +use Magento\Backend\App\Action\Context; use Magento\Framework\Model\Exception; use Magento\Sales\Model\Order\Email\Sender\InvoiceCommentSender; use Magento\Sales\Model\Order\Invoice; use Magento\Backend\App\Action; use Magento\Framework\Registry; +use Magento\Framework\Controller\Result\JSONFactory; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\Controller\Result\RawFactory; class AddComment extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { @@ -20,23 +24,49 @@ class AddComment extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInv protected $invoiceCommentSender; /** - * @param Action\Context $context + * @var JSONFactory + */ + protected $resultJsonFactory; + + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @var RawFactory + */ + protected $resultRawFactory; + + /** + * @param Context $context * @param Registry $registry + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory * @param InvoiceCommentSender $invoiceCommentSender + * @param JSONFactory $resultJsonFactory + * @param PageFactory $resultPageFactory + * @param RawFactory $resultRawFactory */ public function __construct( - Action\Context $context, + Context $context, Registry $registry, - InvoiceCommentSender $invoiceCommentSender + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + InvoiceCommentSender $invoiceCommentSender, + JSONFactory $resultJsonFactory, + PageFactory $resultPageFactory, + RawFactory $resultRawFactory ) { $this->invoiceCommentSender = $invoiceCommentSender; - parent::__construct($context, $registry); + $this->resultJsonFactory = $resultJsonFactory; + $this->resultPageFactory = $resultPageFactory; + $this->resultRawFactory = $resultRawFactory; + parent::__construct($context, $registry, $resultForwardFactory); } /** * Add comment to invoice action * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { @@ -48,8 +78,9 @@ public function execute() } $invoice = $this->getInvoice(); if (!$invoice) { - $this->_forward('noroute'); - return; + /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('noroute'); } $invoice->addComment( $data['comment'], @@ -60,19 +91,25 @@ public function execute() $this->invoiceCommentSender->send($invoice, !empty($data['is_customer_notified']), $data['comment']); $invoice->save(); - $this->_view->loadLayout(); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Invoices')); - $response = $this->_view->getLayout()->getBlock('invoice_comments')->toHtml(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getConfig()->getTitle()->prepend(__('Invoices')); + $response = $resultPage->getLayout()->getBlock('invoice_comments')->toHtml(); } catch (Exception $e) { $response = ['error' => true, 'message' => $e->getMessage()]; } catch (\Exception $e) { $response = ['error' => true, 'message' => __('Cannot add new comment.')]; } if (is_array($response)) { - $response = $this->_objectManager->get('Magento\Core\Helper\Data')->jsonEncode($response); - $this->getResponse()->representJson($response); + /** @var \Magento\Framework\Controller\Result\JSON $resultJson */ + $resultJson = $this->resultJsonFactory->create(); + $resultJson->setData($response); + return $resultJson; } else { - $this->getResponse()->setBody($response); + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultRawFactory->create(); + $resultRaw->setContents($response); + return $resultRaw; } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Cancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Cancel.php old mode 100644 new mode 100755 index 82ac94d0e9ebb..d2f1abc9532b9 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Cancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Cancel.php @@ -8,20 +8,44 @@ use Magento\Framework\Model\Exception; use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Registry; class Cancel extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param Context $context + * @param Registry $registry + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + */ + public function __construct( + Context $context, + Registry $registry, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + ) { + $this->resultRedirectFactory = $resultRedirectFactory; + parent::__construct($context, $registry, $resultForwardFactory); + } + /** * Cancel invoice action * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $invoice = $this->getInvoice(); if (!$invoice) { - $this->_forward('noroute'); - return; + /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('noroute'); } try { $invoice->cancel(); @@ -39,6 +63,9 @@ public function execute() } catch (\Exception $e) { $this->messageManager->addError(__('Invoice canceling error')); } - $this->_redirect('sales/*/view', ['invoice_id' => $invoice->getId()]); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/view', ['invoice_id' => $invoice->getId()]); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Capture.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Capture.php old mode 100644 new mode 100755 index b9f9ea657e8ad..eb72d6e4ef393 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Capture.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Capture.php @@ -8,20 +8,46 @@ use Magento\Framework\Model\Exception; use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Registry; class Capture extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { + + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param Context $context + * @param Registry $registry + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + */ + public function __construct( + Context $context, + Registry $registry, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + ) { + $this->resultRedirectFactory = $resultRedirectFactory; + parent::__construct($context, $registry, $resultForwardFactory); + } + /** * Capture invoice action * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $invoice = $this->getInvoice(); if (!$invoice) { - $this->_forward('noroute'); - return; + /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + $resultForward->forward('noroute'); + return $resultForward; } try { $invoice->capture(); @@ -39,6 +65,9 @@ public function execute() } catch (\Exception $e) { $this->messageManager->addError(__('Invoice capturing error')); } - $this->_redirect('sales/*/view', ['invoice_id' => $invoice->getId()]); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/view', ['invoice_id' => $invoice->getId()]); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php old mode 100644 new mode 100755 index a6dad9e77d2cf..4b8c4751951aa --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php @@ -8,6 +8,8 @@ use Magento\Backend\App\Action; use Magento\Framework\Registry; +use Magento\Framework\View\Result\PageFactory; +use Magento\Backend\Model\View\Result\RedirectFactory; class NewAction extends \Magento\Backend\App\Action { @@ -16,13 +18,31 @@ class NewAction extends \Magento\Backend\App\Action */ protected $registry; + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + /** * @param Action\Context $context * @param Registry $registry + * @param PageFactory $resultPageFactory + * @param RedirectFactory $resultRedirectFactory */ - public function __construct(Action\Context $context, Registry $registry) - { + public function __construct( + Action\Context $context, + Registry $registry, + PageFactory $resultPageFactory, + RedirectFactory $resultRedirectFactory + ) { $this->registry = $registry; + $this->resultPageFactory = $resultPageFactory; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } @@ -34,10 +54,24 @@ protected function _isAllowed() return $this->_authorization->isAllowed('Magento_Sales::sales_invoice'); } + /** + * Redirect to order view page + * + * @param int $orderId + * @return \Magento\Backend\Model\View\Result\Redirect + */ + protected function _redirectToOrder($orderId) + { + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]); + return $resultRedirect; + } + /** * Invoice create page * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { @@ -70,17 +104,18 @@ public function execute() $invoice->setCommentText($comment); } - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::sales_order'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Invoices')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('New Invoice')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_order'); + $resultPage->getConfig()->getTitle()->prepend(__('Invoices')); + $resultPage->getConfig()->getTitle()->prepend(__('New Invoice')); + return $resultPage; } catch (\Magento\Framework\Exception $exception) { $this->messageManager->addError($exception->getMessage()); - $this->_redirect('sales/order/view', ['order_id' => $orderId]); + return $this->_redirectToOrder($orderId); } catch (\Exception $exception) { $this->messageManager->addException($exception, 'Cannot create an invoice.'); - $this->_redirect('sales/order/view', ['order_id' => $orderId]); + return $this->_redirectToOrder($orderId); } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php old mode 100644 new mode 100755 index cbc04f14c659d..2016270003fdc --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php @@ -12,6 +12,7 @@ use Magento\Sales\Model\Order\Email\Sender\InvoiceCommentSender; use Magento\Sales\Model\Order\Email\Sender\ShipmentSender; use Magento\Sales\Model\Order\Invoice; +use Magento\Backend\Model\View\Result\RedirectFactory; class Save extends \Magento\Backend\App\Action { @@ -30,21 +31,29 @@ class Save extends \Magento\Backend\App\Action */ protected $registry; + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + /** * @param Action\Context $context * @param Registry $registry * @param InvoiceCommentSender $invoiceCommentSender * @param ShipmentSender $shipmentSender + * @param RedirectFactory $resultRedirectFactory */ public function __construct( Action\Context $context, Registry $registry, InvoiceCommentSender $invoiceCommentSender, - ShipmentSender $shipmentSender + ShipmentSender $shipmentSender, + RedirectFactory $resultRedirectFactory ) { $this->registry = $registry; $this->invoiceCommentSender = $invoiceCommentSender; $this->shipmentSender = $shipmentSender; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } @@ -94,7 +103,8 @@ protected function _prepareShipment($invoice) * Save invoice * We can save only new invoice. Existing invoices are not editable * - * @return void + * @return \Magento\Framework\Controller\ResultInterface + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) @@ -108,6 +118,8 @@ public function execute() $this->_objectManager->get('Magento\Backend\Model\Session')->setCommentText($data['comment_text']); } + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); try { $invoiceData = $this->getRequest()->getParam('invoice', []); $invoiceItems = isset($invoiceData['items']) ? $invoiceData['items'] : []; @@ -204,14 +216,13 @@ public function execute() } } $this->_objectManager->get('Magento\Backend\Model\Session')->getCommentText(true); - $this->_redirect('sales/order/view', ['order_id' => $orderId]); - return; + return $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]); } catch (Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t save the invoice.')); $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); } - $this->_redirect('sales/*/new', ['order_id' => $orderId]); + return $resultRedirect->setPath('sales/*/new', ['order_id' => $orderId]); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php old mode 100644 new mode 100755 index 93c6b52b523e2..de0b55ad653d2 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php @@ -6,12 +6,38 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; +use Magento\Backend\Model\View\Result\RedirectFactory; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Registry; + class Start extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { + + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param Context $context + * @param Registry $registry + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param RedirectFactory $resultRedirectFactory + */ + public function __construct( + Context $context, + Registry $registry, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + RedirectFactory $resultRedirectFactory + ) { + $this->resultRedirectFactory = $resultRedirectFactory; + parent::__construct($context, $registry, $resultForwardFactory); + } + /** * Start create invoice action * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { @@ -19,6 +45,10 @@ public function execute() * Clear old values for invoice qty's */ $this->_getSession()->getInvoiceItemQtys(true); - $this->_redirect('sales/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php old mode 100644 new mode 100755 index 6ca233c40b725..e355699ea0d01 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php @@ -8,13 +8,55 @@ use Magento\Framework\Model\Exception; use Magento\Backend\App\Action; +use Magento\Framework\Controller\Result\JSONFactory; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\Controller\Result\RawFactory; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Registry; class UpdateQty extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { + /** + * @var JSONFactory + */ + protected $resultJsonFactory; + + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @var RawFactory + */ + protected $resultRawFactory; + + /** + * @param Context $context + * @param Registry $registry + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param PageFactory $resultPageFactory + * @param JSONFactory $resultJsonFactory + * @param RawFactory $resultRawFactory + */ + public function __construct( + Context $context, + Registry $registry, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + PageFactory $resultPageFactory, + JSONFactory $resultJsonFactory, + RawFactory $resultRawFactory + ) { + $this->resultPageFactory = $resultPageFactory; + $this->resultJsonFactory = $resultJsonFactory; + $this->resultRawFactory = $resultRawFactory; + parent::__construct($context, $registry, $resultForwardFactory); + } + /** * Update items qty action * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { @@ -44,19 +86,25 @@ public function execute() $invoiceRawCommentText = $invoiceData['comment_text']; $invoice->setCommentText($invoiceRawCommentText); - $this->_view->loadLayout(); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Invoices')); - $response = $this->_view->getLayout()->getBlock('order_items')->toHtml(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getConfig()->getTitle()->prepend(__('Invoices')); + $response = $resultPage->getLayout()->getBlock('order_items')->toHtml(); } catch (Exception $e) { $response = ['error' => true, 'message' => $e->getMessage()]; } catch (\Exception $e) { $response = ['error' => true, 'message' => __('Cannot update item quantity.')]; } if (is_array($response)) { - $response = $this->_objectManager->get('Magento\Core\Helper\Data')->jsonEncode($response); - $this->getResponse()->representJson($response); + /** @var \Magento\Framework\Controller\Result\JSON $resultJson */ + $resultJson = $this->resultJsonFactory->create(); + $resultJson->setData($response); + return $resultJson; } else { - $this->getResponse()->setBody($response); + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultRawFactory->create(); + $resultRaw->setContents($response); + return $resultRaw; } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php old mode 100644 new mode 100755 index fd949f6e3d29c..b6f4ae27b44e6 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php @@ -6,30 +6,58 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; +use Magento\Framework\View\Result\PageFactory; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Registry; + class View extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { + + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @param Context $context + * @param Registry $registry + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param PageFactory $resultPageFactory + */ + public function __construct( + Context $context, + Registry $registry, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + PageFactory $resultPageFactory + ) { + $this->resultPageFactory = $resultPageFactory; + parent::__construct($context, $registry, $resultForwardFactory); + } + /** * Invoice information page * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $invoice = $this->getInvoice(); if (!$invoice) { - $this->_forward('noroute'); - return; + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('noroute'); } - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::sales_order'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Invoices')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(sprintf("#%s", $invoice->getIncrementId())); - $this->_view->getLayout()->getBlock( + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_order'); + $resultPage->getConfig()->getTitle()->prepend(__('Invoices')); + $resultPage->getConfig()->getTitle()->prepend(sprintf("#%s", $invoice->getIncrementId())); + $resultPage->getLayout()->getBlock( 'sales_invoice_view' )->updateBackButtonUrl( $this->getRequest()->getParam('come_from') ); - $this->_view->renderLayout(); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php old mode 100644 new mode 100755 index 90524bb86ff09..18f2986b8ce09 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php @@ -7,20 +7,44 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; use Magento\Framework\Model\Exception; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Registry; class Void extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param Context $context + * @param Registry $registry + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + */ + public function __construct( + Context $context, + Registry $registry, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + ) { + $this->resultRedirectFactory = $resultRedirectFactory; + parent::__construct($context, $registry, $resultForwardFactory); + } + /** * Void invoice action * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $invoice = $this->getInvoice(); if (!$invoice) { - $this->_forward('noroute'); - return; + /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('noroute'); } try { $invoice->void(); @@ -38,6 +62,9 @@ public function execute() } catch (\Exception $e) { $this->messageManager->addError(__('Invoice voiding error')); } - $this->_redirect('sales/*/view', ['invoice_id' => $invoice->getId()]); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/view', ['invoice_id' => $invoice->getId()]); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoices.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoices.php index 43eeb45f5eb1e..08354deb66839 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoices.php @@ -1,23 +1,21 @@ _initOrder(); - $this->_view->loadLayout(false); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php index cd3d5fab3c231..14eface4372bd 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php @@ -1,18 +1,16 @@ messageManager->addSuccess(__('We canceled %1 order(s).', $countCancelOrder)); } - $this->_redirect('sales/*/'); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php index bc70c6335353b..6681bb10a83fc 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php @@ -1,18 +1,16 @@ messageManager->addSuccess(__('You have put %1 order(s) on hold.', $countHoldOrder)); } - $this->_redirect('sales/*/'); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassPrint.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassPrint.php index c39d801639c03..69e3e26dabdd3 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassPrint.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassPrint.php @@ -1,12 +1,10 @@ _redirect('sales/*/'); + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php index 9354d3ab4749f..1c0022b10dca2 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php @@ -1,6 +1,5 @@ getRequest()->getPost('order_ids'); + $resultRedirect = $this->resultRedirectFactory->create(); $flag = false; if (!empty($orderIds)) { foreach ($orderIds as $orderId) { - $creditmemos = $this->_objectManager->create( - 'Magento\Sales\Model\Resource\Order\Creditmemo\Collection' - )->setOrderFilter( - $orderId - )->load(); + $creditmemos = $this->_objectManager->create('Magento\Sales\Model\Resource\Order\Creditmemo\Collection') + ->setOrderFilter($orderId) + ->load(); if ($creditmemos->getSize()) { $flag = true; if (!isset($pdf)) { - $pdf = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Creditmemo' - )->getPdf( - $creditmemos - ); + $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo') + ->getPdf($creditmemos); } else { - $pages = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Creditmemo' - )->getPdf( - $creditmemos - ); + $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo') + ->getPdf($creditmemos); $pdf->pages = array_merge($pdf->pages, $pages->pages); } } } if ($flag) { + $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime') + ->date('Y-m-d_H-i-s'); return $this->_fileFactory->create( - 'creditmemo' . $this->_objectManager->get( - 'Magento\Framework\Stdlib\DateTime\DateTime' - )->date( - 'Y-m-d_H-i-s' - ) . '.pdf', + 'creditmemo' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf' ); } else { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php index 9fdebb897551a..498c72f47cdb5 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php @@ -1,6 +1,5 @@ getRequest()->getPost('order_ids'); + $resultRedirect = $this->resultRedirectFactory->create(); $flag = false; if (!empty($orderIds)) { foreach ($orderIds as $orderId) { - $invoices = $this->_objectManager->create( - 'Magento\Sales\Model\Resource\Order\Invoice\Collection' - )->setOrderFilter( - $orderId - )->load(); + $invoices = $this->_objectManager->create('Magento\Sales\Model\Resource\Order\Invoice\Collection') + ->setOrderFilter($orderId) + ->load(); if ($invoices->getSize()) { $flag = true; if (!isset($pdf)) { - $pdf = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Invoice' - )->getPdf( - $invoices - ); + $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice') + ->getPdf($invoices); } else { - $pages = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Invoice' - )->getPdf( - $invoices - ); + $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice') + ->getPdf($invoices); $pdf->pages = array_merge($pdf->pages, $pages->pages); } } - $shipments = $this->_objectManager->create( - 'Magento\Sales\Model\Resource\Order\Shipment\Collection' - )->setOrderFilter( - $orderId - )->load(); + $shipments = $this->_objectManager->create('Magento\Sales\Model\Resource\Order\Shipment\Collection') + ->setOrderFilter($orderId) + ->load(); if ($shipments->getSize()) { $flag = true; if (!isset($pdf)) { - $pdf = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Shipment' - )->getPdf( - $shipments - ); + $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment') + ->getPdf($shipments); } else { - $pages = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Shipment' - )->getPdf( - $shipments - ); + $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment') + ->getPdf($shipments); $pdf->pages = array_merge($pdf->pages, $pages->pages); } } - $creditmemos = $this->_objectManager->create( - 'Magento\Sales\Model\Resource\Order\Creditmemo\Collection' - )->setOrderFilter( - $orderId - )->load(); + $creditmemos = $this->_objectManager->create('Magento\Sales\Model\Resource\Order\Creditmemo\Collection') + ->setOrderFilter($orderId) + ->load(); if ($creditmemos->getSize()) { $flag = true; if (!isset($pdf)) { - $pdf = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Creditmemo' - )->getPdf( - $creditmemos - ); + $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo') + ->getPdf($creditmemos); } else { - $pages = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Creditmemo' - )->getPdf( - $creditmemos - ); + $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo') + ->getPdf($creditmemos); $pdf->pages = array_merge($pdf->pages, $pages->pages); } } } if ($flag) { + $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime') + ->date('Y-m-d_H-i-s'); return $this->_fileFactory->create( - 'docs' . $this->_objectManager->get( - 'Magento\Framework\Stdlib\DateTime\DateTime' - )->date( - 'Y-m-d_H-i-s' - ) . '.pdf', + 'docs' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf' ); } else { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php index 8d7c2a050988d..1f15336dc8c63 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php @@ -1,6 +1,5 @@ getRequest()->getPost('order_ids'); + $resultRedirect = $this->resultRedirectFactory->create(); $flag = false; if (!empty($orderIds)) { foreach ($orderIds as $orderId) { - $invoices = $this->_objectManager->create( - 'Magento\Sales\Model\Resource\Order\Invoice\Collection' - )->setOrderFilter( - $orderId - )->load(); + $invoices = $this->_objectManager->create('Magento\Sales\Model\Resource\Order\Invoice\Collection') + ->setOrderFilter($orderId) + ->load(); if ($invoices->getSize() > 0) { $flag = true; if (!isset($pdf)) { - $pdf = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Invoice' - )->getPdf( - $invoices - ); + $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice') + ->getPdf($invoices); } else { - $pages = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Invoice' - )->getPdf( - $invoices - ); + $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice') + ->getPdf($invoices); $pdf->pages = array_merge($pdf->pages, $pages->pages); } } } if ($flag) { + $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime') + ->date('Y-m-d_H-i-s'); return $this->_fileFactory->create( - 'invoice' . $this->_objectManager->get( - 'Magento\Framework\Stdlib\DateTime\DateTime' - )->date( - 'Y-m-d_H-i-s' - ) . '.pdf', + 'invoice' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf' ); } else { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php index 911afa93575be..32e548f416879 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php @@ -1,6 +1,5 @@ getRequest()->getPost('order_ids'); + $resultRedirect = $this->resultRedirectFactory->create(); $flag = false; if (!empty($orderIds)) { foreach ($orderIds as $orderId) { - $shipments = $this->_objectManager->create( - 'Magento\Sales\Model\Resource\Order\Shipment\Collection' - )->setOrderFilter( - $orderId - )->load(); + $shipments = $this->_objectManager->create('Magento\Sales\Model\Resource\Order\Shipment\Collection') + ->setOrderFilter($orderId) + ->load(); if ($shipments->getSize()) { $flag = true; if (!isset($pdf)) { - $pdf = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Shipment' - )->getPdf( - $shipments - ); + $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment') + ->getPdf($shipments); } else { - $pages = $this->_objectManager->create( - 'Magento\Sales\Model\Order\Pdf\Shipment' - )->getPdf( - $shipments - ); + $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment') + ->getPdf($shipments); $pdf->pages = array_merge($pdf->pages, $pages->pages); } } } if ($flag) { + $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime') + ->date('Y-m-d_H-i-s'); return $this->_fileFactory->create( - 'packingslip' . $this->_objectManager->get( - 'Magento\Framework\Stdlib\DateTime\DateTime' - )->date( - 'Y-m-d_H-i-s' - ) . '.pdf', + 'packingslip' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf' ); } else { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } - $this->_redirect('sales/*/'); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/ReviewPayment.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/ReviewPayment.php index de45a7111a98e..9800b6f1560df 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/ReviewPayment.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/ReviewPayment.php @@ -1,6 +1,5 @@ resultRedirectFactory->create(); try { $order = $this->_initOrder(); - if (!$order) { - return; + if ($order) { + $action = $this->getRequest()->getParam('action', ''); + switch ($action) { + case 'accept': + $order->getPayment()->accept(); + $message = __('The payment has been accepted.'); + break; + case 'deny': + $order->getPayment()->deny(); + $message = __('The payment has been denied.'); + break; + case 'update': + $order->getPayment()->registerPaymentReviewAction( + \Magento\Sales\Model\Order\Payment::REVIEW_ACTION_UPDATE, + true + ); + $message = __('The payment update has been made.'); + break; + default: + throw new \Exception(sprintf('Action "%s" is not supported.', $action)); + } + $order->save(); + $this->messageManager->addSuccess($message); } - $action = $this->getRequest()->getParam('action', ''); - switch ($action) { - case 'accept': - $order->getPayment()->accept(); - $message = __('The payment has been accepted.'); - break; - case 'deny': - $order->getPayment()->deny(); - $message = __('The payment has been denied.'); - break; - case 'update': - $order->getPayment()->registerPaymentReviewAction( - \Magento\Sales\Model\Order\Payment::REVIEW_ACTION_UPDATE, - true - ); - $message = __('The payment update has been made.'); - break; - default: - throw new \Exception(sprintf('Action "%s" is not supported.', $action)); - } - $order->save(); - $this->messageManager->addSuccess($message); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('We couldn\'t update the payment.')); $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); } - $this->_redirect('sales/order/view', ['order_id' => $order->getId()]); + $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Shipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Shipments.php index 1252b3be1124d..98683c7601790 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Shipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Shipments.php @@ -1,23 +1,21 @@ _initOrder(); - $this->_view->loadLayout(false); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status.php index 5540c0548351b..1fb0d8f3c6463 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status.php @@ -7,8 +7,6 @@ /** * Order status management controller - * - * @author Magento Core Team */ class Status extends \Magento\Backend\App\Action { @@ -23,8 +21,10 @@ class Status extends \Magento\Backend\App\Action * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry */ - public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry) - { + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Registry $coreRegistry + ) { $this->_coreRegistry = $coreRegistry; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Assign.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Assign.php index 1b354d3b3ede0..04e05fc348e1f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Assign.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Assign.php @@ -6,19 +6,44 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; +use Magento\Framework\Registry; +use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; + class Assign extends \Magento\Sales\Controller\Adminhtml\Order\Status { + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @param Context $context + * @param Registry $coreRegistry + * @param PageFactory $resultPageFactory + */ + public function __construct( + Context $context, + Registry $coreRegistry, + PageFactory $resultPageFactory + ) { + parent::__construct($context, $coreRegistry); + $this->resultPageFactory = $resultPageFactory; + } + /** * Assign status to state form * - * @return void + * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::system_order_statuses'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Order Status')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Assign Order Status to State')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::system_order_statuses'); + $resultPage->getConfig()->getTitle()->prepend(__('Order Status')); + $resultPage->getConfig()->getTitle()->prepend(__('Assign Order Status to State')); + + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php index c2d15b8e957f0..2c33340cfcd8e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php @@ -6,16 +6,41 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; +use Magento\Framework\Registry; +use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\RedirectFactory; + class AssignPost extends \Magento\Sales\Controller\Adminhtml\Order\Status { + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param Context $context + * @param Registry $coreRegistry + * @param RedirectFactory $resultRedirectFactory + */ + public function __construct( + Context $context, + Registry $coreRegistry, + RedirectFactory $resultRedirectFactory + ) { + parent::__construct($context, $coreRegistry); + $this->resultRedirectFactory = $resultRedirectFactory; + } + /** * Save status assignment to state * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $data = $this->getRequest()->getPost(); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { $state = $this->getRequest()->getParam('state'); $isDefault = $this->getRequest()->getParam('is_default'); @@ -25,8 +50,7 @@ public function execute() try { $status->assignState($state, $isDefault, $visibleOnFront); $this->messageManager->addSuccess(__('You have assigned the order status.')); - $this->_redirect('sales/*/'); - return; + return $resultRedirect->setPath('sales/*/'); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { @@ -38,9 +62,8 @@ public function execute() } else { $this->messageManager->addError(__('We can\'t find this order status.')); } - $this->_redirect('sales/*/assign'); - return; + return $resultRedirect->setPath('sales/*/assign'); } - $this->_redirect('sales/*/'); + return $resultRedirect->setPath('sales/*/'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Edit.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Edit.php index c03fdb2f99417..aa3f04ef236be 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Edit.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Edit.php @@ -6,26 +6,61 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; +use Magento\Framework\Registry; +use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; +use Magento\Backend\Model\View\Result\RedirectFactory; + class Edit extends \Magento\Sales\Controller\Adminhtml\Order\Status { + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param Context $context + * @param Registry $coreRegistry + * @param PageFactory $resultPageFactory + * @param RedirectFactory $resultRedirectFactory + */ + public function __construct( + Context $context, + Registry $coreRegistry, + PageFactory $resultPageFactory, + RedirectFactory $resultRedirectFactory + ) { + parent::__construct($context, $coreRegistry); + $this->resultPageFactory = $resultPageFactory; + $this->resultRedirectFactory = $resultRedirectFactory; + } + /** * Editing existing status form * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $status = $this->_initStatus(); if ($status) { $this->_coreRegistry->register('current_status', $status); - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::system_order_statuses'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Order Status')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Edit Order Status')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::system_order_statuses'); + $resultPage->getConfig()->getTitle()->prepend(__('Order Status')); + $resultPage->getConfig()->getTitle()->prepend(__('Edit Order Status')); + return $resultPage; } else { $this->messageManager->addError(__('We can\'t find this order status.')); - $this->_redirect('sales/'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('sales/'); } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Index.php index e8bcd0812a011..3bafba1937248 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Index.php @@ -6,18 +6,43 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; +use Magento\Framework\Registry; +use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; + class Index extends \Magento\Sales\Controller\Adminhtml\Order\Status { + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @param Context $context + * @param Registry $coreRegistry + * @param PageFactory $resultPageFactory + */ + public function __construct( + Context $context, + Registry $coreRegistry, + PageFactory $resultPageFactory + ) { + parent::__construct($context, $coreRegistry); + $this->resultPageFactory = $resultPageFactory; + } + /** * Statuses grid page * - * @return void + * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::system_order_statuses'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Order Status')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::system_order_statuses'); + $resultPage->getConfig()->getTitle()->prepend(__('Order Status')); + + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/NewAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/NewAction.php index a36ecdb239107..f9668e8325859 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/NewAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/NewAction.php @@ -6,12 +6,35 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; +use Magento\Framework\Registry; +use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; + class NewAction extends \Magento\Sales\Controller\Adminhtml\Order\Status { + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @param Context $context + * @param Registry $coreRegistry + * @param PageFactory $resultPageFactory + */ + public function __construct( + Context $context, + Registry $coreRegistry, + PageFactory $resultPageFactory + ) { + parent::__construct($context, $coreRegistry); + $this->resultPageFactory = $resultPageFactory; + } + /** * New status form * - * @return void + * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { @@ -20,10 +43,12 @@ public function execute() $status = $this->_objectManager->create('Magento\Sales\Model\Order\Status')->setData($data); $this->_coreRegistry->register('current_status', $status); } - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::system_order_statuses'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Order Status')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Create New Order Status')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::system_order_statuses'); + $resultPage->getConfig()->getTitle()->prepend(__('Order Status')); + $resultPage->getConfig()->getTitle()->prepend(__('Create New Order Status')); + + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php index 9737f983cac96..5e1fe3c8bf080 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php @@ -6,17 +6,42 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; +use Magento\Framework\Registry; +use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\RedirectFactory; + class Save extends \Magento\Sales\Controller\Adminhtml\Order\Status { + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param Context $context + * @param Registry $coreRegistry + * @param RedirectFactory $resultRedirectFactory + */ + public function __construct( + Context $context, + Registry $coreRegistry, + RedirectFactory $resultRedirectFactory + ) { + parent::__construct($context, $coreRegistry); + $this->resultRedirectFactory = $resultRedirectFactory; + } + /** * Save status form processing * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $data = $this->getRequest()->getPost(); $isNew = $this->getRequest()->getParam('is_new'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { $statusCode = $this->getRequest()->getParam('status'); @@ -36,8 +61,7 @@ public function execute() if ($isNew && $status->getStatus()) { $this->messageManager->addError(__('We found another order status with the same order status code.')); $this->_getSession()->setFormData($data); - $this->_redirect('sales/*/new'); - return; + return $resultRedirect->setPath('sales/*/new'); } $status->setData($data)->setStatus($statusCode); @@ -45,8 +69,7 @@ public function execute() try { $status->save(); $this->messageManager->addSuccess(__('You have saved the order status.')); - $this->_redirect('sales/*/'); - return; + return $resultRedirect->setPath('sales/*/'); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { @@ -57,12 +80,11 @@ public function execute() } $this->_getSession()->setFormData($data); if ($isNew) { - $this->_redirect('sales/*/new'); + return $resultRedirect->setPath('sales/*/new'); } else { - $this->_redirect('sales/*/edit', ['status' => $this->getRequest()->getParam('status')]); + return $resultRedirect->setPath('sales/*/edit', ['status' => $this->getRequest()->getParam('status')]); } - return; } - $this->_redirect('sales/*/'); + return $resultRedirect->setPath('sales/*/'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php index 144698616ec8d..852cda481c296 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php @@ -6,10 +6,33 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; +use Magento\Framework\Registry; +use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\RedirectFactory; + class Unassign extends \Magento\Sales\Controller\Adminhtml\Order\Status { /** - * @return void + * @var RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param Context $context + * @param Registry $coreRegistry + * @param RedirectFactory $resultRedirectFactory + */ + public function __construct( + Context $context, + Registry $coreRegistry, + RedirectFactory $resultRedirectFactory + ) { + parent::__construct($context, $coreRegistry); + $this->resultRedirectFactory = $resultRedirectFactory; + } + + /** + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { @@ -30,6 +53,8 @@ public function execute() } else { $this->messageManager->addError(__('We can\'t find this order status.')); } - $this->_redirect('sales/*/'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('sales/*/'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Transactions.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Transactions.php index ff474a82ce14d..f41824df84b5f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Transactions.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Transactions.php @@ -1,6 +1,5 @@ _initOrder(); - $this->_view->loadLayout(false); - $this->_view->renderLayout(); + $resultLayout = $this->resultLayoutFactory->create(); + return $resultLayout; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Unhold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Unhold.php index eafd3a41656e4..d5f262a80dc3f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Unhold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Unhold.php @@ -1,22 +1,21 @@ _initOrder(); + $resultRedirect = $this->resultRedirectFactory->create(); if ($order) { try { $order->unhold()->save(); @@ -26,7 +25,10 @@ public function execute() } catch (\Exception $e) { $this->messageManager->addError(__('The order was not on hold.')); } - $this->_redirect('sales/order/view', ['order_id' => $order->getId()]); + $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]); + return $resultRedirect; } + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php index 0aacc53ce7efa..c4535d45719a9 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php @@ -1,6 +1,5 @@ _initOrder(); + $resultRedirect = $this->resultRedirectFactory->create(); if ($order) { try { - $this->_initAction(); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Orders')); + $resultPage = $this->_initAction(); + $resultPage->getConfig()->getTitle()->prepend(__('Orders')); } catch (\Magento\Framework\App\Action\Exception $e) { $this->messageManager->addError($e->getMessage()); - $this->_redirect('sales/order/index'); - return; + $resultRedirect->setPath('sales/order/index'); + return $resultRedirect; } catch (\Exception $e) { $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); $this->messageManager->addError(__('Exception occurred during order load')); - $this->_redirect('sales/order/index'); - return; + $resultRedirect->setPath('sales/order/index'); + return $resultRedirect; } - $this->_view->getPage()->getConfig()->getTitle()->prepend(sprintf("#%s", $order->getRealOrderId())); - $this->_view->renderLayout(); + $resultPage->getConfig()->getTitle()->prepend(sprintf("#%s", $order->getRealOrderId())); + return $resultPage; } + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/VoidPayment.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/VoidPayment.php index ef59ce1280c56..50d467dec0d70 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/VoidPayment.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/VoidPayment.php @@ -1,34 +1,36 @@ _initOrder())) { - return; - } - try { - $order->getPayment()->void(new \Magento\Framework\Object()); // workaround for backwards compatibility - $order->save(); - $this->messageManager->addSuccess(__('The payment has been voided.')); - } catch (\Magento\Framework\Model\Exception $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addError(__('We couldn\'t void the payment.')); - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); + $order = $this->_initOrder(); + $resultRedirect = $this->resultRedirectFactory->create(); + if ($order) { + try { + $order->getPayment()->void(new \Magento\Framework\Object()); // workaround for backwards compatibility + $order->save(); + $this->messageManager->addSuccess(__('The payment has been voided.')); + } catch (\Magento\Framework\Model\Exception $e) { + $this->messageManager->addError($e->getMessage()); + } catch (\Exception $e) { + $this->messageManager->addError(__('We couldn\'t void the payment.')); + $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); + } + $resultRedirect->setPath('sales/*/view', ['order_id' => $order->getId()]); + return $resultRedirect; } - $this->_redirect('sales/*/view', ['order_id' => $order->getId()]); + $resultRedirect->setPath('sales/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Index.php index 4a5f6b04589a8..1a800be5b93a3 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Index.php @@ -6,45 +6,50 @@ */ namespace Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment; +use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; + abstract class Index extends \Magento\Backend\App\Action { /** - * @return bool + * @var PageFactory */ - protected function _isAllowed() - { - return $this->_authorization->isAllowed('Magento_Sales::shipment'); + protected $resultPageFactory; + + /** + * @param Context $context + * @param PageFactory $resultPageFactory + */ + public function __construct( + Context $context, + PageFactory $resultPageFactory + ) { + parent::__construct($context); + $this->resultPageFactory = $resultPageFactory; } /** - * Init layout, menu and breadcrumb - * - * @return $this + * @return bool */ - protected function _initAction() + protected function _isAllowed() { - $this->_view->loadLayout(); - $this->_setActiveMenu( - 'Magento_Sales::sales_shipment' - )->_addBreadcrumb( - __('Sales'), - __('Sales') - )->_addBreadcrumb( - __('Shipments'), - __('Shipments') - ); - return $this; + return $this->_authorization->isAllowed('Magento_Sales::shipment'); } /** * Shipments grid * - * @return void + * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { - $this->_initAction(); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_shipment') + ->addBreadcrumb(__('Sales'), __('Sales')) + ->addBreadcrumb(__('Shipments'), __('Shipments')); + $resultPage->getConfig()->getTitle()->prepend(__('Shipments')); + + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php index 0c8b88c0611d6..4378121ad0aa2 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php @@ -6,25 +6,36 @@ */ namespace Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment; +use Magento\Backend\App\Action\Context; use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Backend\Model\View\Result\RedirectFactory; abstract class Pdfshipments extends \Magento\Backend\App\Action { /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var FileFactory */ protected $_fileFactory; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @var RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param Context $context + * @param FileFactory $fileFactory + * @param RedirectFactory $resultRedirectFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + FileFactory $fileFactory, + RedirectFactory $resultRedirectFactory ) { $this->_fileFactory = $fileFactory; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } @@ -37,7 +48,7 @@ protected function _isAllowed() } /** - * @return ResponseInterface|void + * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect */ public function execute() { @@ -65,6 +76,8 @@ public function execute() 'application/pdf' ); } - $this->_redirect('sales/*/'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('sales/*/'); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/PrintAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/PrintAction.php index 6ab459e0918b0..633cf071b933b 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/PrintAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/PrintAction.php @@ -6,25 +6,36 @@ */ namespace Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment; +use Magento\Backend\App\Action\Context; use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Backend\Model\View\Result\ForwardFactory; abstract class PrintAction extends \Magento\Backend\App\Action { /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var FileFactory */ protected $_fileFactory; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @var ForwardFactory + */ + protected $resultForwardFactory; + + /** + * @param Context $context + * @param FileFactory $fileFactory + * @param ForwardFactory $resultForwardFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + FileFactory $fileFactory, + ForwardFactory $resultForwardFactory ) { $this->_fileFactory = $fileFactory; + $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } @@ -37,7 +48,7 @@ protected function _isAllowed() } /** - * @return ResponseInterface|void + * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward */ public function execute() { @@ -59,7 +70,9 @@ public function execute() ); } } else { - $this->_forward('noroute'); + /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('noroute'); } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/View.php index ba190ac2cbc50..150f98e597b10 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/View.php @@ -6,8 +6,28 @@ */ namespace Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment; +use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\ForwardFactory; + abstract class View extends \Magento\Backend\App\Action { + /** + * @var ForwardFactory + */ + protected $resultForwardFactory; + + /** + * @param Context $context + * @param ForwardFactory $resultForwardFactory + */ + public function __construct( + Context $context, + ForwardFactory $resultForwardFactory + ) { + parent::__construct($context); + $this->resultForwardFactory = $resultForwardFactory; + } + /** * @return bool */ @@ -19,15 +39,20 @@ protected function _isAllowed() /** * Shipment information page * - * @return void - * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @return \Magento\Backend\Model\View\Result\Forward */ public function execute() { - if ($shipmentId = $this->getRequest()->getParam('shipment_id')) { - $this->_forward('view', 'order_shipment', 'admin', ['come_from' => 'shipment']); + /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + if ($this->getRequest()->getParam('shipment_id')) { + $resultForward->setController('order_shipment') + ->setModule('admin') + ->setParams(['come_from' => 'shipment']) + ->forward('view'); + return $resultForward; } else { - $this->_forward('noroute'); + return $resultForward->forward('noroute'); } } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportCsv.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportCsv.php index 43a3f7f252f86..301d7fceacf20 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportCsv.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportCsv.php @@ -6,26 +6,37 @@ */ namespace Magento\Sales\Controller\Adminhtml\Shipment; +use Magento\Backend\App\Action\Context; use Magento\Framework\App\ResponseInterface; +use Magento\Framework\View\Result\LayoutFactory; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\Response\Http\FileFactory; class ExportCsv extends \Magento\Backend\App\Action { /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var FileFactory */ protected $_fileFactory; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @var LayoutFactory + */ + protected $resultLayoutFactory; + + /** + * @param Context $context + * @param FileFactory $fileFactory + * @param LayoutFactory $resultLayoutFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + FileFactory $fileFactory, + LayoutFactory $resultLayoutFactory ) { - $this->_fileFactory = $fileFactory; parent::__construct($context); + $this->_fileFactory = $fileFactory; + $this->resultLayoutFactory = $resultLayoutFactory; } /** @@ -43,9 +54,10 @@ protected function _isAllowed() */ public function execute() { - $this->_view->loadLayout(false); $fileName = 'shipments.csv'; - $grid = $this->_view->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export'); + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultLayoutFactory->create(); + $grid = $resultLayout->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export'); return $this->_fileFactory->create( $fileName, $grid->getCsvFile(), diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportExcel.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportExcel.php index 671e658a26c3d..45f47691e9856 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportExcel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportExcel.php @@ -6,25 +6,36 @@ */ namespace Magento\Sales\Controller\Adminhtml\Shipment; +use Magento\Backend\App\Action\Context; use Magento\Framework\App\ResponseInterface; +use Magento\Framework\View\Result\LayoutFactory; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\Response\Http\FileFactory; class ExportExcel extends \Magento\Backend\App\Action { /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var FileFactory */ protected $_fileFactory; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @var LayoutFactory + */ + protected $resultLayoutFactory; + + /** + * @param Context $context + * @param FileFactory $fileFactory + * @param LayoutFactory $resultLayoutFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + FileFactory $fileFactory, + LayoutFactory $resultLayoutFactory ) { $this->_fileFactory = $fileFactory; + $this->resultLayoutFactory = $resultLayoutFactory; parent::__construct($context); } @@ -43,9 +54,10 @@ protected function _isAllowed() */ public function execute() { - $this->_view->loadLayout(false); $fileName = 'shipments.xml'; - $grid = $this->_view->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export'); + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultLayoutFactory->create(); + $grid = $resultLayout->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export'); return $this->_fileFactory->create( $fileName, $grid->getExcelFile($fileName), diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Transactions.php b/app/code/Magento/Sales/Controller/Adminhtml/Transactions.php index ec41f879615e7..9c4d5ea276877 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Transactions.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Transactions.php @@ -6,6 +6,10 @@ namespace Magento\Sales\Controller\Adminhtml; use Magento\Backend\App\Action; +use Magento\Framework\Registry; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\View\Result\LayoutFactory; +use Magento\Backend\Model\View\Result\RedirectFactory; /** * Adminhtml sales transactions controller @@ -17,19 +21,43 @@ class Transactions extends \Magento\Backend\App\Action /** * Core registry * - * @var \Magento\Framework\Registry + * @var Registry */ protected $_coreRegistry = null; + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @var LayoutFactory + */ + protected $resultLayoutFactory; + + /** + * @var RedirectFactory + */ + protected $resultRedirectFactory; + /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\Registry $coreRegistry + * @param Registry $coreRegistry + * @param PageFactory $resultPageFactory + * @param LayoutFactory $resultLayoutFactory + * @param RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry + Registry $coreRegistry, + PageFactory $resultPageFactory, + LayoutFactory $resultLayoutFactory, + RedirectFactory $resultRedirectFactory ) { $this->_coreRegistry = $coreRegistry; + $this->resultPageFactory = $resultPageFactory; + $this->resultLayoutFactory = $resultLayoutFactory; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } @@ -48,7 +76,6 @@ protected function _initTransaction() if (!$txn->getId()) { $this->messageManager->addError(__('Please correct the transaction ID and try again.')); - $this->_redirect('sales/*/'); $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); return false; } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Fetch.php b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Fetch.php index 8dbf36b9590d9..3103376bcf6ad 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Fetch.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Fetch.php @@ -7,19 +7,22 @@ namespace Magento\Sales\Controller\Adminhtml\Transactions; use Magento\Backend\App\Action; +use Magento\Backend\Model\View\Result\Redirect; class Fetch extends \Magento\Sales\Controller\Adminhtml\Transactions { /** * Fetch transaction details action * - * @return void + * @return Redirect */ public function execute() { $txn = $this->_initTransaction(); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); if (!$txn) { - return; + return $resultRedirect->setPath('sales/*/'); } try { $txn->getOrderPaymentObject()->setOrder($txn->getOrder())->importTransactionInfo($txn); @@ -31,6 +34,6 @@ public function execute() $this->messageManager->addError(__('We can\'t update the transaction details.')); $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); } - $this->_redirect('sales/transactions/view', ['_current' => true]); + return $resultRedirect->setPath('sales/transactions/view', ['_current' => true]); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Grid.php b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Grid.php index cb5505094cd9d..0b4579d1810b9 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Grid.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Grid.php @@ -7,17 +7,17 @@ namespace Magento\Sales\Controller\Adminhtml\Transactions; use Magento\Backend\App\Action; +use Magento\Framework\View\Result\Layout; class Grid extends \Magento\Sales\Controller\Adminhtml\Transactions { /** * Ajax grid action * - * @return void + * @return Layout */ public function execute() { - $this->_view->loadLayout(false); - $this->_view->renderLayout(); + return $this->resultLayoutFactory->create(); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Index.php b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Index.php index 688f6d67ee7b1..6125b244d2991 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Index.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Index.php @@ -6,17 +6,20 @@ */ namespace Magento\Sales\Controller\Adminhtml\Transactions; +use Magento\Backend\Model\View\Result\Page; class Index extends \Magento\Sales\Controller\Adminhtml\Transactions { /** - * @return void + * @return Page */ public function execute() { - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::sales_transactions'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Transactions')); - $this->_view->renderLayout(); + /** @var Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_transactions'); + $resultPage->getConfig()->getTitle()->prepend(__('Transactions')); + + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/View.php index c04a2bf5efceb..867d700cb41ec 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/View.php @@ -7,24 +7,29 @@ namespace Magento\Sales\Controller\Adminhtml\Transactions; use Magento\Backend\App\Action; +use Magento\Backend\Model\View\Result\Page; class View extends \Magento\Sales\Controller\Adminhtml\Transactions { /** * View Transaction Details action * - * @return void + * @return Page */ public function execute() { $txn = $this->_initTransaction(); if (!$txn) { - return; + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('sales/*/'); } - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Sales::sales_transactions'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Transactions')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(sprintf("#%s", $txn->getTxnId())); - $this->_view->renderLayout(); + /** @var Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->setActiveMenu('Magento_Sales::sales_transactions'); + $resultPage->getConfig()->getTitle()->prepend(__('Transactions')); + $resultPage->getConfig()->getTitle()->prepend(sprintf("#%s", $txn->getTxnId())); + + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php index 84defe9173482..aa5e0541fc896 100644 --- a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php +++ b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php @@ -6,31 +6,61 @@ */ namespace Magento\Sales\Controller\Download; -use Magento\Catalog\Model\Product\Type\AbstractType\AbstractProductType; +use Magento\Sales\Model\Download; +use Magento\Backend\App\Action\Context; +use Magento\Catalog\Model\Product\Type\AbstractType; +use Magento\Backend\Model\View\Result\ForwardFactory; class DownloadCustomOption extends \Magento\Framework\App\Action\Action { + /** + * @var ForwardFactory + */ + protected $resultForwardFactory; + + /** + * @var Download + */ + protected $download; + + /** + * @param Context $context + * @param ForwardFactory $resultForwardFactory + * @param Download $download + */ + public function __construct( + Context $context, + ForwardFactory $resultForwardFactory, + Download $download + ) { + parent::__construct($context); + $this->resultForwardFactory = $resultForwardFactory; + $this->download = $download; + } + /** * Custom options download action * - * @return void + * @return void|\Magento\Framework\Controller\Result\Forward + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExitExpression) */ public function execute() { $quoteItemOptionId = $this->getRequest()->getParam('id'); - /** @var $option \Magento\Quote\Model\Quote\Item\Option */ - $option = $this->_objectManager->create('Magento\Quote\Model\Quote\Item\Option')->load($quoteItemOptionId); + /** @var $option \Magento\Sales\Model\Quote\Item\Option */ + $option = $this->_objectManager->create('Magento\Sales\Model\Quote\Item\Option')->load($quoteItemOptionId); + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); if (!$option->getId()) { - $this->_forward('noroute'); - return; + return $resultForward->forward('noroute'); } $optionId = null; - if (strpos($option->getCode(), AbstractProductType::OPTION_PREFIX) === 0) { - $optionId = str_replace(AbstractProductType::OPTION_PREFIX, '', $option->getCode()); + if (strpos($option->getCode(), AbstractType::OPTION_PREFIX) === 0) { + $optionId = str_replace(AbstractType::OPTION_PREFIX, '', $option->getCode()); if ((int)$optionId != $optionId) { $optionId = null; } @@ -45,19 +75,17 @@ public function execute() $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file' ) { - $this->_forward('noroute'); - return; + return $resultForward->forward('noroute'); } try { $info = unserialize($option->getValue()); if ($this->getRequest()->getParam('key') != $info['secret_key']) { - $this->_forward('noroute'); - return; + return $resultForward->forward('noroute'); } - $this->_download->downloadFile($info); + $this->download->downloadFile($info); } catch (\Exception $e) { - $this->_forward('noroute'); + return $resultForward->forward('noroute'); } exit(0); } diff --git a/app/code/Magento/Sales/Controller/Guest/Form.php b/app/code/Magento/Sales/Controller/Guest/Form.php index 59f041384eeaa..e2f90c18f31e7 100644 --- a/app/code/Magento/Sales/Controller/Guest/Form.php +++ b/app/code/Magento/Sales/Controller/Guest/Form.php @@ -8,20 +8,44 @@ class Form extends \Magento\Framework\App\Action\Action { + /** + * @var \Magento\Framework\View\Result\PageFactory + */ + protected $resultPageFactory; + + /** + * @var \Magento\Framework\Controller\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory + */ + public function __construct( + \Magento\Framework\App\Action\Context $context, + \Magento\Framework\View\Result\PageFactory $resultPageFactory, + \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory + ) { + parent::__construct($context); + $this->resultPageFactory = $resultPageFactory; + $this->resultRedirectFactory = $resultRedirectFactory; + } + /** * Order view form page * - * @return void + * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function execute() { if ($this->_objectManager->get('Magento\Customer\Model\Session')->isLoggedIn()) { - $this->_redirect('customer/account/'); - return; + return $this->resultRedirectFactory->create()->setPath('customer/account/'); } - $this->_view->loadLayout(); - $this->_view->getPage()->getConfig()->getTitle()->set(__('Orders and Returns')); - $this->_objectManager->get('Magento\Sales\Helper\Guest')->getBreadcrumbs(); - $this->_view->renderLayout(); + $resultPage = $this->resultPageFactory->create(); + $resultPage->getConfig()->getTitle()->set(__('Orders and Returns')); + $this->_objectManager->get('Magento\Sales\Helper\Guest')->getBreadcrumbs($resultPage); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Guest/OrderLoader.php b/app/code/Magento/Sales/Controller/Guest/OrderLoader.php index df4dcf4d56790..469b08c4b867e 100644 --- a/app/code/Magento/Sales/Controller/Guest/OrderLoader.php +++ b/app/code/Magento/Sales/Controller/Guest/OrderLoader.php @@ -7,7 +7,6 @@ namespace Magento\Sales\Controller\Guest; use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\ResponseInterface; use Magento\Sales\Controller\AbstractController\OrderLoaderInterface; class OrderLoader implements OrderLoaderInterface @@ -29,8 +28,8 @@ public function __construct( /** * {@inheritdoc} */ - public function load(RequestInterface $request, ResponseInterface $response) + public function load(RequestInterface $request) { - return $this->guestHelper->loadValidOrder($request, $response); + return $this->guestHelper->loadValidOrder($request); } } diff --git a/app/code/Magento/Sales/Controller/Guest/PrintAction.php b/app/code/Magento/Sales/Controller/Guest/PrintAction.php index 4588001b70e61..cf94ab2f5ffb9 100644 --- a/app/code/Magento/Sales/Controller/Guest/PrintAction.php +++ b/app/code/Magento/Sales/Controller/Guest/PrintAction.php @@ -6,16 +6,6 @@ */ namespace Magento\Sales\Controller\Guest; -use Magento\Framework\App\Action\Context; - class PrintAction extends \Magento\Sales\Controller\AbstractController\PrintAction { - /** - * @param Context $context - * @param OrderLoader $orderLoader - */ - public function __construct(Context $context, OrderLoader $orderLoader) - { - parent::__construct($context, $orderLoader); - } } diff --git a/app/code/Magento/Sales/Controller/Guest/PrintCreditmemo.php b/app/code/Magento/Sales/Controller/Guest/PrintCreditmemo.php index de95cda246ca0..5283ea8858e0d 100644 --- a/app/code/Magento/Sales/Controller/Guest/PrintCreditmemo.php +++ b/app/code/Magento/Sales/Controller/Guest/PrintCreditmemo.php @@ -6,7 +6,9 @@ */ namespace Magento\Sales\Controller\Guest; +use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; class PrintCreditmemo extends \Magento\Sales\Controller\AbstractController\PrintCreditmemo { @@ -19,25 +21,36 @@ class PrintCreditmemo extends \Magento\Sales\Controller\AbstractController\Print * @param Context $context * @param OrderViewAuthorization $orderAuthorization * @param \Magento\Framework\Registry $registry + * @param PageFactory $resultPageFactory + * @param RedirectFactory $resultRedirectFactory * @param OrderLoader $orderLoader */ public function __construct( Context $context, OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, + PageFactory $resultPageFactory, + RedirectFactory $resultRedirectFactory, OrderLoader $orderLoader ) { $this->orderLoader = $orderLoader; - parent::__construct($context, $orderAuthorization, $registry); + parent::__construct( + $context, + $orderAuthorization, + $registry, + $resultPageFactory, + $resultRedirectFactory + ); } /** - * {@inheritdoc} + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { - if (!$this->orderLoader->load($this->_request, $this->_response)) { - return; + $result = $this->orderLoader->load($this->_request); + if ($result instanceof \Magento\Framework\Controller\ResultInterface) { + return $result; } $creditmemoId = (int)$this->getRequest()->getParam('creditmemo_id'); @@ -52,10 +65,9 @@ public function execute() if (isset($creditmemo)) { $this->_coreRegistry->register('current_creditmemo', $creditmemo); } - $this->_view->loadLayout('print'); - $this->_view->renderLayout(); + return $this->resultPageFactory->create()->addHandle('print'); } else { - $this->_redirect('sales/guest/form'); + return $this->resultRedirectFactory->create()->setPath('sales/guest/form'); } } } diff --git a/app/code/Magento/Sales/Controller/Guest/PrintInvoice.php b/app/code/Magento/Sales/Controller/Guest/PrintInvoice.php index 9658f87e5736e..3999a1bf078bb 100644 --- a/app/code/Magento/Sales/Controller/Guest/PrintInvoice.php +++ b/app/code/Magento/Sales/Controller/Guest/PrintInvoice.php @@ -6,7 +6,9 @@ */ namespace Magento\Sales\Controller\Guest; +use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; class PrintInvoice extends \Magento\Sales\Controller\AbstractController\PrintInvoice { @@ -19,16 +21,26 @@ class PrintInvoice extends \Magento\Sales\Controller\AbstractController\PrintInv * @param Context $context * @param OrderViewAuthorization $orderAuthorization * @param \Magento\Framework\Registry $registry + * @param PageFactory $resultPageFactory + * @param RedirectFactory $resultRedirectFactory * @param OrderLoader $orderLoader */ public function __construct( Context $context, OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, + PageFactory $resultPageFactory, + RedirectFactory $resultRedirectFactory, OrderLoader $orderLoader ) { $this->orderLoader = $orderLoader; - parent::__construct($context, $orderAuthorization, $registry); + parent::__construct( + $context, + $orderAuthorization, + $registry, + $resultPageFactory, + $resultRedirectFactory + ); } /** @@ -36,8 +48,9 @@ public function __construct( */ public function execute() { - if (!$this->orderLoader->load($this->_request, $this->_response)) { - return; + $result = $this->orderLoader->load($this->_request); + if ($result instanceof \Magento\Framework\Controller\ResultInterface) { + return $result; } $invoiceId = (int)$this->getRequest()->getParam('invoice_id'); @@ -52,10 +65,9 @@ public function execute() if (isset($invoice)) { $this->_coreRegistry->register('current_invoice', $invoice); } - $this->_view->loadLayout('print'); - $this->_view->renderLayout(); + return $this->resultPageFactory->create()->addHandle('print'); } else { - $this->_redirect('sales/guest/form'); + return $this->resultRedirectFactory->create()->setPath('sales/guest/form'); } } } diff --git a/app/code/Magento/Sales/Controller/Guest/PrintShipment.php b/app/code/Magento/Sales/Controller/Guest/PrintShipment.php index 5abf66f5f300d..e3ae69ef3d992 100644 --- a/app/code/Magento/Sales/Controller/Guest/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/Guest/PrintShipment.php @@ -6,7 +6,9 @@ */ namespace Magento\Sales\Controller\Guest; +use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; class PrintShipment extends \Magento\Sales\Controller\AbstractController\PrintShipment { @@ -19,16 +21,26 @@ class PrintShipment extends \Magento\Sales\Controller\AbstractController\PrintSh * @param Context $context * @param OrderViewAuthorization $orderAuthorization * @param \Magento\Framework\Registry $registry + * @param PageFactory $resultPageFactory + * @param RedirectFactory $resultRedirectFactory * @param OrderLoader $orderLoader */ public function __construct( Context $context, OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, + PageFactory $resultPageFactory, + RedirectFactory $resultRedirectFactory, OrderLoader $orderLoader ) { $this->orderLoader = $orderLoader; - parent::__construct($context, $orderAuthorization, $registry); + parent::__construct( + $context, + $orderAuthorization, + $registry, + $resultPageFactory, + $resultRedirectFactory + ); } /** @@ -36,8 +48,9 @@ public function __construct( */ public function execute() { - if (!$this->orderLoader->load($this->_request, $this->_response)) { - return; + $result = $this->orderLoader->load($this->_request); + if ($result instanceof \Magento\Framework\Controller\ResultInterface) { + return $result; } $shipmentId = (int)$this->getRequest()->getParam('shipment_id'); @@ -51,10 +64,9 @@ public function execute() if (isset($shipment)) { $this->_coreRegistry->register('current_shipment', $shipment); } - $this->_view->loadLayout('print'); - $this->_view->renderLayout(); + return $this->resultPageFactory->create()->addHandle('print'); } else { - $this->_redirect('sales/guest/form'); + return $this->resultRedirectFactory->create()->setPath('sales/guest/form'); } } } diff --git a/app/code/Magento/Sales/Controller/Guest/Reorder.php b/app/code/Magento/Sales/Controller/Guest/Reorder.php index 24996aa76e8e3..745351dc652b4 100644 --- a/app/code/Magento/Sales/Controller/Guest/Reorder.php +++ b/app/code/Magento/Sales/Controller/Guest/Reorder.php @@ -6,20 +6,6 @@ */ namespace Magento\Sales\Controller\Guest; -use Magento\Framework\App\Action; - class Reorder extends \Magento\Sales\Controller\AbstractController\Reorder { - /** - * @param Action\Context $context - * @param OrderLoader $orderLoader - * @param \Magento\Framework\Registry $registry - */ - public function __construct( - Action\Context $context, - OrderLoader $orderLoader, - \Magento\Framework\Registry $registry - ) { - parent::__construct($context, $orderLoader, $registry); - } } diff --git a/app/code/Magento/Sales/Controller/Guest/View.php b/app/code/Magento/Sales/Controller/Guest/View.php index eb0796535abe2..e2185e0b269cb 100644 --- a/app/code/Magento/Sales/Controller/Guest/View.php +++ b/app/code/Magento/Sales/Controller/Guest/View.php @@ -10,26 +10,18 @@ class View extends \Magento\Sales\Controller\AbstractController\View { - /** - * @param Action\Context $context - * @param OrderLoader $orderLoader - */ - public function __construct(Action\Context $context, OrderLoader $orderLoader) - { - parent::__construct($context, $orderLoader); - } - /** * {@inheritdoc} */ public function execute() { - if (!$this->orderLoader->load($this->_request, $this->_response)) { - return; + $result = $this->orderLoader->load($this->_request); + if ($result instanceof \Magento\Framework\Controller\ResultInterface) { + return $result; } - $this->_view->loadLayout(); - $this->_objectManager->get('Magento\Sales\Helper\Guest')->getBreadcrumbs(); - $this->_view->renderLayout(); + $resultPage = $this->resultPageFactory->create(); + $this->_objectManager->get('Magento\Sales\Helper\Guest')->getBreadcrumbs($resultPage); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Controller/Order/History.php b/app/code/Magento/Sales/Controller/Order/History.php index 6abf8720ed086..d93a7b3b1fc0e 100644 --- a/app/code/Magento/Sales/Controller/Order/History.php +++ b/app/code/Magento/Sales/Controller/Order/History.php @@ -7,25 +7,44 @@ namespace Magento\Sales\Controller\Order; use Magento\Sales\Controller\OrderInterface; +use Magento\Framework\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; class History extends \Magento\Framework\App\Action\Action implements OrderInterface { + /** + * @var PageFactory + */ + protected $resultPageFactory; + + /** + * @param Context $context + * @param PageFactory $resultPageFactory + */ + public function __construct( + Context $context, + PageFactory $resultPageFactory + ) { + $this->resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + /** * Customer order history * - * @return void + * @return \Magento\Framework\View\Result\Page */ public function execute() { - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); - - $this->_view->getPage()->getConfig()->getTitle()->set(__('My Orders')); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $resultPage->getLayout()->initMessages(); + $resultPage->getConfig()->getTitle()->set(__('My Orders')); - $block = $this->_view->getLayout()->getBlock('customer.account.link.back'); + $block = $resultPage->getLayout()->getBlock('customer.account.link.back'); if ($block) { $block->setRefererUrl($this->_redirect->getRefererUrl()); } - $this->_view->renderLayout(); + return $resultPage; } } diff --git a/app/code/Magento/Sales/Helper/Guest.php b/app/code/Magento/Sales/Helper/Guest.php index 5ba1261f9a005..48424133a1981 100644 --- a/app/code/Magento/Sales/Helper/Guest.php +++ b/app/code/Magento/Sales/Helper/Guest.php @@ -46,6 +46,11 @@ class Guest extends \Magento\Core\Helper\Data */ protected $orderFactory; + /** + * @var \Magento\Framework\Controller\Result\RedirectFactory + */ + protected $resultRedirectFactory; + /** * Cookie key for guest view */ @@ -73,7 +78,7 @@ class Guest extends \Magento\Core\Helper\Data * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory * @param \Magento\Framework\Message\ManagerInterface $messageManager * @param \Magento\Sales\Model\OrderFactory $orderFactory - * @param \Magento\Framework\App\ViewInterface $view + * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param bool $dbCompatibleMode * * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -90,7 +95,7 @@ public function __construct( \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Sales\Model\OrderFactory $orderFactory, - \Magento\Framework\App\ViewInterface $view, + \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, $dbCompatibleMode = true ) { $this->coreRegistry = $coreRegistry; @@ -99,7 +104,7 @@ public function __construct( $this->cookieMetadataFactory = $cookieMetadataFactory; $this->messageManager = $messageManager; $this->orderFactory = $orderFactory; - $this->_view = $view; + $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct( $context, $scopeConfig, @@ -114,17 +119,15 @@ public function __construct( * Try to load valid order by $_POST or $_COOKIE * * @param App\RequestInterface $request - * @param App\ResponseInterface $response - * @return bool + * @return \Magento\Framework\Controller\Result\Redirect|bool * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function loadValidOrder(App\RequestInterface $request, App\ResponseInterface $response) + public function loadValidOrder(App\RequestInterface $request) { if ($this->customerSession->isLoggedIn()) { - $response->setRedirect($this->_urlBuilder->getUrl('sales/order/history')); - return false; + return $this->resultRedirectFactory->create()->setPath('sales/order/history'); } $post = $request->getPost(); @@ -135,8 +138,7 @@ public function loadValidOrder(App\RequestInterface $request, App\ResponseInterf $fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME); if (empty($post) && !$fromCookie) { - $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form')); - return false; + return $this->resultRedirectFactory->create()->setPath('sales/guest/form'); } elseif (!empty($post) && isset($post['oar_order_id']) && isset($post['oar_type'])) { $type = $post['oar_type']; $incrementId = $post['oar_order_id']; @@ -193,18 +195,18 @@ public function loadValidOrder(App\RequestInterface $request, App\ResponseInterf } $this->messageManager->addError(__('You entered incorrect data. Please try again.')); - $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form')); - return false; + return $this->resultRedirectFactory->create()->setPath('sales/guest/form'); } /** * Get Breadcrumbs for current controller action * + * @param \Magento\Framework\View\Result\Page $resultPage * @return void */ - public function getBreadcrumbs() + public function getBreadcrumbs(\Magento\Framework\View\Result\Page $resultPage) { - $breadcrumbs = $this->_view->getLayout()->getBlock('breadcrumbs'); + $breadcrumbs = $resultPage->getLayout()->getBlock('breadcrumbs'); $breadcrumbs->addCrumb( 'home', [ diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt index a8c9b77df27fc..6261135f9816c 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt @@ -56,6 +56,7 @@ Magento/Core/Model/Store Magento/Store/Model Magento/Cron/Model/Config/Backend/Product Magento/Customer/Block/Account/Dashboard +Magento/Customer/Controller/Adminhtml/Index Magento/Customer/Model/Config/Backend/Show Magento/Customer/Model/Metadata Magento/Customer/Model/Resource/Customer diff --git a/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/ConfirmTest.php b/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/ConfirmTest.php index bd6a6616f385a..4d23754e8f950 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/ConfirmTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/ConfirmTest.php @@ -14,6 +14,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class ConfirmTest extends \PHPUnit_Framework_TestCase { @@ -92,6 +93,11 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase */ protected $contextMock; + /** + * @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $redirectResultMock; + protected function setUp() { $this->customerSessionMock = $this->getMock('\Magento\Customer\Model\Session', [], [], '', false); @@ -121,6 +127,18 @@ protected function setUp() $this->addressHelperMock = $this->getMock('Magento\Customer\Helper\Address', [], [], '', false); $this->storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); $this->storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false); + $this->redirectResultMock = $this->getMock('Magento\Framework\Controller\Result\Redirect', [], [], '', false); + + $redirectFactoryMock = $this->getMock( + 'Magento\Framework\Controller\Result\RedirectFactory', + ['create'], + [], + '', + false + ); + $redirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->redirectResultMock); $this->scopeConfigMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface'); $this->contextMock = $this->getMock('Magento\Framework\App\Action\Context', [], [], '', false); @@ -140,15 +158,21 @@ protected function setUp() ->method('getMessageManager') ->will($this->returnValue($this->messageManagerMock)); - $this->model = new \Magento\Customer\Controller\Account\Confirm( - $this->contextMock, - $this->customerSessionMock, - $this->scopeConfigMock, - $this->storeManagerMock, - $this->customerAccountManagementMock, - $this->customerRepositoryMock, - $this->addressHelperMock, - $urlFactoryMock + $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + + $this->model = $objectManagerHelper->getObject( + 'Magento\Customer\Controller\Account\Confirm', + [ + 'context' => $this->contextMock, + 'customerSession' => $this->customerSessionMock, + 'scopeConfig' => $this->scopeConfigMock, + 'storeManager' => $this->storeManagerMock, + 'customerAccountManagement' => $this->customerAccountManagementMock, + 'customerRepository' => $this->customerRepositoryMock, + 'addressHelper' => $this->addressHelperMock, + 'urlFactory' => $urlFactoryMock, + 'resultRedirectFactory' => $redirectFactoryMock + ] ); } @@ -158,12 +182,12 @@ public function testIsLoggedIn() ->method('isLoggedIn') ->will($this->returnValue(true)); - $this->redirectMock->expects($this->once()) - ->method('redirect') - ->with($this->responseMock, '*/*/', []) - ->will($this->returnValue(false)); + $this->redirectResultMock->expects($this->once()) + ->method('setPath') + ->with('*/*/') + ->willReturnSelf(); - $this->model->execute(); + $this->assertInstanceOf('Magento\Framework\Controller\Result\Redirect', $this->model->execute()); } /** @@ -200,12 +224,12 @@ public function testNoCustomerIdInRequest($customerId, $key) ->with($this->equalTo($testUrl)) ->will($this->returnValue($testUrl)); - $this->responseMock->expects($this->once()) - ->method('setRedirect') + $this->redirectResultMock->expects($this->once()) + ->method('setUrl') ->with($this->equalTo($testUrl)) - ->will($this->returnSelf()); + ->willReturnSelf(); - $this->model->execute(); + $this->assertInstanceOf('Magento\Framework\Controller\Result\Redirect', $this->model->execute()); } /** @@ -259,12 +283,12 @@ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $ad $this->customerSessionMock->expects($this->any()) ->method('setCustomerDataAsLoggedIn') ->with($this->equalTo($this->customerDataMock)) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->messageManagerMock->expects($this->any()) ->method('addSuccess') ->with($this->stringContains($successMessage)) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->addressHelperMock->expects($this->once()) ->method('isVatValidationEnabled') @@ -345,12 +369,12 @@ public function testSuccessRedirect( $this->customerSessionMock->expects($this->any()) ->method('setCustomerDataAsLoggedIn') ->with($this->equalTo($this->customerDataMock)) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->messageManagerMock->expects($this->any()) ->method('addSuccess') ->with($this->stringContains($successMessage)) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->storeMock->expects($this->any()) ->method('getFrontendName') diff --git a/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/CreateTest.php b/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/CreateTest.php index 202d2a4319c55..af1bfd2b7787f 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/CreateTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/CreateTest.php @@ -37,9 +37,24 @@ class CreateTest extends \PHPUnit_Framework_TestCase protected $response; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Controller\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $redirectFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $redirectResultMock; + + /** + * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultPageMock; + + /** + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $viewMock; + protected $pageFactoryMock; protected function setUp() { @@ -55,15 +70,28 @@ protected function setUp() '', false ); - $this->viewMock = $this->getMock('Magento\Framework\App\ViewInterface'); + $this->redirectResultMock = $this->getMock('Magento\Framework\Controller\Result\Redirect', [], [], '', false); + + $this->redirectFactoryMock = $this->getMock( + 'Magento\Framework\Controller\Result\RedirectFactory', + ['create'], + [], + '', + false + ); + + $this->resultPageMock = $this->getMock('Magento\Framework\View\Result\Page', [], [], '', false ); + $this->pageFactoryMock = $this->getMock('Magento\Framework\View\Result\PageFactory', [], [], '', false); + $this->object = $objectManager->getObject('Magento\Customer\Controller\Account\Create', [ - 'view' => $this->viewMock, 'request' => $this->request, 'response' => $this->response, 'customerSession' => $this->customerSession, 'registration' => $this->registrationMock, 'redirect' => $this->redirectMock, + 'resultRedirectFactory' => $this->redirectFactoryMock, + 'resultPageFactory' => $this->pageFactoryMock ] ); } @@ -81,17 +109,17 @@ public function testCreateActionRegistrationDisabled() ->method('isAllowed') ->will($this->returnValue(false)); - $this->redirectMock->expects($this->once()) - ->method('redirect') - ->with($this->response, '*/*', []) - ->will($this->returnValue(false)); + $this->redirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->redirectResultMock); - $this->viewMock->expects($this->never()) - ->method('loadLayout'); - $this->viewMock->expects($this->never()) + $this->redirectResultMock->expects($this->once()) + ->method('setPath') + ->with('*/*') + ->willReturnSelf(); + + $this->resultPageMock->expects($this->never()) ->method('getLayout'); - $this->viewMock->expects($this->never()) - ->method('renderLayout'); $this->object->execute(); } @@ -121,17 +149,15 @@ public function testCreateActionRegistrationEnabled() ); $layoutMock->expects($this->once()) ->method('initMessages') - ->will($this->returnSelf()); + ->willReturnSelf(); + + $this->pageFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultPageMock); - $this->viewMock->expects($this->once()) - ->method('loadLayout') - ->will($this->returnSelf()); - $this->viewMock->expects($this->once()) + $this->resultPageMock->expects($this->once()) ->method('getLayout') ->will($this->returnValue($layoutMock)); - $this->viewMock->expects($this->once()) - ->method('renderLayout') - ->will($this->returnSelf()); $this->object->execute(); } diff --git a/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/LoginPostTest.php b/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/LoginPostTest.php index 7ee84e017a61a..c04e6c13fa7bb 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/LoginPostTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Controller/Account/LoginPostTest.php @@ -66,6 +66,16 @@ class LoginPostTest extends \PHPUnit_Framework_TestCase */ protected $customerAccountManagementMock; + /** + * @var \Magento\Framework\Controller\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $redirectFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $redirectResultMock; + /** * List of actions that are allowed for not authorized users * @@ -148,6 +158,15 @@ protected function setUp() $this->customerAccountManagementMock = $this->getMockForAbstractClass('Magento\Customer\Api\AccountManagementInterface'); + $this->redirectResultMock = $this->getMock('Magento\Framework\Controller\Result\Redirect', [], [], '', false); + + $this->redirectFactoryMock = $this->getMock( + 'Magento\Framework\Controller\Result\RedirectFactory', + ['create'], + [], + '', + false + ); $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->object = $objectManager->getObject( 'Magento\Customer\Controller\Account\LoginPost', @@ -162,6 +181,7 @@ protected function setUp() 'redirect' => $this->redirectMock, 'view' => $this->viewMock, 'customerAccountManagement' => $this->customerAccountManagementMock, + 'resultRedirectFactory' => $this->redirectFactoryMock, ] ); } @@ -215,6 +235,14 @@ public function testLoginPostActionWhenRefererSetBeforeAuthUrl() ); $this->url->expects($this->once())->method('isOwnOriginUrl')->with(); + $this->redirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->redirectResultMock); + + $this->redirectResultMock->expects($this->once()) + ->method('setUrl') + ->willReturnSelf(); + $this->object->execute(); } } diff --git a/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/IndexTest.php b/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/IndexTest.php index b8e0af6209feb..10fcf8d538486 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/IndexTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/IndexTest.php @@ -6,199 +6,185 @@ namespace Magento\Customer\Controller\Adminhtml\Index; /** - * Class IndexTest + * @covers \Magento\Customer\Controller\Adminhtml\Index\Index */ class IndexTest extends \PHPUnit_Framework_TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $requestMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $responseMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $sessionMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Customer\Controller\Adminhtml\Index\Index */ - protected $actionFlagMock; + protected $indexController; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\App\Action\Context */ - protected $contextMock; + protected $context; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $titleMock; + protected $requestMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $layoutInterfaceMock; + protected $resultForwardFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject */ - protected $breadcrumbsBlockMock; + protected $resultForwardMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $menuBlockMock; + protected $resultPageFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */ - protected $viewInterfaceMock; + protected $resultPageMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject */ - protected $resultPageMock; + protected $pageConfigMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject */ - protected $pageConfigMock; + protected $pageTitleMock; /** - * @var \Magento\Customer\Controller\Adminhtml\Index\Index + * @var \Magento\Backend\Model\Session|\PHPUnit_Framework_MockObject_MockObject */ - protected $controller; + protected $sessionMock; protected function setUp() { - $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') + $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') ->disableOriginalConstructor() + ->setMethods( + [ + 'getQuery', + 'getModuleName', + 'setModuleName', + 'getActionName', + 'setActionName', + 'getParam', + 'getCookie' + ] + ) ->getMock(); - $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http') - ->disableOriginalConstructor() - ->setMethods(['setRedirect', 'getHeader', '__wakeup']) - ->getMock(); - $this->sessionMock = $this->getMockBuilder('Magento\Backend\Model\Session') + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') ->disableOriginalConstructor() - ->setMethods(['unsCustomerData', '__wakeup', 'setIsUrlNotice']) + ->setMethods(['create']) ->getMock(); - $this->actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag') + $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') ->disableOriginalConstructor() ->getMock(); - $this->titleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title') + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') ->disableOriginalConstructor() ->getMock(); $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') ->disableOriginalConstructor() + ->setMethods(['setActiveMenu', 'getConfig', 'addBreadcrumb']) ->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') ->disableOriginalConstructor() ->getMock(); - - $this->breadcrumbsBlockMock = $this->getMockBuilder('Magento\Backend\Block\Widget\Breadcrumbs') - ->disableOriginalConstructor() - ->getMock(); - - $this->menuBlockMock = $this->getMockBuilder('Magento\Backend\Block\Menu') + $this->pageTitleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title') ->disableOriginalConstructor() - ->setMethods(['getMenuModel', 'getParentItems']) ->getMock(); - $this->menuBlockMock->expects($this->any()) - ->method('getMenuModel') - ->willReturnSelf(); - $this->menuBlockMock->expects($this->any()) - ->method('getParentItems') - ->willReturn([]); - - $this->layoutInterfaceMock = $this->getMockBuilder('Magento\Framework\View\LayoutInterface') - ->disableOriginalConstructor() - ->getMock(); - - $this->viewInterfaceMock = $this->getMockBuilder('Magento\Framework\App\ViewInterface') - ->disableOriginalConstructor() - ->getMock(); - - $this->viewInterfaceMock->expects($this->any())->method('getPage')->will( - $this->returnValue($this->resultPageMock) - ); - $this->resultPageMock->expects($this->any())->method('getConfig')->will( - $this->returnValue($this->pageConfigMock) - ); - - $this->pageConfigMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->titleMock)); - - $this->contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') + $this->sessionMock = $this->getMockBuilder('Magento\Backend\Model\Session') ->disableOriginalConstructor() + ->setMethods(['unsCustomerData']) ->getMock(); - $this->contextMock->expects($this->any()) - ->method('getRequest') - ->willReturn($this->requestMock); - $this->contextMock->expects($this->any()) - ->method('getResponse') - ->willReturn($this->responseMock); - $this->contextMock->expects($this->any()) - ->method('getSession') - ->willReturn($this->sessionMock); - $this->contextMock->expects($this->any()) - ->method('getActionFlag') - ->willReturn($this->actionFlagMock); - $this->contextMock->expects($this->any()) - ->method('getTitle') - ->willReturn($this->titleMock); - $this->contextMock->expects($this->any()) - ->method('getView') - ->willReturn($this->viewInterfaceMock); $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); - $this->controller = $objectManager->getObject( + $this->context = $objectManager->getObject( + 'Magento\Backend\App\Action\Context', + [ + 'request' => $this->requestMock, + 'session' => $this->sessionMock + ] + ); + $this->indexController = $objectManager->getObject( 'Magento\Customer\Controller\Adminhtml\Index\Index', [ - 'context' => $this->contextMock, + 'context' => $this->context, + 'resultForwardFactory' => $this->resultForwardFactoryMock, + 'resultPageFactory' => $this->resultPageFactoryMock ] ); } - public function testExecuteAjax() + /** + * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute + */ + public function testExecute() { - $this->requestMock->expects($this->once()) - ->method('getQuery') - ->with('ajax') - ->willReturn(true); - $this->assertNull($this->controller->execute()); + $this->prepareExecute(); + + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultPageMock); + $this->resultPageMock->expects($this->once()) + ->method('setActiveMenu') + ->with('Magento_Customer::customer_manage'); + $this->resultPageMock->expects($this->once()) + ->method('getConfig') + ->willReturn($this->pageConfigMock); + $this->pageConfigMock->expects($this->once()) + ->method('getTitle') + ->willReturn($this->pageTitleMock); + $this->pageTitleMock->expects($this->once()) + ->method('prepend') + ->with('Customers'); + $this->resultPageMock->expects($this->atLeastOnce()) + ->method('addBreadcrumb') + ->withConsecutive( + ['Customers', 'Customers'], + ['Manage Customers', 'Manage Customers'] + ); + $this->sessionMock->expects($this->once()) + ->method('unsCustomerData'); + + $this->assertInstanceOf( + 'Magento\Framework\View\Result\Page', + $this->indexController->execute() + ); } - public function testExecute() + /** + * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute + */ + public function testExecuteAjax() { - $this->titleMock->expects($this->once())->method('prepend')->with(__('Customers')); - $this->viewInterfaceMock->expects($this->any())->method('getLayout')->will( - $this->returnValue($this->layoutInterfaceMock) + $this->prepareExecute(true); + + $this->resultForwardFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultForwardMock); + $this->resultForwardMock->expects($this->once()) + ->method('forward') + ->with('grid') + ->willReturnSelf(); + + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Forward', + $this->indexController->execute() ); - $this->layoutInterfaceMock->expects($this->at(0)) - ->method('getBlock') - ->with('menu') - ->willReturn($this->menuBlockMock); - - $this->layoutInterfaceMock->expects($this->at(1)) - ->method('getBlock') - ->with('breadcrumbs') - ->willReturn($this->breadcrumbsBlockMock); - $this->layoutInterfaceMock->expects($this->at(2)) - ->method('getBlock') - ->with('breadcrumbs') - ->willReturn($this->breadcrumbsBlockMock); + } + /** + * @param bool $ajax + */ + protected function prepareExecute($ajax = false) + { $this->requestMock->expects($this->once()) ->method('getQuery') ->with('ajax') - ->willReturn(false); - $this->sessionMock->expects($this->once()) - ->method('unsCustomerData'); - $this->assertNull($this->controller->execute()); + ->willReturn($ajax); } } diff --git a/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/NewsletterTest.php b/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/NewsletterTest.php index 16ae2157cc75b..fa2576f50cf26 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/NewsletterTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/NewsletterTest.php @@ -63,9 +63,9 @@ class NewsletterTest extends \PHPUnit_Framework_TestCase protected $messageManager; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\View\Result\Layout|\PHPUnit_Framework_MockObject_MockObject */ - protected $resultPageMock; + protected $resultLayoutMock; /** * @var \PHPUnit_Framework_MockObject_MockObject @@ -87,6 +87,11 @@ class NewsletterTest extends \PHPUnit_Framework_TestCase */ protected $viewInterfaceMock; + /** + * @var \Magento\Framework\View\Result\LayoutFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultLayoutFactoryMock; + /** * Prepare required values * @@ -203,7 +208,7 @@ protected function setUp() $this->viewInterfaceMock->expects($this->any())->method('loadLayout')->will($this->returnSelf()); $contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewInterfaceMock)); - $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') + $this->resultLayoutMock = $this->getMockBuilder('Magento\Framework\View\Result\Layout') ->disableOriginalConstructor() ->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') @@ -212,17 +217,15 @@ protected function setUp() $this->customerAccountManagement = $this->getMockBuilder( 'Magento\Customer\Api\AccountManagementInterface' )->getMock(); + $this->resultLayoutFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\LayoutFactory') + ->disableOriginalConstructor() + ->getMock(); - $args = ['context' => $contextMock, 'customerAccountManagement' => $this->customerAccountManagement]; - - $this->viewInterfaceMock->expects($this->any())->method('getPage')->will( - $this->returnValue($this->resultPageMock) - ); - $this->resultPageMock->expects($this->any())->method('getConfig')->will( - $this->returnValue($this->pageConfigMock) - ); - - $this->pageConfigMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->titleMock)); + $args = [ + 'context' => $contextMock, + 'customerAccountManagement' => $this->customerAccountManagement, + 'resultLayoutFactory' => $this->resultLayoutFactoryMock + ]; $helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_testedObject = $helperObjectManager->getObject( @@ -240,16 +243,20 @@ public function testNewsletterAction() '', false ); - $this->titleMock->expects($this->once())->method('prepend')->with(__('Customers')); - $this->viewInterfaceMock->expects($this->any())->method('getLayout')->will( - $this->returnValue($this->layoutInterfaceMock) - ); - $subscriberMock->expects($this->once())->method('loadByCustomerId'); + $this->resultLayoutFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultLayoutMock); + $subscriberMock->expects($this->once()) + ->method('loadByCustomerId'); $this->_objectManager ->expects($this->at(1)) ->method('create') ->with('Magento\Newsletter\Model\Subscriber') ->will($this->returnValue($subscriberMock)); - $this->_testedObject->execute(); + + $this->assertInstanceOf( + 'Magento\Framework\View\Result\Layout', + $this->_testedObject->execute() + ); } } diff --git a/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php b/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php index 7dd5138256e04..55709ef5a02fc 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/ResetPasswordTest.php @@ -74,6 +74,16 @@ class ResetPasswordTest extends \PHPUnit_Framework_TestCase */ protected $messageManager; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectMock; + /** * Prepare required values * @@ -134,6 +144,18 @@ protected function setUp() ['addSuccess', 'addMessage', 'addException'] )->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $contextArgs = [ 'getHelper', 'getSession', @@ -200,6 +222,7 @@ protected function setUp() 'context' => $contextMock, 'customerAccountManagement' => $this->_customerAccountManagementMock, 'customerRepository' => $this->_customerRepositoryMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock ]; $helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this); @@ -211,7 +234,7 @@ protected function setUp() public function testResetPasswordActionNoCustomer() { - $redirectLink = 'http://example.com/customer/'; + $redirectLink = 'customer/index'; $this->_request->expects( $this->once() )->method( @@ -223,24 +246,19 @@ public function testResetPasswordActionNoCustomer() $this->returnValue(false) ); - $this->_helper->expects( - $this->once() - )->method( - 'getUrl' - )->with( - $this->equalTo('customer/index'), - $this->equalTo([]) - )->will( - $this->returnValue($redirectLink) - ); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with($this->equalTo($redirectLink)); - $this->_response->expects($this->once())->method('setRedirect')->with($this->equalTo($redirectLink)); - $this->_testedObject->execute(); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->_testedObject->execute() + ); } public function testResetPasswordActionInvalidCustomerId() { - $redirectLink = 'http://example.com/customer/'; + $redirectLink = 'customer/index'; $customerId = 1; $this->_request->expects( @@ -261,7 +279,8 @@ public function testResetPasswordActionInvalidCustomerId() )->with( $customerId )->will( - $this->throwException(new NoSuchEntityException( + $this->throwException( + new NoSuchEntityException( NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'customerId', 'fieldValue' => $customerId] ) @@ -279,8 +298,14 @@ public function testResetPasswordActionInvalidCustomerId() $this->returnValue($redirectLink) ); - $this->_response->expects($this->once())->method('setRedirect')->with($this->equalTo($redirectLink)); - $this->_testedObject->execute(); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with($this->equalTo($redirectLink)); + + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->_testedObject->execute() + ); } public function testResetPasswordActionCoreException() @@ -408,7 +433,7 @@ public function testResetPasswordActionSendEmail() $customerId = 1; $email = 'test@example.com'; $websiteId = 1; - $redirectLink = 'http://example.com'; + $redirectLink = 'customer/*/edit'; $this->_request->expects( $this->once() @@ -471,8 +496,16 @@ public function testResetPasswordActionSendEmail() $this->returnValue($redirectLink) ); - $this->_response->expects($this->once())->method('setRedirect')->with($this->equalTo($redirectLink)); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with( + $redirectLink, + ['id' => $customerId, '_current' => true] + ); - $this->_testedObject->execute(); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->_testedObject->execute() + ); } } diff --git a/dev/tests/unit/testsuite/Magento/Customer/Controller/Ajax/LoginTest.php b/dev/tests/unit/testsuite/Magento/Customer/Controller/Ajax/LoginTest.php index fcbe8fe3c6b2f..0d8bb159011e8 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Controller/Ajax/LoginTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Controller/Ajax/LoginTest.php @@ -50,6 +50,21 @@ class LoginTest extends \PHPUnit_Framework_TestCase */ protected $dataHelper; + /** + * @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultJson; + + /** + * @var \Magento\Framework\Controller\Result\JSONFactory| \PHPUnit_Framework_MockObject_MockObject + */ + protected $resultJsonFactory; + + /** + * @var \Magento\Framework\Controller\Result\Raw \PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRaw; + protected function setUp() { $this->request = $this->getMock( @@ -109,12 +124,31 @@ protected function setUp() $this->dataHelper = $this->getMock( '\Magento\Core\Helper\Data', - ['jsonDecode', 'jsonEncode'], + ['jsonDecode'], [], '', false ); + $this->resultJson = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON') + ->disableOriginalConstructor() + ->getMock(); + $this->resultJsonFactory = $this->getMockBuilder('Magento\Framework\Controller\Result\JSONFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultRaw = $this->getMockBuilder('Magento\Framework\Controller\Result\Raw') + ->disableOriginalConstructor() + ->getMock(); + $resultRawFactory = $this->getMockBuilder('Magento\Framework\Controller\Result\RawFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $resultRawFactory->expects($this->atLeastOnce()) + ->method('create') + ->willReturn($this->resultRaw); + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->object = $objectManager->getObject( 'Magento\Customer\Controller\Ajax\Login', @@ -123,6 +157,8 @@ protected function setUp() 'helper' => $this->dataHelper, 'request' => $this->request, 'response' => $this->response, + 'resultRawFactory' => $resultRawFactory, + 'resultJsonFactory' => $this->resultJsonFactory, 'objectManager' => $this->objectManager, 'customerAccountManagement' => $this->customerAccountManagementMock, ] @@ -149,18 +185,16 @@ public function testLogin() ->method('isXmlHttpRequest') ->willReturn(true); + $this->resultJsonFactory->expects($this->atLeastOnce()) + ->method('create') + ->willReturn($this->resultJson); + $this->dataHelper ->expects($this->any()) ->method('jsonDecode') ->with($jsonRequest) ->willReturn(['username' => 'customer@example.com', 'password' => 'password']); - $this->dataHelper - ->expects($this->any()) - ->method('jsonEncode') - ->with(['message' => 'Login successful.']) - ->willReturn($loginSuccessResponse); - $customerMock = $this->getMockForAbstractClass('Magento\Customer\Api\Data\CustomerInterface'); $this->customerAccountManagementMock ->expects($this->any()) @@ -174,7 +208,13 @@ public function testLogin() $this->customerSession->expects($this->once())->method('regenerateId'); - $this->response->expects($this->once())->method('representJson')->with($loginSuccessResponse); + $this->resultRaw->expects($this->never())->method('setHttpResponseCode'); + + $this->resultJson + ->expects($this->once()) + ->method('setData') + ->with(['message' => 'Login successful.']) + ->willReturn($loginSuccessResponse); $this->object->execute(); } @@ -199,18 +239,16 @@ public function testLoginFailure() ->method('isXmlHttpRequest') ->willReturn(true); + $this->resultJsonFactory->expects($this->never()) + ->method('create') + ->willReturn($this->resultJson); + $this->dataHelper ->expects($this->any()) ->method('jsonDecode') ->with($jsonRequest) ->willReturn(['username' => 'invalid@example.com', 'password' => 'invalid']); - $this->dataHelper - ->expects($this->any()) - ->method('jsonEncode') - ->with(['message' => 'Invalid login or password.']) - ->willReturn($loginFailureResponse); - $customerMock = $this->getMockForAbstractClass('Magento\Customer\Api\Data\CustomerInterface'); $this->customerAccountManagementMock ->expects($this->any()) @@ -224,11 +262,14 @@ public function testLoginFailure() $this->customerSession->expects($this->never())->method('regenerateId'); - $this->response->expects($this->once())->method('representJson')->with($loginFailureResponse); + $this->resultJson + ->expects($this->never()) + ->method('setData') + ->with(['message' => 'Invalid login or password.']) + ->willReturn($loginFailureResponse); - $this->response->expects($this->once())->method('setHttpResponseCode')->with(401); + $this->resultRaw->expects($this->once())->method('setHttpResponseCode')->with(401); $this->object->execute(); } } - diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/EmailTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/EmailTest.php index 84c787d707d4e..f70c8e15c67e6 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/EmailTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/EmailTest.php @@ -61,6 +61,16 @@ class EmailTest extends \PHPUnit_Framework_TestCase */ protected $helper; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectMock; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); @@ -105,6 +115,13 @@ public function setUp() $this->session = $this->getMock('Magento\Backend\Model\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', ['get'], [], '', false); $this->helper = $this->getMock('\Magento\Backend\Helper\Data', ['getUrl'], [], '', false); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); $this->context->expects($this->once()) ->method('getMessageManager') ->will($this->returnValue($this->messageManager)); @@ -131,7 +148,8 @@ public function setUp() [ 'context' => $this->context, 'request' => $this->request, - 'response' => $this->response + 'response' => $this->response, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock ] ); } @@ -143,6 +161,7 @@ public function testEmail() $cmNotifierClassName = 'Magento\Sales\Model\Order\CreditmemoNotifier'; $creditmemo = $this->getMock($creditmemoClassName, ['load', '__wakeup'], [], '', false); $cmNotifier = $this->getMock($cmNotifierClassName, ['notify', '__wakeup'], [], '', false); + $this->prepareRedirect($cmId); $this->request->expects($this->once()) ->method('getParam') @@ -167,9 +186,10 @@ public function testEmail() ->method('addSuccess') ->with('We sent the message.'); - $this->prepareRedirect($cmId); - - $this->creditmemoEmail->execute(); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->creditmemoEmail->execute() + ); $this->assertEquals($this->response, $this->creditmemoEmail->getResponse()); } @@ -179,6 +199,7 @@ public function testEmailNoCreditmemoId() ->method('getParam') ->with('creditmemo_id') ->will($this->returnValue(null)); + $this->assertNull($this->creditmemoEmail->execute()); } @@ -209,20 +230,12 @@ public function testEmailNoCreditmemo() */ protected function prepareRedirect($cmId) { - $this->actionFlag->expects($this->once()) - ->method('get') - ->with('', 'check_url_settings') - ->will($this->returnValue(true)); - $this->session->expects($this->once()) - ->method('setIsUrlNotice') - ->with(true); - $path = 'sales/order_creditmemo/view'; - $this->response->expects($this->once()) - ->method('setRedirect') - ->with($path . '/' . $cmId); - $this->helper->expects($this->atLeastOnce()) - ->method('getUrl') - ->with($path, ['creditmemo_id' => $cmId]) - ->will($this->returnValue($path . '/' . $cmId)); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/order_creditmemo/view', ['creditmemo_id' => $cmId]) + ->willReturnSelf(); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/EmailTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/EmailTest.php index 19b17f328ee7c..e956fe60276cb 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/EmailTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/EmailTest.php @@ -13,6 +13,7 @@ * Class EmailTest * * @package Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class EmailTest extends \PHPUnit_Framework_TestCase { @@ -61,17 +62,31 @@ class EmailTest extends \PHPUnit_Framework_TestCase */ protected $helper; + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirect; + + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactory; + + /** + * @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForward; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactory; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); $this->context = $this->getMock('Magento\Backend\App\Action\Context', [], [], '', false); - $this->response = $this->getMock( - 'Magento\Framework\App\ResponseInterface', - ['setRedirect', 'sendResponse'], - [], - '', - false - ); + $this->response = $this->getMock('Magento\Framework\App\ResponseInterface', [], [], '', false); $this->request = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false); $this->objectManager = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); $this->messageManager = $this->getMock('Magento\Framework\Message\Manager', [], [], '', false); @@ -81,12 +96,6 @@ public function setUp() $this->context->expects($this->once()) ->method('getMessageManager') ->willReturn($this->messageManager); - $this->context->expects($this->once()) - ->method('getRequest') - ->willReturn($this->request); - $this->context->expects($this->once()) - ->method('getResponse') - ->willReturn($this->response); $this->context->expects($this->once()) ->method('getObjectManager') ->willReturn($this->objectManager); @@ -96,15 +105,38 @@ public function setUp() $this->context->expects($this->once()) ->method('getActionFlag') ->willReturn($this->actionFlag); + $this->context->expects($this->once()) + ->method('getRequest') + ->willReturn($this->request); + $this->context->expects($this->once()) + ->method('getResponse') + ->willReturn($this->response); $this->context->expects($this->once()) ->method('getHelper') ->willReturn($this->helper); + + $this->resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->getMock(); + $this->resultForwardFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->invoiceEmail = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\Email', [ 'context' => $this->context, - 'request' => $this->request, - 'response' => $this->response + 'resultRedirectFactory' => $this->resultRedirectFactory, + 'resultForwardFactory' => $this->resultForwardFactory, ] ); } @@ -148,10 +180,14 @@ public function testEmail() ->method('addSuccess') ->with('We sent the message.'); - $this->prepareRedirect($invoiceId, $orderId); - - $this->invoiceEmail->execute(); - $this->assertEquals($this->response, $this->invoiceEmail->getResponse()); + $this->resultRedirectFactory->expects($this->atLeastOnce()) + ->method('create') + ->willReturn($this->resultRedirect); + $this->resultRedirect->expects($this->once()) + ->method('setPath') + ->with('sales/invoice/view', ['order_id' => $orderId, 'invoice_id' => $invoiceId]) + ->willReturnSelf(); + $this->assertInstanceOf('Magento\Backend\Model\View\Result\Redirect', $this->invoiceEmail->execute()); } public function testEmailNoInvoiceId() @@ -160,7 +196,15 @@ public function testEmailNoInvoiceId() ->method('getParam') ->with('invoice_id') ->willReturn(null); - $this->assertNull($this->invoiceEmail->execute()); + $this->resultForwardFactory->expects($this->any()) + ->method('create') + ->willReturn($this->resultForward); + $this->resultForward->expects($this->once()) + ->method('forward') + ->with('noroute') + ->willReturnSelf(); + + $this->assertInstanceOf('Magento\Backend\Model\View\Result\Forward', $this->invoiceEmail->execute()); } public function testEmailNoInvoice() @@ -181,30 +225,14 @@ public function testEmailNoInvoice() ->method('load') ->with($invoiceId) ->willReturn(null); + $this->resultForwardFactory->expects($this->any()) + ->method('create') + ->willReturn($this->resultForward); + $this->resultForward->expects($this->once()) + ->method('forward') + ->with('noroute') + ->willReturnSelf(); - $this->assertNull($this->invoiceEmail->execute()); - } - - /*** - * @param $invoiceId - * @param $orderId - */ - protected function prepareRedirect($invoiceId, $orderId) - { - $this->actionFlag->expects($this->once()) - ->method('get') - ->with('', 'check_url_settings') - ->willReturn(true); - $this->session->expects($this->once()) - ->method('setIsUrlNotice') - ->with(true); - $path = 'sales/invoice/view'; - $this->response->expects($this->once()) - ->method('setRedirect') - ->with($path . '/' . $invoiceId); - $this->helper->expects($this->atLeastOnce()) - ->method('getUrl') - ->with($path, ['order_id' => $orderId, 'invoice_id' => $invoiceId]) - ->willReturn($path . '/' . $invoiceId); + $this->assertInstanceOf('Magento\Backend\Model\View\Result\Forward', $this->invoiceEmail->execute()); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/ProcessDataTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/ProcessDataTest.php index 52dd560e9fdcd..c72a140293203 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/ProcessDataTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/ProcessDataTest.php @@ -39,11 +39,6 @@ class ProcessDataTest extends \PHPUnit_Framework_TestCase */ protected $eventManager; - /** - * @var \Magento\Framework\App\ActionFlag|\PHPUnit_Framework_MockObject_MockObject - */ - protected $actionFlag; - /** * @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -54,6 +49,16 @@ class ProcessDataTest extends \PHPUnit_Framework_TestCase */ protected $escaper; + /** + * @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForward; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactory; + protected function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); @@ -92,9 +97,6 @@ protected function setUp() $context->expects($this->any())->method('getResponse')->willReturn($response); $context->expects($this->any())->method('getRequest')->willReturn($this->request); - $this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false); - $context->expects($this->any())->method('getActionFlag')->willReturn($this->actionFlag); - $this->messageManager = $this->getMock('Magento\Framework\Message\ManagerInterface', [], [], '', false); $context->expects($this->any())->method('getMessageManager')->willReturn($this->messageManager); @@ -104,21 +106,28 @@ protected function setUp() $this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface'); $context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManager); - $this->session = $this->getMock( - 'Magento\Backend\Model\Session\Quote', - ['setIsUrlNotice', 'getQuote'], - [], - '', - false - ); + $this->session = $this->getMock('Magento\Backend\Model\Session\Quote', [], [], '', false); $context->expects($this->any())->method('getSession')->willReturn($this->session); $this->escaper = $this->getMock('Magento\Framework\Escaper', ['escapeHtml'], [], '', false); + $this->resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->getMock(); + $this->resultForwardFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultForwardFactory->expects($this->once()) + ->method('create') + ->willReturn($this->resultForward); + $this->processData = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Create\ProcessData', [ 'context' => $context, - 'escaper' => $this->escaper + 'escaper' => $this->escaper, + 'resultForwardFactory' => $this->resultForwardFactory, ] ); } @@ -217,12 +226,11 @@ public function testExecute($noDiscount, $couponCode, $errorMessage, $actualCoup $this->messageManager->expects($this->once())->method('addError')->with($errorMessageManager)->willReturnSelf(); - $this->actionFlag->expects($this->once())->method('get')->willReturn(false); - $this->session->expects($this->once())->method('setIsUrlNotice')->with(false)->willReturn(false); - $this->request->expects($this->once())->method('initForward')->willReturnSelf(); - $this->request->expects($this->once())->method('setActionName')->willReturnSelf(); - $this->request->expects($this->once())->method('setDispatched')->willReturnSelf(); - $this->assertNull($this->processData->execute()); + $this->resultForward->expects($this->once()) + ->method('forward') + ->with('index') + ->willReturnSelf(); + $this->assertInstanceOf('Magento\Backend\Model\View\Result\Forward', $this->processData->execute()); } public function isApplyDiscountDataProvider() diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/AddCommentTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/AddCommentTest.php index 54dca84c1748f..4ed46493ce78e 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/AddCommentTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/AddCommentTest.php @@ -46,46 +46,49 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase protected $objectManagerMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $viewMock; + protected $resultPageFactoryMock; /** - * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Controller\Result\JSONFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultJsonFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRawFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */ protected $resultPageMock; /** - * @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */ - protected $pageConfigMock; + protected $resultJsonMock; /** - * @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Controller\Result\Raw|\PHPUnit_Framework_MockObject_MockObject */ - protected $pageTitleMock; + protected $resultRawMock; public function setUp() { $titleMock = $this->getMockBuilder('Magento\Framework\App\Action\Title') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->viewMock = $this->getMockBuilder('Magento\Backend\Model\View') - ->disableOriginalConstructor() - ->getMock(); $this->contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock->expects($this->any()) ->method('getRequest') @@ -99,43 +102,46 @@ public function setUp() $this->contextMock->expects($this->any()) ->method('getTitle') ->will($this->returnValue($titleMock)); - $this->contextMock->expects($this->any()) - ->method('getView') - ->will($this->returnValue($this->viewMock)); $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->senderMock = $this->getMockBuilder('Magento\Sales\Model\Order\Email\Sender\CreditmemoSender') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); - $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') ->disableOriginalConstructor() + ->setMethods(['create']) ->getMock(); - $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') + $this->resultJsonFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSONFactory') ->disableOriginalConstructor() + ->setMethods(['create']) ->getMock(); - $this->pageTitleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title') + $this->resultRawFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\RawFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') + ->disableOriginalConstructor() + ->getMock(); + $this->resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRawMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Raw') ->disableOriginalConstructor() ->getMock(); - $this->controller = new \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\AddComment( - $this->contextMock, - $this->loaderMock, - $this->senderMock - ); - $this->viewMock->expects($this->any()) - ->method('getPage') - ->willReturn($this->resultPageMock); - $this->resultPageMock->expects($this->any()) - ->method('getConfig') - ->willReturn($this->pageConfigMock); - $this->pageConfigMock->expects($this->any()) - ->method('getTitle') - ->willReturn($this->pageTitleMock); - $this->pageTitleMock->expects($this->any()) - ->method('prepend'); + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->controller = $objectManager->getObject( + 'Magento\Sales\Controller\Adminhtml\Order\Creditmemo\AddComment', + [ + 'context' => $this->contextMock, + 'creditmemoLoader' => $this->loaderMock, + 'creditmemoSender' => $this->senderMock, + 'resultPageFactory' => $this->resultPageFactoryMock, + 'resultJsonFactory' => $this->resultJsonFactoryMock, + 'resultRawFactory' => $this->resultRawFactoryMock + ] + ); } public function testExecuteModelException() @@ -147,20 +153,18 @@ public function testExecuteModelException() $this->requestMock->expects($this->any()) ->method('setParam') ->will($this->throwException($e)); - $helperMock = $this->getMockBuilder('Magento\Core\Helper\Data') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $helperMock->expects($this->once()) - ->method('jsonEncode') + $this->resultJsonFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultJsonMock); + $this->resultJsonMock->expects($this->once()) + ->method('setData') ->with($response) - ->willReturn(json_encode($response)); - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Magento\Core\Helper\Data') - ->willReturn($helperMock); + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Framework\Controller\Result\JSON', + $this->controller->execute() + ); } public function testExecuteException() @@ -172,20 +176,18 @@ public function testExecuteException() $this->requestMock->expects($this->any()) ->method('setParam') ->will($this->throwException($e)); - $helperMock = $this->getMockBuilder('Magento\Core\Helper\Data') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $helperMock->expects($this->once()) - ->method('jsonEncode') + $this->resultJsonFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultJsonMock); + $this->resultJsonMock->expects($this->once()) + ->method('setData') ->with($response) - ->willReturn(json_encode($response)); - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Magento\Core\Helper\Data') - ->willReturn($helperMock); + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Framework\Controller\Result\JSON', + $this->controller->execute() + ); } public function testExecuteNoComment() @@ -194,25 +196,22 @@ public function testExecuteNoComment() $response = ['error' => true, 'message' => $message]; $data = []; - $helperMock = $this->getMockBuilder('Magento\Core\Helper\Data') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $helperMock->expects($this->once()) - ->method('jsonEncode') - ->with($response) - ->willReturn(json_encode($response)); - $this->requestMock->expects($this->once()) ->method('getPost') ->with('comment') ->willReturn($data); - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Magento\Core\Helper\Data') - ->willReturn($helperMock); + $this->resultJsonFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultJsonMock); + $this->resultJsonMock->expects($this->once()) + ->method('setData') + ->with($response) + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Framework\Controller\Result\JSON', + $this->controller->execute() + ); } public function testExecute() @@ -221,48 +220,56 @@ public function testExecute() $data = ['comment' => $comment]; $html = 'test output'; + $creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') + ->disableOriginalConstructor() + ->getMock(); + $commentMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo\Comment') + ->disableOriginalConstructor() + ->getMock(); + $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') + ->disableOriginalConstructor() + ->getMock(); + $blockMock = $this->getMockBuilder('Magento\Sales\Block\Adminhtml\Order\Creditmemo\View\Comments') + ->disableOriginalConstructor() + ->getMock(); + $this->requestMock->expects($this->once()) ->method('getPost') ->with('comment') ->willReturn($data); $this->requestMock->expects($this->any()) ->method('getParam') - ->withAnyParameters() ->willReturnArgument(0); - $creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $commentMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo\Comment') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $creditmemoMock->expects($this->once()) ->method('addComment') - ->withAnyParameters() ->willReturn($commentMock); $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($creditmemoMock); - $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $blockMock = $this->getMockBuilder('Magento\Sales\Block\Adminhtml\Order\Creditmemo\View\Comments') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $blockMock->expects($this->once()) - ->method('toHtml') - ->willReturn($html); + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultPageMock); + $this->resultPageMock->expects($this->atLeastOnce()) + ->method('getLayout') + ->willReturn($layoutMock); $layoutMock->expects($this->once()) ->method('getBlock') ->with('creditmemo_comments') ->willReturn($blockMock); - $this->viewMock->expects($this->once()) - ->method('getLayout') - ->willReturn($layoutMock); + $blockMock->expects($this->once()) + ->method('toHtml') + ->willReturn($html); + $this->resultRawFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRawMock); + $this->resultRawMock->expects($this->once()) + ->method('setContents') + ->with($html) + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Framework\Controller\Result\Raw', + $this->controller->execute() + ); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/CancelTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/CancelTest.php index 83b8f81e10e80..6d0433192ab26 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/CancelTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/CancelTest.php @@ -40,11 +40,6 @@ class CancelTest extends \PHPUnit_Framework_TestCase */ protected $objectManagerMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $viewMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -70,6 +65,26 @@ class CancelTest extends \PHPUnit_Framework_TestCase */ protected $helperMock; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectMock; + + /** + * @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardMock; + public function setUp() { $this->creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') @@ -78,43 +93,31 @@ public function setUp() ->getMock(); $titleMock = $this->getMockBuilder('Magento\Framework\App\Action\Title') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->viewMock = $this->getMockBuilder('Magento\Backend\Model\View') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\Manager') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->sessionMock = $this->getMockBuilder('Magento\Backend\Model\Session') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->helperMock = $this->getMockBuilder('Magento\Backend\Helper\Data') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock->expects($this->any()) ->method('getHelper') ->will($this->returnValue($this->helperMock)); $this->actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock->expects($this->any()) ->method('getSession') @@ -134,30 +137,47 @@ public function setUp() $this->contextMock->expects($this->any()) ->method('getTitle') ->will($this->returnValue($titleMock)); - $this->contextMock->expects($this->any()) - ->method('getView') - ->will($this->returnValue($this->viewMock)); $this->contextMock->expects($this->any()) ->method('getMessageManager') ->will($this->returnValue($this->messageManagerMock)); $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); - $this->controller = new \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Cancel( - $this->contextMock, - $this->loaderMock + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->getMock(); + + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->controller = $objectManager->getObject( + 'Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Cancel', + [ + 'context' => $this->contextMock, + 'creditmemoLoader' => $this->loaderMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock, + 'resultForwardFactory' => $this->resultForwardFactoryMock + ] ); } public function testExecuteModelException() { + $id = 123; $message = 'Model exception'; $e = new \Magento\Framework\Model\Exception($message); $this->requestMock->expects($this->any()) ->method('getParam') - ->withAnyParameters() ->willReturnArgument(0); $this->creditmemoMock->expects($this->once()) ->method('cancel') @@ -165,18 +185,31 @@ public function testExecuteModelException() $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($this->creditmemoMock); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->creditmemoMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn($id); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/view', ['creditmemo_id' => $id]) + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->controller->execute() + ); } public function testExecuteException() { + $id = 321; $message = 'Model exception'; $e = new \Exception($message); $this->requestMock->expects($this->any()) ->method('getParam') - ->withAnyParameters() ->willReturnArgument(0); $this->creditmemoMock->expects($this->once()) ->method('cancel') @@ -184,8 +217,21 @@ public function testExecuteException() $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($this->creditmemoMock); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->creditmemoMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn($id); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/view', ['creditmemo_id' => $id]) + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->controller->execute() + ); } public function testExecuteNoCreditmemo() @@ -197,35 +243,44 @@ public function testExecuteNoCreditmemo() $this->loaderMock->expects($this->once()) ->method('load') ->willReturn(false); + $this->resultForwardFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultForwardMock); + $this->resultForwardMock->expects($this->once()) + ->method('forward') + ->with('noroute') + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Forward', + $this->controller->execute() + ); } public function testExecute() { + $id = '111'; + + $transactionMock = $this->getMockBuilder('Magento\Framework\DB\Transaction') + ->disableOriginalConstructor() + ->getMock(); + $invoiceMock = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice') + ->disableOriginalConstructor() + ->getMock(); + $orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') + ->disableOriginalConstructor() + ->getMock(); + $this->requestMock->expects($this->any()) ->method('getParam') - ->withAnyParameters() ->willReturnArgument(0); $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($this->creditmemoMock); - $transactionMock = $this->getMockBuilder('Magento\Framework\DB\Transaction') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Framework\DB\Transaction') ->willReturn($transactionMock); - $invoiceMock = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->creditmemoMock->expects($this->any()) ->method('getOrder') ->willReturn($orderMock); @@ -235,7 +290,20 @@ public function testExecute() $this->messageManagerMock->expects($this->once()) ->method('addSuccess') ->with('The credit memo has been canceled.'); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->creditmemoMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn($id); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/view', ['creditmemo_id' => $id]) + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->controller->execute() + ); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/NewActionTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/NewActionTest.php index 6a97735ce2f02..76c3f1dad3316 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/NewActionTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/NewActionTest.php @@ -46,11 +46,6 @@ class NewActionTest extends \PHPUnit_Framework_TestCase */ protected $invoiceMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $resultPageMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -71,30 +66,20 @@ class NewActionTest extends \PHPUnit_Framework_TestCase */ protected $backendSessionMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\ViewInterface - */ - protected $viewMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\LayoutInterface */ protected $layoutMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Element\BlockInterface + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $blockMenuMock; + protected $resultPageFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Menu + * @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */ - protected $modelMenuMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Menu\Item - */ - protected $modelMenuItem; + protected $resultPageMock; public function setUp() { @@ -140,22 +125,10 @@ public function setUp() [] ); $this->titleMock = $this->getMock('Magento\Framework\View\Page\Title', [], [], '', false); - $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') - ->disableOriginalConstructor() - ->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') ->disableOriginalConstructor() ->getMock(); $this->backendSessionMock = $this->getMock('Magento\Backend\Model\Session', ['getCommentText'], [], '', false); - $this->viewMock = $this->getMockForAbstractClass( - 'Magento\Framework\App\ViewInterface', - [], - '', - false, - false, - true, - [] - ); $this->layoutMock = $this->getMockForAbstractClass( 'Magento\Framework\View\LayoutInterface', [], @@ -165,29 +138,33 @@ public function setUp() true, [] ); - $this->blockMenuMock = $this->getMock( - 'Magento\Backend\Block\Menu', - ['setActive', 'getMenuModel'], - [], - '', - false - ); - $this->modelMenuMock = $this->getMockBuilder('Magento\Backend\Model\Menu') - ->disableOriginalConstructor()->getMock(); - $this->modelMenuItem = $this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock->expects($this->once()) ->method('getRequest') ->will($this->returnValue($this->requestMock)); $this->contextMock->expects($this->once()) ->method('getResponse') ->will($this->returnValue($this->responseMock)); - $this->contextMock->expects($this->once()) - ->method('getView') - ->will($this->returnValue($this->viewMock)); $this->contextMock->expects($this->once()) ->method('getObjectManager') ->will($this->returnValue($this->objectManagerMock)); - $this->controller = new NewAction($this->contextMock, $this->creditmemoLoaderMock); + + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->controller = $objectManager->getObject( + 'Magento\Sales\Controller\Adminhtml\Order\Creditmemo\NewAction', + [ + 'context' => $this->contextMock, + 'creditmemoLoader' => $this->creditmemoLoaderMock, + 'resultPageFactory' => $this->resultPageFactoryMock + ] + ); } /** @@ -224,7 +201,7 @@ public function testExecute() $this->invoiceMock->expects($this->once()) ->method('getIncrementId') ->will($this->returnValue('invoice-increment-id')); - $this->titleMock->expects($this->exactly(3)) + $this->titleMock->expects($this->exactly(2)) ->method('prepend') ->will($this->returnValueMap([ ['Credit Memos', null], @@ -242,34 +219,26 @@ public function testExecute() $this->creditmemoMock->expects($this->once()) ->method('setCommentText') ->with($this->equalTo('comment')); - $this->viewMock->expects($this->once()) - ->method('loadLayout'); - $this->viewMock->expects($this->once()) - ->method('renderLayout'); - $this->viewMock->expects($this->once()) - ->method('getLayout') - ->will($this->returnValue($this->layoutMock)); - $this->viewMock->expects($this->any())->method('getPage')->will($this->returnValue($this->resultPageMock)); $this->resultPageMock->expects($this->any())->method('getConfig')->will( $this->returnValue($this->pageConfigMock) ); - $this->pageConfigMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->titleMock)); - $this->layoutMock->expects($this->once()) - ->method('getBlock') - ->with($this->equalTo('menu')) - ->will($this->returnValue($this->blockMenuMock)); - $this->blockMenuMock->expects($this->once()) - ->method('setActive') - ->with($this->equalTo('Magento_Sales::sales_order')); - $this->blockMenuMock->expects($this->once()) - ->method('getMenuModel') - ->will($this->returnValue($this->modelMenuMock)); - $this->modelMenuMock->expects($this->once()) - ->method('getParentItems') - ->will($this->returnValue([$this->modelMenuItem])); - $this->modelMenuItem->expects($this->once()) + $this->pageConfigMock->expects($this->any()) ->method('getTitle') - ->will($this->returnValue('item-title')); - $this->assertNull($this->controller->execute()); + ->willReturn($this->titleMock); + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultPageMock); + $this->resultPageMock->expects($this->once()) + ->method('setActiveMenu') + ->with('Magento_Sales::sales_order') + ->willReturnSelf(); + $this->resultPageMock->expects($this->atLeastOnce()) + ->method('getConfig') + ->willReturn($this->pageConfigMock); + + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Page', + $this->controller->execute() + ); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/PrintActionTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/PrintActionTest.php index bbbc973d67f1a..8173d67f13fe1 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/PrintActionTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/PrintActionTest.php @@ -6,219 +6,249 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Creditmemo; /** - * Class PrintActionTest - * @SuppressWarnings(PHPMD.TooManyFields) + * @covers \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class PrintActionTest extends \PHPUnit_Framework_TestCase { /** * @var \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction */ - protected $controller; + protected $printAction; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\App\Action\Context */ - protected $contextMock; + protected $context; /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $loaderMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $requestMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader|\PHPUnit_Framework_MockObject_MockObject */ - protected $responseMock; + protected $creditmemoLoaderMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $objectManagerMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $viewMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Model\Order\Creditmemo|\PHPUnit_Framework_MockObject_MockObject */ protected $creditmemoMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $messageManagerMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Model\Order\Pdf\Creditmemo|\PHPUnit_Framework_MockObject_MockObject */ - protected $sessionMock; + protected $creditmemoPdfMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Zend_Pdf|\PHPUnit_Framework_MockObject_MockObject */ - protected $actionFlagMock; + protected $pdfMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Stdlib\DateTime\DateTime|\PHPUnit_Framework_MockObject_MockObject */ - protected $helperMock; + protected $dateTimeMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\Response\Http\FileFactory|\PHPUnit_Framework_MockObject_MockObject */ protected $fileFactoryMock; /** - * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $resultPageMock; + protected $responseMock; /** - * @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $pageConfigMock; + protected $resultForwardFactoryMock; /** - * @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject */ - protected $pageTitleMock; + protected $resultForwardMock; public function setUp() { - $this->creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') - ->disableOriginalConstructor() - ->setMethods(['getInvoice', 'getOrder', 'cancel', 'getId', '__wakeup']) - ->getMock(); - $titleMock = $this->getMockBuilder('Magento\Framework\App\Action\Title') - ->disableOriginalConstructor() - ->setMethods([]) + $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') ->getMock(); - $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') + $this->creditmemoLoaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') ->disableOriginalConstructor() - ->setMethods([]) + ->setMethods( + [ + 'setOrderId', + 'setCreditmemoId', + 'setCreditmemo', + 'setInvoiceId', + 'load' + ] + ) ->getMock(); - $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->viewMock = $this->getMockBuilder('Magento\Backend\Model\View') - ->disableOriginalConstructor() - ->setMethods([]) + $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') ->getMock(); - $this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\Manager') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->sessionMock = $this->getMockBuilder('Magento\Backend\Model\Session') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->helperMock = $this->getMockBuilder('Magento\Backend\Helper\Data') + $this->creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); - $this->contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') + $this->creditmemoPdfMock = $this->getMockBuilder('Magento\Sales\Model\Order\Pdf\Creditmemo') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); - $this->contextMock->expects($this->any()) - ->method('getHelper') - ->will($this->returnValue($this->helperMock)); - $this->actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag') + $this->pdfMock = $this->getMockBuilder('Zend_Pdf') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); - $this->contextMock->expects($this->any()) - ->method('getSession') - ->will($this->returnValue($this->sessionMock)); - $this->contextMock->expects($this->any()) - ->method('getActionFlag') - ->will($this->returnValue($this->actionFlagMock)); - $this->contextMock->expects($this->any()) - ->method('getRequest') - ->will($this->returnValue($this->requestMock)); - $this->contextMock->expects($this->any()) - ->method('getResponse') - ->will($this->returnValue($this->responseMock)); - $this->contextMock->expects($this->any()) - ->method('getObjectManager') - ->will($this->returnValue($this->objectManagerMock)); - $this->contextMock->expects($this->any()) - ->method('getTitle') - ->will($this->returnValue($titleMock)); - $this->contextMock->expects($this->any()) - ->method('getView') - ->will($this->returnValue($this->viewMock)); - $this->contextMock->expects($this->any()) - ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); - $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') + $this->dateTimeMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTime') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->fileFactoryMock = $this->getMockBuilder('Magento\Framework\App\Response\Http\FileFactory') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); - $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') - ->disableOriginalConstructor() + $this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface') ->getMock(); - $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') ->disableOriginalConstructor() + ->setMethods(['create']) ->getMock(); - $this->pageTitleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title') + $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') ->disableOriginalConstructor() ->getMock(); - $this->controller = new \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction( - $this->contextMock, - $this->fileFactoryMock, - $this->loaderMock + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->context = $objectManager->getObject( + 'Magento\Backend\App\Action\Context', + [ + 'request' => $this->requestMock, + 'objectManager' => $this->objectManagerMock + ] + ); + $this->printAction = $objectManager->getObject( + 'Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction', + [ + 'context' => $this->context, + 'fileFactory' => $this->fileFactoryMock, + 'creditmemoLoader' => $this->creditmemoLoaderMock, + 'resultForwardFactory' => $this->resultForwardFactoryMock + ] ); } - public function testExecuteModelException() + /** + * @covers \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction::execute + */ + public function testExecute() { - $this->requestMock->expects($this->at(0)) - ->method('getParam') - ->with('order_id') - ->willReturn(1); - $this->requestMock->expects($this->at(1)) - ->method('getParam') - ->with('creditmemo_id') - ->willReturn(1); - $this->requestMock->expects($this->at(2)) - ->method('getParam') - ->with('creditmemo') - ->willReturn('some data'); - $this->requestMock->expects($this->at(3)) - ->method('getParam') - ->with('invoice_id') - ->willReturn(1); - $this->loaderMock->expects($this->once()) + $creditmemoId = 2; + $date = '2015-01-19_13-03-45'; + $fileName = 'creditmemo2015-01-19_13-03-45.pdf'; + $fileContents = 'pdf0123456789'; + $this->prepareTestExecute($creditmemoId); + + $this->objectManagerMock->expects($this->any()) + ->method('create') + ->willReturnMap( + [ + ['Magento\Sales\Model\Order\Creditmemo', [], $this->creditmemoMock], + ['Magento\Sales\Model\Order\Pdf\Creditmemo', [], $this->creditmemoPdfMock] + ] + ); + $this->creditmemoMock->expects($this->once()) ->method('load') - ->willReturn($this->creditmemoMock); - $this->viewMock->expects($this->atLeastOnce()) - ->method('getPage') - ->willReturn($this->resultPageMock); - $this->resultPageMock->expects($this->atLeastOnce()) - ->method('getConfig') - ->willReturn($this->pageConfigMock); - $this->pageConfigMock->expects($this->atLeastOnce()) - ->method('getTitle') - ->willReturn($this->pageTitleMock); - $this->pageTitleMock->expects($this->atLeastOnce()) - ->method('prepend'); - - $this->assertNull($this->controller->execute()); + ->with($creditmemoId) + ->willReturnSelf(); + $this->creditmemoPdfMock->expects($this->once()) + ->method('getPdf') + ->with([$this->creditmemoMock]) + ->willReturn($this->pdfMock); + $this->objectManagerMock->expects($this->once()) + ->method('get') + ->with('Magento\Framework\Stdlib\DateTime\DateTime') + ->willReturn($this->dateTimeMock); + $this->dateTimeMock->expects($this->once()) + ->method('date') + ->with('Y-m-d_H-i-s') + ->willReturn($date); + $this->pdfMock->expects($this->once()) + ->method('render') + ->willReturn($fileContents); + $this->fileFactoryMock->expects($this->once()) + ->method('create') + ->with( + $fileName, + $fileContents, + \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, + 'application/pdf' + ) + ->willReturn($this->responseMock); + + $this->assertInstanceOf( + 'Magento\Framework\App\ResponseInterface', + $this->printAction->execute() + ); + } + + /** + * @covers \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction::execute + */ + public function testExecuteNoCreditmemoId() + { + $this->prepareTestExecute(); + + $this->resultForwardFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultForwardMock); + $this->resultForwardMock->expects($this->once()) + ->method('forward') + ->with('noroute') + ->willReturnSelf(); + + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Forward', + $this->printAction->execute() + ); + } + + /** + * @param int|null $creditmemoId + */ + protected function prepareTestExecute($creditmemoId = null) + { + $orderId = 1; + $creditmemo = 3; + $invoiceId = 4; + + $this->requestMock->expects($this->any()) + ->method('getParam') + ->willReturnMap( + [ + ['order_id', null, $orderId], + ['creditmemo_id', null, $creditmemoId], + ['creditmemo', null, $creditmemo], + ['invoice_id', null, $invoiceId] + ] + ); + $this->creditmemoLoaderMock->expects($this->once()) + ->method('setOrderId') + ->with($orderId) + ->willReturnSelf(); + $this->creditmemoLoaderMock->expects($this->once()) + ->method('setCreditmemoId') + ->with($creditmemoId) + ->willReturnSelf(); + $this->creditmemoLoaderMock->expects($this->once()) + ->method('setCreditmemo') + ->with($creditmemo) + ->willReturnSelf(); + $this->creditmemoLoaderMock->expects($this->once()) + ->method('setInvoiceId') + ->with($invoiceId) + ->willReturnSelf(); + $this->creditmemoLoaderMock->expects($this->once()) + ->method('load'); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/SaveTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/SaveTest.php index 5a39535775382..d41004a8daa3f 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/SaveTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/SaveTest.php @@ -8,6 +8,9 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Creditmemo; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class SaveTest extends \PHPUnit_Framework_TestCase { /** @@ -45,6 +48,26 @@ class SaveTest extends \PHPUnit_Framework_TestCase */ protected $memoLoaderMock; + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardMock; + + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectMock; + /** * Init model for future tests */ @@ -64,6 +87,20 @@ protected function setUp() ['setFormData'], $constructArguments ); + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); $this->_objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface'); $registryMock = $this->getMock('Magento\Framework\Registry', [], [], '', false, false); $this->_objectManager->expects( @@ -98,7 +135,11 @@ protected function setUp() ); $this->_controller = $helper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save', - ['context' => $context, 'creditmemoLoader' => $this->memoLoaderMock] + [ + 'context' => $context, + 'creditmemoLoader' => $this->memoLoaderMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock + ] ); } @@ -134,13 +175,23 @@ public function testSaveActionOnlineRefundToStoreCredit() )->will( $this->returnValue($creditmemoMock) ); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/new', ['_current' => true]) + ->willReturnSelf(); $this->_setSaveActionExpectationForMageCoreException( $data, 'Cannot create online refund for Refund to Store Credit.' ); - $this->_controller->execute(); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->_controller->execute() + ); } /** @@ -176,6 +227,13 @@ public function testSaveActionWithNegativeCreditmemo() )->will( $this->returnValue($creditmemoMock) ); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/new', ['_current' => true]) + ->willReturnSelf(); $this->_setSaveActionExpectationForMageCoreException($data, 'Credit memo\'s total must be positive.'); @@ -192,7 +250,5 @@ protected function _setSaveActionExpectationForMageCoreException($data, $errorMe { $this->_messageManager->expects($this->once())->method('addError')->with($this->equalTo($errorMessage)); $this->_sessionMock->expects($this->once())->method('setFormData')->with($this->equalTo($data)); - - $this->_responseMock->expects($this->once())->method('setRedirect'); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQtyTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQtyTest.php index 0bd789d5a3a6a..2b20cdac35995 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQtyTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/UpdateQtyTest.php @@ -7,6 +7,7 @@ /** * Class UpdateQtyTest + * @SuppressWarnings(PHPMD.TooManyFields) */ class UpdateQtyTest extends \PHPUnit_Framework_TestCase { @@ -40,11 +41,6 @@ class UpdateQtyTest extends \PHPUnit_Framework_TestCase */ protected $objectManagerMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $viewMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -70,6 +66,36 @@ class UpdateQtyTest extends \PHPUnit_Framework_TestCase */ protected $helperMock; + /** + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultPageFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\JSONFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultJsonFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRawFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultPageMock; + + /** + * @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultJsonMock; + + /** + * @var \Magento\Framework\Controller\Result\Raw|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRawMock; + public function setUp() { $this->creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') @@ -78,43 +104,31 @@ public function setUp() ->getMock(); $titleMock = $this->getMockBuilder('Magento\Framework\App\Action\Title') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->viewMock = $this->getMockBuilder('Magento\Backend\Model\View') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\Manager') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->sessionMock = $this->getMockBuilder('Magento\Backend\Model\Session') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->helperMock = $this->getMockBuilder('Magento\Backend\Helper\Data') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock->expects($this->any()) ->method('getHelper') ->will($this->returnValue($this->helperMock)); $this->actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock->expects($this->any()) ->method('getSession') @@ -134,20 +148,44 @@ public function setUp() $this->contextMock->expects($this->any()) ->method('getTitle') ->will($this->returnValue($titleMock)); - $this->contextMock->expects($this->any()) - ->method('getView') - ->will($this->returnValue($this->viewMock)); $this->contextMock->expects($this->any()) ->method('getMessageManager') ->will($this->returnValue($this->messageManagerMock)); $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') ->disableOriginalConstructor() - ->setMethods([]) + ->getMock(); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultJsonFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSONFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRawFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\RawFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') + ->disableOriginalConstructor() + ->getMock(); + $this->resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRawMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Raw') + ->disableOriginalConstructor() ->getMock(); - $this->controller = new \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\UpdateQty( - $this->contextMock, - $this->loaderMock + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->controller = $objectManager->getObject( + 'Magento\Sales\Controller\Adminhtml\Order\Creditmemo\UpdateQty', + [ + 'context' => $this->contextMock, + 'creditmemoLoader' => $this->loaderMock, + 'resultPageFactory' => $this->resultPageFactoryMock, + 'resultJsonFactory' => $this->resultJsonFactoryMock, + 'resultRawFactory' => $this->resultRawFactoryMock + ] ); } @@ -159,25 +197,22 @@ public function testExecuteModelException() $this->requestMock->expects($this->any()) ->method('getParam') - ->withAnyParameters() ->willReturnArgument(0); $this->loaderMock->expects($this->once()) ->method('load') ->willThrowException($e); - $helperMock = $this->getMockBuilder('Magento\Core\Helper\Data') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $helperMock->expects($this->once()) - ->method('jsonEncode') + $this->resultJsonFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultJsonMock); + $this->resultJsonMock->expects($this->once()) + ->method('setData') ->with($response) - ->willReturn(json_encode($response)); - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Magento\Core\Helper\Data') - ->willReturn($helperMock); + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Framework\Controller\Result\JSON', + $this->controller->execute() + ); } public function testExecuteException() @@ -188,25 +223,22 @@ public function testExecuteException() $this->requestMock->expects($this->any()) ->method('getParam') - ->withAnyParameters() ->willReturnArgument(0); $this->loaderMock->expects($this->once()) ->method('load') ->willThrowException($e); - $helperMock = $this->getMockBuilder('Magento\Core\Helper\Data') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $helperMock->expects($this->once()) - ->method('jsonEncode') + $this->resultJsonFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultJsonMock); + $this->resultJsonMock->expects($this->once()) + ->method('setData') ->with($response) - ->willReturn(json_encode($response)); - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Magento\Core\Helper\Data') - ->willReturn($helperMock); + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Framework\Controller\Result\JSON', + $this->controller->execute() + ); } public function testExecute() @@ -220,12 +252,17 @@ public function testExecute() $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $blockMock = $this->getMockBuilder('Magento\Sales\Block\Order\Items') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); + + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultPageMock); + $this->resultPageMock->expects($this->atLeastOnce()) + ->method('getLayout') + ->willReturn($layoutMock); $blockMock->expects($this->once()) ->method('toHtml') ->willReturn($response); @@ -233,10 +270,17 @@ public function testExecute() ->method('getBlock') ->with('order_items') ->willReturn($blockMock); - $this->viewMock->expects($this->once()) - ->method('getLayout') - ->willReturn($layoutMock); + $this->resultRawFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRawMock); + $this->resultRawMock->expects($this->once()) + ->method('setContents') + ->with($response) + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Framework\Controller\Result\Raw', + $this->controller->execute() + ); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/ViewTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/ViewTest.php index 5da711e94fd3e..904773cec79d7 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/ViewTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/ViewTest.php @@ -41,11 +41,6 @@ class ViewTest extends \PHPUnit_Framework_TestCase */ protected $objectManagerMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $viewMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -76,11 +71,6 @@ class ViewTest extends \PHPUnit_Framework_TestCase */ protected $invoiceMock; - /** - * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject - */ - protected $resultPageMock; - /** * @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject */ @@ -91,59 +81,90 @@ class ViewTest extends \PHPUnit_Framework_TestCase */ protected $pageTitleMock; + /** + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultPageFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultPageMock; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardMock; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function setUp() { + $titleMock = $this->getMockBuilder('Magento\Framework\App\Action\Title') + ->disableOriginalConstructor() + ->getMock(); $this->invoiceMock = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') ->disableOriginalConstructor() ->setMethods(['getInvoice', 'getOrder', 'cancel', 'getId', '__wakeup']) ->getMock(); - $titleMock = $this->getMockBuilder('Magento\Framework\App\Action\Title') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->viewMock = $this->getMockBuilder('Magento\Backend\Model\View') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\Manager') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->sessionMock = $this->getMockBuilder('Magento\Backend\Model\Session') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->helperMock = $this->getMockBuilder('Magento\Backend\Helper\Data') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock->expects($this->any()) ->method('getHelper') ->will($this->returnValue($this->helperMock)); $this->actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); + $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') + ->disableOriginalConstructor() + ->getMock(); + $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') + ->disableOriginalConstructor() + ->getMock(); + $this->pageTitleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title') + ->disableOriginalConstructor() + ->getMock(); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') + ->disableOriginalConstructor() + ->getMock(); + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock->expects($this->any()) ->method('getSession') ->will($this->returnValue($this->sessionMock)); @@ -162,60 +183,62 @@ public function setUp() $this->contextMock->expects($this->any()) ->method('getTitle') ->will($this->returnValue($titleMock)); - $this->contextMock->expects($this->any()) - ->method('getView') - ->will($this->returnValue($this->viewMock)); $this->contextMock->expects($this->any()) ->method('getMessageManager') ->will($this->returnValue($this->messageManagerMock)); - $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') - ->disableOriginalConstructor() - ->getMock(); - $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') - ->disableOriginalConstructor() - ->getMock(); - $this->pageTitleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title') - ->disableOriginalConstructor() - ->getMock(); - - $this->controller = new \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\View( - $this->contextMock, - $this->loaderMock - ); - - $this->viewMock->expects($this->any()) - ->method('getPage') - ->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->any()) ->method('getConfig') ->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any()) ->method('getTitle') ->willReturn($this->pageTitleMock); + + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->controller = $objectManager->getObject( + 'Magento\Sales\Controller\Adminhtml\Order\Creditmemo\View', + [ + 'context' => $this->contextMock, + 'creditmemoLoader' => $this->loaderMock, + 'resultPageFactory' => $this->resultPageFactoryMock, + 'resultForwardFactory' => $this->resultForwardFactoryMock + ] + ); } public function testExecuteNoCreditMemo() { $this->requestMock->expects($this->any()) ->method('getParam') - ->withAnyParameters() ->willReturnArgument(0); $this->loaderMock->expects($this->once()) ->method('load') ->willReturn(false); + $this->resultForwardFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultForwardMock); + $this->resultForwardMock->expects($this->once()) + ->method('forward') + ->with('noroute') + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Forward', + $this->controller->execute() + ); } /** - * @dataProvider dataProviderForExecute + * @dataProvider testExecuteDataProvider */ - public function testExecuteNoInvoice($invoice) + public function testExecute($invoice) { + $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') + ->disableOriginalConstructor() + ->getMock(); + $blockMock = $this->getMockBuilder('Magento\Sales\Block\Adminhtml\Order\Creditmemo\View') + ->disableOriginalConstructor() + ->getMock(); + $this->requestMock->expects($this->any()) ->method('getParam') ->withAnyParameters() @@ -226,41 +249,34 @@ public function testExecuteNoInvoice($invoice) $this->creditmemoMock->expects($this->any()) ->method('getInvoice') ->willReturn($invoice); - - $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $blockMock = $this->getMockBuilder('Magento\Sales\Block\Adminhtml\Order\Creditmemo\View') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $blockMenuMock = $this->getMockBuilder('Magento\Backend\Block\Menu') - ->disableOriginalConstructor() - ->setMethods(['getMenuModel', 'setActive', 'getParentItems']) - ->getMock(); - $blockMenuMock->expects($this->any()) - ->method('getMenuModel') - ->willReturnSelf(); - $blockMenuMock->expects($this->any()) - ->method('getParentItems') - ->willReturn([]); - $layoutMock->expects($this->at(0)) + $layoutMock->expects($this->once()) ->method('getBlock') ->with('sales_creditmemo_view') ->willReturn($blockMock); - $layoutMock->expects($this->at(1)) - ->method('getBlock') - ->with('menu') - ->willReturn($blockMenuMock); - $this->viewMock->expects($this->any()) + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultPageMock); + $this->resultPageMock->expects($this->atLeastOnce()) ->method('getLayout') ->willReturn($layoutMock); + $this->resultPageMock->expects($this->once()) + ->method('setActiveMenu') + ->with('Magento_Sales::sales_creditmemo') + ->willReturnSelf(); + $this->resultPageMock->expects($this->atLeastOnce()) + ->method('getConfig') + ->willReturn($this->pageConfigMock); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Page', + $this->controller->execute() + ); } - public function dataProviderForExecute() + /** + * @return array + */ + public function testExecuteDataProvider() { return [ [false], diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/VoidTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/VoidTest.php index 95b130bdab348..3e3a946061881 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/VoidTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/VoidTest.php @@ -7,6 +7,7 @@ /** * Class VoidTest + * @SuppressWarnings(PHPMD.TooManyFields) */ class VoidTest extends \PHPUnit_Framework_TestCase { @@ -45,11 +46,6 @@ class VoidTest extends \PHPUnit_Framework_TestCase */ protected $objectManagerMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $viewMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -75,6 +71,26 @@ class VoidTest extends \PHPUnit_Framework_TestCase */ protected $helperMock; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectMock; + + /** + * @var \Magento\Backend\Model\View\Result\Forward|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardMock; + public function setUp() { $this->creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') @@ -83,41 +99,50 @@ public function setUp() ->getMock(); $titleMock = $this->getMockBuilder('Magento\Framework\App\Action\Title') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->viewMock = $this->getMockBuilder('Magento\Backend\Model\View') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->helperMock = $this->getMockBuilder('Magento\Backend\Helper\Data') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\Manager') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->sessionMock = $this->getMockBuilder('Magento\Backend\Model\Session') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); $this->contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); + $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') + ->disableOriginalConstructor() + ->getMock(); + $this->senderMock = $this->getMockBuilder('Magento\Sales\Model\Order\Email\Sender\CreditmemoSender') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock->expects($this->any()) ->method('getRequest') ->will($this->returnValue($this->requestMock)); @@ -139,23 +164,19 @@ public function setUp() $this->contextMock->expects($this->any()) ->method('getTitle') ->will($this->returnValue($titleMock)); - $this->contextMock->expects($this->any()) - ->method('getView') - ->will($this->returnValue($this->viewMock)); $this->contextMock->expects($this->any()) ->method('getMessageManager') ->will($this->returnValue($this->messageManagerMock)); - $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->senderMock = $this->getMockBuilder('Magento\Sales\Model\Order\Email\Sender\CreditmemoSender') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->controller = new \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Void( - $this->contextMock, - $this->loaderMock + + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->controller = $objectManager->getObject( + 'Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Void', + [ + 'context' => $this->contextMock, + 'creditmemoLoader' => $this->loaderMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock, + 'resultForwardFactory' => $this->resultForwardFactoryMock + ] ); } @@ -168,12 +189,23 @@ public function testExecuteNoCreditmemo() $this->loaderMock->expects($this->once()) ->method('load') ->willReturn(false); + $this->resultForwardFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultForwardMock); + $this->resultForwardMock->expects($this->once()) + ->method('forward') + ->with('noroute') + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Forward', + $this->controller->execute() + ); } public function testExecuteModelException() { + $id = 123; $message = 'Model exception'; $e = new \Magento\Framework\Model\Exception($message); @@ -187,12 +219,26 @@ public function testExecuteModelException() $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($this->creditmemoMock); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->creditmemoMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn($id); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/view', ['creditmemo_id' => $id]) + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->controller->execute() + ); } public function testExecuteException() { + $id = 321; $message = 'Model exception'; $e = new \Exception($message); @@ -206,12 +252,37 @@ public function testExecuteException() $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($this->creditmemoMock); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->creditmemoMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn($id); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/view', ['creditmemo_id' => $id]) + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->controller->execute() + ); } public function testExecute() { + $id = '111'; + + $transactionMock = $this->getMockBuilder('Magento\Framework\DB\Transaction') + ->disableOriginalConstructor() + ->getMock(); + $orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') + ->disableOriginalConstructor() + ->getMock(); + $invoiceMock = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice') + ->disableOriginalConstructor() + ->getMock(); + $this->requestMock->expects($this->any()) ->method('getParam') ->withAnyParameters() @@ -219,32 +290,33 @@ public function testExecute() $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($this->creditmemoMock); - $transactionMock = $this->getMockBuilder('Magento\Framework\DB\Transaction') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Framework\DB\Transaction') ->willReturn($transactionMock); - $orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->creditmemoMock->expects($this->any()) ->method('getOrder') ->willReturn($orderMock); - $invoiceMock = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); $this->creditmemoMock->expects($this->any()) ->method('getInvoice') ->willReturn($invoiceMock); $this->messageManagerMock->expects($this->once()) ->method('addSuccess') ->with('You voided the credit memo.'); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->creditmemoMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn($id); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/view', ['creditmemo_id' => $id]) + ->willReturnSelf(); - $this->assertNull($this->controller->execute()); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->controller->execute() + ); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/EmailTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/EmailTest.php index 3efd02b3891c3..132f2c1734804 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/EmailTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/EmailTest.php @@ -26,6 +26,11 @@ class EmailTest extends \PHPUnit_Framework_TestCase */ protected $context; + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirect; + /** * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -80,6 +85,13 @@ public function setUp() '', false ); + $resultRedirectFactory = $this->getMock( + 'Magento\Backend\Model\View\Result\RedirectFactory', + ['create'], + [], + '', + false + ); $this->response = $this->getMock( 'Magento\Framework\App\ResponseInterface', ['setRedirect', 'sendResponse'], @@ -132,10 +144,14 @@ public function setUp() $this->context->expects($this->once()) ->method('getHelper') ->will($this->returnValue($this->helper)); + $this->resultRedirect = $this->getMock('Magento\Backend\Model\View\Result\Redirect', [], [], '', false); + $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect); + $this->orderEmail = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Email', [ 'context' => $this->context, + 'resultRedirectFactory' => $resultRedirectFactory, 'request' => $this->request, 'response' => $this->response ] @@ -175,11 +191,15 @@ public function testEmail() $this->messageManager->expects($this->once()) ->method('addSuccess') ->with('You sent the order email.'); - $path = 'sales/order/view'; - $arguments = ['order_id' => $orderId]; - $this->prepareRedirect($path, $arguments, 0); - - $this->orderEmail->execute(); + $this->resultRedirect->expects($this->once()) + ->method('setPath') + ->with('sales/order/view', ['order_id' => $orderId]) + ->willReturnSelf(); + + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->orderEmail->execute() + ); $this->assertEquals($this->response, $this->orderEmail->getResponse()); } @@ -208,34 +228,14 @@ public function testEmailNoOrderId() ->method('set') ->with('', 'no-dispatch', true) ->will($this->returnValue(true)); - $path = 'sales/*/'; - $this->prepareRedirect($path, [], 0); - - $this->assertNull($this->orderEmail->execute()); - } - - /** - * @param string $path - * @param array $arguments - * @param int $index - */ - protected function prepareRedirect($path, $arguments, $index) - { - $this->actionFlag->expects($this->any()) - ->method('get') - ->with('', 'check_url_settings') - ->will($this->returnValue(true)); - $this->session->expects($this->any()) - ->method('setIsUrlNotice') - ->with(true); - - $url = $path . '/' . (!empty($arguments) ? $arguments['order_id'] : ''); - $this->helper->expects($this->at($index)) - ->method('getUrl') - ->with($path, $arguments) - ->will($this->returnValue($url)); - $this->response->expects($this->at($index)) - ->method('setRedirect') - ->with($url); + $this->resultRedirect->expects($this->once()) + ->method('setPath') + ->with('sales/*/') + ->willReturnSelf(); + + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->orderEmail->execute() + ); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddCommentTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddCommentTest.php old mode 100644 new mode 100755 index a2c4b17b716ee..112369e7e3ac8 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddCommentTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddCommentTest.php @@ -59,6 +59,26 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase */ protected $controller; + /** + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultPageFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\JSONFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultJsonFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRawFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultJsonMock; + public function setUp() { $objectManager = new ObjectManager($this); @@ -121,6 +141,26 @@ public function setUp() ->method('getTitle') ->willReturn($this->pageTitleMock); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $this->resultRawFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\RawFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultJsonFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSONFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->commentSenderMock = $this->getMockBuilder('Magento\Sales\Model\Order\Email\Sender\InvoiceCommentSender') ->disableOriginalConstructor() ->setMethods([]) @@ -129,7 +169,10 @@ public function setUp() 'Magento\Sales\Controller\Adminhtml\Order\Invoice\AddComment', [ 'context' => $contextMock, - 'invoiceCommentSender' => $this->commentSenderMock + 'invoiceCommentSender' => $this->commentSenderMock, + 'resultPageFactory' => $this->resultPageFactoryMock, + 'resultRawFactory' => $this->resultRawFactoryMock, + 'resultJsonFactory' => $this->resultJsonFactoryMock ] ); } @@ -190,7 +233,11 @@ public function testExecute() ->with('invoice_comments') ->will($this->returnValue($commentsBlockMock)); - $this->viewMock->expects($this->any()) + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($this->resultPageMock)); + + $this->resultPageMock->expects($this->any()) ->method('getLayout') ->will($this->returnValue($layoutMock)); @@ -198,11 +245,14 @@ public function testExecute() ->method('send') ->with($invoiceMock, false, $data['comment']); - $this->responseMock->expects($this->once()) - ->method('setBody') - ->with($response); + $resultRaw = $this->getMockBuilder('Magento\Framework\Controller\Result\Raw') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRaw->expects($this->once())->method('setContents')->with($response); - $this->assertNull($this->controller->execute()); + $this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw)); + $this->assertSame($resultRaw, $this->controller->execute()); } public function testExecuteModelException() @@ -215,24 +265,12 @@ public function testExecuteModelException() ->method('getParam') ->will($this->throwException($e)); - $helperMock = $this->getMockBuilder('Magento\Core\Helper\Data') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $helperMock->expects($this->once()) - ->method('jsonEncode') - ->with($response) - ->will($this->returnValue(json_encode($response))); - - $this->responseMock->expects($this->once()) - ->method('representJson') - ->with(json_encode($response)); + $this->resultJsonFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($this->resultJsonMock)); - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Magento\Core\Helper\Data') - ->will($this->returnValue($helperMock)); - $this->assertNull($this->controller->execute()); + $this->resultJsonMock->expects($this->once())->method('setData')->with($response); + $this->assertSame($this->resultJsonMock, $this->controller->execute()); } public function testExecuteException() @@ -244,24 +282,11 @@ public function testExecuteException() ->method('getParam') ->will($this->throwException($e)); - $helperMock = $this->getMockBuilder('Magento\Core\Helper\Data') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $helperMock->expects($this->once()) - ->method('jsonEncode') - ->with($response) - ->will($this->returnValue(json_encode($response))); - - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Magento\Core\Helper\Data') - ->will($this->returnValue($helperMock)); - - $this->responseMock->expects($this->once()) - ->method('representJson') - ->with(json_encode($response)); + $this->resultJsonFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($this->resultJsonMock)); - $this->assertNull($this->controller->execute()); + $this->resultJsonMock->expects($this->once())->method('setData')->with($response); + $this->assertSame($this->resultJsonMock, $this->controller->execute()); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/CancelTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/CancelTest.php old mode 100644 new mode 100755 index 673f0fef35180..630b5c1f39b2e --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/CancelTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/CancelTest.php @@ -49,6 +49,16 @@ class CancelTest extends \PHPUnit_Framework_TestCase */ protected $helperMock; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactoryMock; + /** * @var \Magento\Sales\Controller\Adminhtml\Order\Invoice\Cancel */ @@ -115,9 +125,23 @@ public function setUp() ->method('getHelper') ->will($this->returnValue($this->helperMock)); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\Cancel', - ['context' => $contextMock] + [ + 'context' => $contextMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock, + 'resultForwardFactory' => $this->resultForwardFactoryMock + ] ); } @@ -176,8 +200,21 @@ public function testExecute() $invoiceMock->expects($this->once()) ->method('load') ->willReturnSelf(); + $invoiceMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($invoiceId)); + + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); - $this->assertNull($this->controller->execute()); + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultRedirect)); + + $this->assertSame($resultRedirect, $this->controller->execute()); } public function testExecuteNoInvoice() @@ -201,7 +238,17 @@ public function testExecuteNoInvoice() ->with('Magento\Sales\Model\Order\Invoice') ->willReturn($invoiceMock); - $this->assertNull($this->controller->execute()); + $resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultForward->expects($this->once())->method('forward')->with(('noroute'))->will($this->returnSelf()); + + $this->resultForwardFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultForward)); + + $this->assertSame($resultForward, $this->controller->execute()); } public function testExecuteModelException() @@ -231,12 +278,26 @@ public function testExecuteModelException() $invoiceMock->expects($this->once()) ->method('load') ->willReturnSelf(); + $invoiceMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($invoiceId)); + $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Sales\Model\Order\Invoice') ->willReturn($invoiceMock); - $this->assertNull($this->controller->execute()); + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); + + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultRedirect)); + + $this->assertSame($resultRedirect, $this->controller->execute()); } public function testExecuteException() @@ -266,10 +327,25 @@ public function testExecuteException() $invoiceMock->expects($this->once()) ->method('load') ->willReturnSelf(); + $invoiceMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($invoiceId)); + $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Sales\Model\Order\Invoice') ->willReturn($invoiceMock); - $this->assertNull($this->controller->execute()); + + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); + + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultRedirect)); + + $this->assertSame($resultRedirect, $this->controller->execute()); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/CaptureTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/CaptureTest.php old mode 100644 new mode 100755 index 1ae9e2627ffd7..e8a5fb0e7872d --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/CaptureTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/CaptureTest.php @@ -49,6 +49,16 @@ class CaptureTest extends \PHPUnit_Framework_TestCase */ protected $helperMock; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactoryMock; + /** * @var \Magento\Sales\Controller\Adminhtml\Order\Invoice\Capture */ @@ -115,9 +125,23 @@ public function setUp() ->method('getHelper') ->will($this->returnValue($this->helperMock)); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\Capture', - ['context' => $contextMock] + [ + 'context' => $contextMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock, + 'resultForwardFactory' => $this->resultForwardFactoryMock + ] ); } @@ -167,6 +191,9 @@ public function testExecute() $invoiceMock->expects($this->once()) ->method('load') ->willReturnSelf(); + $invoiceMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($invoiceId)); $this->objectManagerMock->expects($this->at(0)) ->method('create') @@ -178,7 +205,17 @@ public function testExecute() ->with('Magento\Framework\DB\Transaction') ->will($this->returnValue($transactionMock)); - $this->assertNull($this->controller->execute()); + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); + + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultRedirect)); + + $this->assertSame($resultRedirect, $this->controller->execute()); } public function testExecuteNoInvoice() @@ -202,7 +239,17 @@ public function testExecuteNoInvoice() ->with('Magento\Sales\Model\Order\Invoice') ->willReturn($invoiceMock); - $this->assertNull($this->controller->execute()); + $resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultForward->expects($this->once())->method('forward')->with(('noroute'))->will($this->returnSelf()); + + $this->resultForwardFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultForward)); + + $this->assertSame($resultForward, $this->controller->execute()); } public function testExecuteModelException() @@ -232,12 +279,26 @@ public function testExecuteModelException() $invoiceMock->expects($this->once()) ->method('load') ->willReturnSelf(); + $invoiceMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($invoiceId)); + $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Sales\Model\Order\Invoice') ->willReturn($invoiceMock); - $this->assertNull($this->controller->execute()); + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); + + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultRedirect)); + + $this->assertSame($resultRedirect, $this->controller->execute()); } public function testExecuteException() @@ -267,11 +328,25 @@ public function testExecuteException() $invoiceMock->expects($this->once()) ->method('load') ->willReturnSelf(); + $invoiceMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($invoiceId)); + $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Sales\Model\Order\Invoice') ->willReturn($invoiceMock); - $this->assertNull($this->controller->execute()); + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); + + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultRedirect)); + + $this->assertSame($resultRedirect, $this->controller->execute()); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewActionTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewActionTest.php old mode 100644 new mode 100755 index 2d14e61f9deb9..6d06bf0d76155 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewActionTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewActionTest.php @@ -10,6 +10,7 @@ /** * Class NewActionTest * @package Magento\Sales\Controller\Adminhtml\Order\Invoice + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ class NewActionTest extends \PHPUnit_Framework_TestCase { @@ -49,7 +50,7 @@ class NewActionTest extends \PHPUnit_Framework_TestCase protected $sessionMock; /** - * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */ protected $resultPageMock; @@ -73,6 +74,17 @@ class NewActionTest extends \PHPUnit_Framework_TestCase */ protected $messageManagerMock; + /** + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultPageFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactoryMock; + + public function setUp() { $objectManager = new ObjectManager($this); @@ -112,8 +124,9 @@ public function setUp() ->disableOriginalConstructor() ->setMethods(['getCommentText', 'setIsUrlNotice']) ->getMock(); - $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') + $this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') ->disableOriginalConstructor() + ->setMethods([]) ->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') ->disableOriginalConstructor() @@ -166,9 +179,23 @@ public function setUp() ->method('getTitle') ->willReturn($this->pageTitleMock); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\NewAction', - ['context' => $contextMock] + [ + 'context' => $contextMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock, + 'resultPageFactory' => $this->resultPageFactoryMock + ] ); } @@ -230,19 +257,6 @@ public function testExecute() ->with('Magento_Sales::sales_order') ->will($this->returnValue([])); - $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $layoutMock->expects($this->once()) - ->method('getBlock') - ->with('menu') - ->will($this->returnValue($menuBlockMock)); - - $this->viewMock->expects($this->once()) - ->method('getLayout') - ->will($this->returnValue($layoutMock)); - $this->sessionMock->expects($this->once()) ->method('getCommentText') ->with(true) @@ -261,7 +275,12 @@ public function testExecute() ->with('Magento\Backend\Model\Session') ->will($this->returnValue($this->sessionMock)); - $this->assertNull($this->controller->execute()); + $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order'); + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($this->resultPageMock)); + + $this->assertSame($this->resultPageMock, $this->controller->execute()); } public function testExecuteNoOrder() @@ -295,6 +314,16 @@ public function testExecuteNoOrder() ->with('Magento\Sales\Model\Order') ->willReturn($orderMock); - $this->assertNull($this->controller->execute()); + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRedirect->expects($this->once())->method('setPath')->with('sales/order/view', ['order_id' => $orderId]); + + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultRedirect)); + + $this->assertSame($resultRedirect, $this->controller->execute()); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQtyTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQtyTest.php old mode 100644 new mode 100755 index c72414684787d..ebaa13ef3b552 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQtyTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQtyTest.php @@ -55,6 +55,21 @@ class UpdateQtyTest extends \PHPUnit_Framework_TestCase */ protected $controller; + /** + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultPageFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRawFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\JSONFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultJsonFactoryMock; + public function setUp() { $objectManager = new ObjectManager($this); @@ -69,8 +84,8 @@ public function setUp() $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Response\Http') ->disableOriginalConstructor() ->getMock(); - $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') - ->setMethods(['getConfig']) + $this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') + ->setMethods([]) ->disableOriginalConstructor() ->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') @@ -110,10 +125,28 @@ public function setUp() ->method('getObjectManager') ->will($this->returnValue($this->objectManagerMock)); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultRawFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\RawFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultJsonFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSONFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\UpdateQty', [ - 'context' => $contextMock + 'context' => $contextMock, + 'resultPageFactory' => $this->resultPageFactoryMock, + 'resultRawFactory' => $this->resultRawFactoryMock, + 'resultJsonFactory' => $this->resultJsonFactoryMock ] ); } @@ -173,10 +206,6 @@ public function testExecute() ->with('Magento\Sales\Model\Service\Order') ->willReturn($orderService); - $this->responseMock->expects($this->once()) - ->method('setBody') - ->with($response); - $blockItemMock = $this->getMockBuilder('Magento\Sales\Block\Order\Items') ->disableOriginalConstructor() ->setMethods([]) @@ -193,16 +222,29 @@ public function testExecute() ->method('getBlock') ->with('order_items') ->will($this->returnValue($blockItemMock)); - $this->viewMock->expects($this->once())->method('getPage')->will($this->returnValue($this->resultPageMock)); - $this->viewMock->expects($this->once()) + + $this->resultPageMock->expects($this->once()) ->method('getLayout') ->will($this->returnValue($layoutMock)); - $this->resultPageMock->expects($this->once())->method('getConfig')->will( - $this->returnValue($this->pageConfigMock) - ); + $this->resultPageMock->expects($this->once()) + ->method('getConfig') + ->will($this->returnValue($this->pageConfigMock)); + $this->pageConfigMock->expects($this->once())->method('getTitle')->will($this->returnValue($this->titleMock)); - $this->assertNull($this->controller->execute()); + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($this->resultPageMock)); + + $resultRaw = $this->getMockBuilder('Magento\Framework\Controller\Result\Raw') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRaw->expects($this->once())->method('setContents')->with($response); + + $this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw)); + + $this->assertSame($resultRaw, $this->controller->execute()); } public function testExecuteModelException() @@ -229,25 +271,18 @@ public function testExecuteModelException() ->method('prepend') ->with('Invoices'); - $this->responseMock->expects($this->once()) - ->method('representJson') - ->with(json_encode($response)); - - $helperMock = $this->getMockBuilder('Magento\Core\Helper\Data') + /** @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */ + $resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); - $helperMock->expects($this->once()) - ->method('jsonEncode') - ->with($response) - ->will($this->returnValue(json_encode($response))); + $resultJsonMock->expects($this->once())->method('setData')->with($response); - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Magento\Core\Helper\Data') - ->will($this->returnValue($helperMock)); + $this->resultJsonFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultJsonMock)); - $this->assertNull($this->controller->execute()); + $this->assertSame($resultJsonMock, $this->controller->execute()); } public function testExecuteException() @@ -269,28 +304,22 @@ public function testExecuteException() ->method('create') ->with('Magento\Sales\Model\Order') ->willReturn($orderMock); + $this->titleMock->expects($this->never()) ->method('prepend') ->with('Invoices'); - $this->responseMock->expects($this->once()) - ->method('representJson') - ->with(json_encode($response)); - - $helperMock = $this->getMockBuilder('Magento\Core\Helper\Data') + /** @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */ + $resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\JSON') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); - $helperMock->expects($this->once()) - ->method('jsonEncode') - ->with($response) - ->will($this->returnValue(json_encode($response))); + $resultJsonMock->expects($this->once())->method('setData')->with($response); - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Magento\Core\Helper\Data') - ->will($this->returnValue($helperMock)); + $this->resultJsonFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultJsonMock)); - $this->assertNull($this->controller->execute()); + $this->assertSame($resultJsonMock, $this->controller->execute()); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/ViewTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/ViewTest.php old mode 100644 new mode 100755 index 81de94faae8b2..90a60f27b8811 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/ViewTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/ViewTest.php @@ -55,7 +55,7 @@ class ViewTest extends \PHPUnit_Framework_TestCase protected $objectManagerMock; /** - * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */ protected $resultPageMock; @@ -74,6 +74,16 @@ class ViewTest extends \PHPUnit_Framework_TestCase */ protected $controller; + /** + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultPageFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactoryMock; + public function setUp() { $objectManager = new ObjectManager($this); @@ -103,7 +113,7 @@ public function setUp() ->setMethods(['getCommentText', 'setIsUrlNotice']) ->getMock(); $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') + $this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') ->disableOriginalConstructor() ->getMock(); $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') @@ -148,10 +158,22 @@ public function setUp() ->method('getTitle') ->willReturn($this->pageTitleMock); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\View', [ - 'context' => $contextMock + 'context' => $contextMock, + 'resultPageFactory' => $this->resultPageFactoryMock, + 'resultForwardFactory' => $this->resultForwardFactoryMock ] ); } @@ -191,15 +213,11 @@ public function testExecute() ->setMethods([]) ->getMock(); $layoutMock->expects($this->at(0)) - ->method('getBlock') - ->with('menu') - ->will($this->returnValue($menuBlockMock)); - $layoutMock->expects($this->at(1)) ->method('getBlock') ->with('sales_invoice_view') ->will($this->returnValue($invoiceViewBlockMock)); - $this->viewMock->expects($this->any()) + $this->resultPageMock->expects($this->any()) ->method('getLayout') ->will($this->returnValue($layoutMock)); @@ -216,7 +234,13 @@ public function testExecute() ->with('Magento\Sales\Model\Order\Invoice') ->willReturn($invoiceMock); - $this->assertNull($this->controller->execute()); + $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order'); + + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($this->resultPageMock)); + + $this->assertSame($this->resultPageMock, $this->controller->execute()); } public function testExecuteNoInvoice() @@ -240,6 +264,16 @@ public function testExecuteNoInvoice() ->with('Magento\Sales\Model\Order\Invoice') ->willReturn($invoiceMock); - $this->assertNull($this->controller->execute()); + $resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultForward->expects($this->once())->method('forward')->with(('noroute'))->will($this->returnSelf()); + + $this->resultForwardFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultForward)); + + $this->assertSame($resultForward, $this->controller->execute()); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/VoidTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/VoidTest.php old mode 100644 new mode 100755 index c42a43faf4766..46191ce57cb5c --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/VoidTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/VoidTest.php @@ -59,6 +59,16 @@ class VoidTest extends \PHPUnit_Framework_TestCase */ protected $controller; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultForwardFactoryMock; + public function setUp() { $objectManager = new ObjectManager($this); @@ -128,10 +138,22 @@ public function setUp() ->method('getHelper') ->will($this->returnValue($this->helperMock)); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\Void', [ - 'context' => $contextMock + 'context' => $contextMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock, + 'resultForwardFactory' => $this->resultForwardFactoryMock ] ); } @@ -163,6 +185,9 @@ public function testExecute() $invoiceMock->expects($this->any()) ->method('getOrder') ->will($this->returnValue($orderMock)); + $invoiceMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($invoiceId)); $transactionMock = $this->getMockBuilder('Magento\Framework\DB\Transaction') ->disableOriginalConstructor() @@ -192,7 +217,17 @@ public function testExecute() ->method('addSuccess') ->with('The invoice has been voided.'); - $this->controller->execute(); + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); + + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultRedirect)); + + $this->assertSame($resultRedirect, $this->controller->execute()); } public function testExecuteNoInvoice() @@ -222,7 +257,17 @@ public function testExecuteNoInvoice() $this->messageManagerMock->expects($this->never()) ->method('addSuccess'); - $this->controller->execute(); + $resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultForward->expects($this->once())->method('forward')->with(('noroute'))->will($this->returnSelf()); + + $this->resultForwardFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultForward)); + + $this->assertSame($resultForward, $this->controller->execute()); } public function testExecuteModelException() @@ -247,6 +292,9 @@ public function testExecuteModelException() $invoiceMock->expects($this->once()) ->method('void') ->will($this->throwException($e)); + $invoiceMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($invoiceId)); $this->objectManagerMock->expects($this->once()) ->method('create') @@ -255,6 +303,17 @@ public function testExecuteModelException() $this->messageManagerMock->expects($this->once()) ->method('addError'); - $this->controller->execute(); + + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $resultRedirect->expects($this->once())->method('setPath')->with('sales/*/view', ['invoice_id' => $invoiceId]); + + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($resultRedirect)); + + $this->assertSame($resultRedirect, $this->controller->execute()); } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/ViewTest.php b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/ViewTest.php index 7cf36ee77d2da..fa6993c204fc6 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/ViewTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Controller/Adminhtml/Order/ViewTest.php @@ -5,131 +5,340 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; -use Magento\Backend\App\Action; - /** - * Magento Adminhtml Order Controller Test + * @covers \Magento\Sales\Controller\Adminhtml\Order\View + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class ViewTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\TestFramework\Helper\ObjectManager + * @var \Magento\Sales\Controller\Adminhtml\Order\View + */ + protected $viewAction; + + /** + * @var \Magento\Backend\App\Action\Context + */ + protected $context; + + /** + * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $requestMock; + + /** + * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $objectManagerMock; + + /** + * @var \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderMock; + + /** + * @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $messageManagerMock; + + /** + * @var \Magento\Framework\App\ActionFlag|\PHPUnit_Framework_MockObject_MockObject + */ + protected $actionFlagMock; + + /** + * @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject + */ + protected $coreRegistryMock; + + /** + * @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject + */ + protected $pageConfigMock; + + /** + * @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject */ - protected $_objectHelper; + protected $pageTitleMock; /** - * Mock for \Magento\Sales\Model\Order - * - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $_orderMock; + protected $resultPageFactoryMock; /** - * Mock for \Magento\Framework\Message - * - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $_messageMock; + protected $resultRedirectFactoryMock; /** - * Mock for \Magento\Sales\Adminhtml\Controller\Order - * - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */ - protected $_controllerMock; + protected $resultPageMock; - protected $viewMock; + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectMock; /** - * setup mocks for all functions + * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $loggerMock; + public function setUp() { - $this->_objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this); - - $this->_orderMock = $this->getMockBuilder('\Magento\Sales\Model\Order') + $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') + ->getMock(); + $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + ->getMock(); + $this->orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() - ->setMethods(['__wakeup', 'getRealOrderId']) ->getMock(); - - $this->_messageMock = $this->getMockBuilder('\Magento\Framework\Message') + $this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\ManagerInterface') + ->getMock(); + $this->actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag') ->disableOriginalConstructor() - ->setMethods(['addError']) ->getMock(); - - $this->viewMock = $this->getMockForAbstractClass('\Magento\Framework\App\ViewInterface'); - - /** - * @TODO: - * - Methods of object under test MUST NOT be mocked - * - Protected properties MUST NOT be set from outside, inject via context passed to constructor instead - */ - $this->_controllerMock = $this->getMockBuilder('\Magento\Sales\Controller\Adminhtml\Order\View') + $this->coreRegistryMock = $this->getMockBuilder('Magento\Framework\Registry') + ->disableOriginalConstructor() + ->getMock(); + $this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config') + ->disableOriginalConstructor() + ->getMock(); + $this->pageTitleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title') + ->disableOriginalConstructor() + ->getMock(); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultPageMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Page') ->disableOriginalConstructor() - ->setMethods(['__wakeup', '_initOrder', '_initAction', '__', 'renderLayout', '_redirect']) ->getMock(); - $this->_controllerMock->expects($this->any())->method('__')->will($this->returnArgument(0)); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface') + ->getMock(); + + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->context = $objectManager->getObject( + 'Magento\Backend\App\Action\Context', + [ + 'request' => $this->requestMock, + 'objectManager' => $this->objectManagerMock, + 'actionFlag' => $this->actionFlagMock, + 'messageManager' => $this->messageManagerMock + ] + ); + $this->viewAction = $objectManager->getObject( + 'Magento\Sales\Controller\Adminhtml\Order\View', + [ + 'context' => $this->context, + 'coreRegistry' => $this->coreRegistryMock, + 'resultPageFactory' => $this->resultPageFactoryMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock + ] + ); + } + + /** + * @covers \Magento\Sales\Controller\Adminhtml\Order\View::execute + */ + public function testExecute() + { + $id = 111; + $titlePart = '#111'; + $this->initOrder(); + $this->initOrderSuccess($id); + $this->prepareRedirect(); + $this->initAction(); - $reflectionProperty = new \ReflectionProperty('\Magento\Sales\Controller\Adminhtml\Order', '_view'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($this->_controllerMock, $this->viewMock); - $reflectionProperty->setAccessible(false); + $this->resultPageMock->expects($this->atLeastOnce()) + ->method('getConfig') + ->willReturn($this->pageConfigMock); + $this->pageConfigMock->expects($this->atLeastOnce()) + ->method('getTitle') + ->willReturn($this->pageTitleMock); + $this->orderMock->expects($this->atLeastOnce()) + ->method('getRealOrderId') + ->willReturn($id); + $this->pageTitleMock->expects($this->exactly(2)) + ->method('prepend') + ->withConsecutive( + ['Orders'], + [$titlePart] + ) + ->willReturnSelf(); - $reflectionProperty = new \ReflectionProperty('\Magento\Sales\Controller\Adminhtml\Order', 'messageManager'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($this->_controllerMock, $this->_messageMock); - $reflectionProperty->setAccessible(false); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Page', + $this->viewAction->execute() + ); } /** - * This function checks if the error is added to session in case of ACTION_FLAG_PRODUCTS_PERMISSION_DENIED - * is set in Sales Order model + * @covers \Magento\Sales\Controller\Adminhtml\Order\View::execute */ - public function testViewActionWithError() + public function testExecuteNoOrder() { - $msg = 'You need more permissions to view this item.'; - $this->_messageMock->expects($this->once())->method('addError')->with($this->equalTo($msg)); - $this->_controllerMock->expects($this->once()) - ->method('_initOrder') - ->will($this->returnValue($this->_orderMock)); - $this->_controllerMock->expects($this->once()) - ->method('_initAction') - ->will($this->throwException(new \Magento\Framework\App\Action\Exception($msg))); - $this->_orderMock->expects($this->never())->method('getRealOrderId'); - - $this->_controllerMock->execute(); + $this->initOrder(); + $this->initOrderFail(); + $this->prepareRedirect(); + $this->setPath('sales/*/'); + + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->viewAction->execute() + ); } /** - * This function checks if the error is added to session in case of ACTION_FLAG_PRODUCTS_PERMISSION_DENIED - * is not set in Sales Order model + * @covers \Magento\Sales\Controller\Adminhtml\Order\View::execute */ - public function testViewActionWithoutError() + public function testExecuteException() { - $realOrderId = 1; - $this->_controllerMock->expects($this->once()) - ->method('_initOrder') - ->will($this->returnValue($this->_orderMock)); - $this->_messageMock->expects($this->never())->method('addError'); - $this->_orderMock->expects($this->once())->method('getRealOrderId')->will($this->returnValue($realOrderId)); - - $pageTitle = $this->getMockBuilder('Magento\Framework\View\Page\Title') - ->disableOriginalConstructor() - ->getMock(); - $pageConfig = $this->getMockBuilder('Magento\Framework\View\Page\Config') - ->disableOriginalConstructor() - ->setMethods(['getTitle']) - ->getMock(); - $pageConfig->expects($this->atLeastOnce())->method('getTitle')->willReturn($pageTitle); - $resultPage = $this->getMockBuilder('Magento\Framework\View\Result\Page') - ->disableOriginalConstructor() - ->setMethods(['getConfig']) - ->getMock(); - $resultPage->expects($this->atLeastOnce())->method('getConfig')->willReturn($pageConfig); - $this->viewMock->expects($this->atLeastOnce())->method('getPage')->willReturn($resultPage); + $id = 111; + $message = 'epic fail'; + $exception = new \Magento\Framework\App\Action\Exception($message); + $this->initOrder(); + $this->initOrderSuccess($id); + $this->prepareRedirect(); + + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->willThrowException($exception); + $this->messageManagerMock->expects($this->once()) + ->method('addError') + ->with($message) + ->willReturnSelf(); + $this->setPath('sales/order/index'); + + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->viewAction->execute() + ); + } + + /** + * @covers \Magento\Sales\Controller\Adminhtml\Order\View::execute + */ + public function testGlobalException() + { + $id = 111; + $exception = new \Exception(); + $this->initOrder(); + $this->initOrderSuccess($id); + $this->prepareRedirect(); + + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->willThrowException($exception); + $this->objectManagerMock->expects($this->once()) + ->method('get') + ->with('Psr\Log\LoggerInterface') + ->willReturn($this->loggerMock); + $this->loggerMock->expects($this->once()) + ->method('critical') + ->with($exception); + $this->messageManagerMock->expects($this->once()) + ->method('addError') + ->with('Exception occurred during order load') + ->willReturnSelf(); + $this->setPath('sales/order/index'); - $pageTitle->expects($this->at(0))->method('prepend')->with('Orders')->willReturnSelf(); - $pageTitle->expects($this->at(1))->method('prepend')->with('#' . $realOrderId)->willReturnSelf(); - $this->_controllerMock->execute(); + $this->assertInstanceOf( + 'Magento\Backend\Model\View\Result\Redirect', + $this->viewAction->execute() + ); + } + + protected function initOrder() + { + $orderIdParam = 111; + + $this->requestMock->expects($this->atLeastOnce()) + ->method('getParam') + ->with('order_id') + ->willReturn($orderIdParam); + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with('Magento\Sales\Model\Order') + ->willReturn($this->orderMock); + $this->orderMock->expects($this->once()) + ->method('load') + ->with($orderIdParam) + ->willReturnSelf(); + } + + /** + * @param int $orderId + */ + protected function initOrderSuccess($orderId) + { + $this->orderMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn($orderId); + $this->coreRegistryMock->expects($this->exactly(2)) + ->method('register') + ->withConsecutive( + ['sales_order', $this->orderMock], + ['current_order', $this->orderMock] + ); + } + + protected function initOrderFail() + { + $this->orderMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn(null); + $this->messageManagerMock->expects($this->once()) + ->method('addError') + ->with('This order no longer exists.') + ->willReturnSelf(); + $this->actionFlagMock->expects($this->once()) + ->method('set') + ->with('', \Magento\Sales\Controller\Adminhtml\Order::FLAG_NO_DISPATCH, true); + } + + protected function initAction() + { + $this->resultPageFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultPageMock); + $this->resultPageMock->expects($this->once()) + ->method('setActiveMenu') + ->with('Magento_Sales::sales_order') + ->willReturnSelf(); + $this->resultPageMock->expects($this->exactly(2)) + ->method('addBreadcrumb') + ->withConsecutive( + ['Sales', 'Sales'], + ['Orders', 'Orders'] + ) + ->willReturnSelf(); + } + + protected function prepareRedirect() + { + $this->resultRedirectFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirectMock); + } + + /** + * @param string $path + * @param array $params + */ + protected function setPath($path, $params = []) + { + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with($path, $params); } } diff --git a/lib/internal/Magento/Framework/App/Response/Http/FileFactory.php b/lib/internal/Magento/Framework/App/Response/Http/FileFactory.php index 539448a1baa35..bfe5cf299d5c3 100644 --- a/lib/internal/Magento/Framework/App/Response/Http/FileFactory.php +++ b/lib/internal/Magento/Framework/App/Response/Http/FileFactory.php @@ -73,33 +73,13 @@ public function create( } } - $this->_response->setHttpResponseCode( - 200 - )->setHeader( - 'Pragma', - 'public', - true - )->setHeader( - 'Cache-Control', - 'must-revalidate, post-check=0, pre-check=0', - true - )->setHeader( - 'Content-type', - $contentType, - true - )->setHeader( - 'Content-Length', - is_null($contentLength) ? strlen($content) : $contentLength, - true - )->setHeader( - 'Content-Disposition', - 'attachment; filename="' . $fileName . '"', - true - )->setHeader( - 'Last-Modified', - date('r'), - true - ); + $this->_response->setHttpResponseCode(200) + ->setHeader('Pragma', 'public', true) + ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true) + ->setHeader('Content-type', $contentType, true) + ->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true) + ->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true) + ->setHeader('Last-Modified', date('r'), true); if (!is_null($content)) { if ($isFile) {