Skip to content

Commit 611b453

Browse files
author
Kovsher, Iurii(ikovsher)
committed
Merge pull request #289 from magento-tango/MAGETWO-37436
[Tango] S52 Controller Refactoring, Bug Fixes
2 parents e98a487 + c183a1c commit 611b453

File tree

72 files changed

+1440
-1174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1440
-1174
lines changed

app/code/Magento/Developer/Model/View/Layout/Plugin.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

app/code/Magento/Developer/etc/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<type name="Magento\Framework\View\TemplateEngineFactory">
1111
<plugin name="debug_hints" type="Magento\Developer\Model\TemplateEngine\Plugin\DebugHints" sortOrder="10"/>
1212
</type>
13-
<type name="Magento\Framework\View\Layout">
14-
<plugin name="exception_handler" type="Magento\Developer\Model\View\Layout\Plugin" sortOrder="10"/>
15-
</type>
1613
<type name="Magento\Framework\View\Result\Page">
1714
<arguments>
1815
<argument name="pageConfigRendererFactory" xsi:type="object">Magento\Developer\Model\View\Page\Config\RendererFactory</argument>

app/code/Magento/GroupedProduct/Controller/Adminhtml/Edit/Popup.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<?php
22
/**
3-
*
43
* Copyright © 2015 Magento. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\GroupedProduct\Controller\Adminhtml\Edit;
87

9-
class Popup extends \Magento\Backend\App\AbstractAction
8+
use Magento\Backend\App\AbstractAction;
9+
use Magento\Backend\App\Action\Context;
10+
use Magento\Framework\Registry;
11+
use Magento\Catalog\Model\ProductFactory;
12+
use Psr\Log\LoggerInterface;
13+
use Magento\Framework\Controller\ResultFactory;
14+
15+
class Popup extends AbstractAction
1016
{
1117
/**
1218
* @var \Magento\Framework\Registry
@@ -30,10 +36,10 @@ class Popup extends \Magento\Backend\App\AbstractAction
3036
* @param \Psr\Log\LoggerInterface $logger
3137
*/
3238
public function __construct(
33-
\Magento\Backend\App\Action\Context $context,
34-
\Magento\Framework\Registry $registry,
35-
\Magento\Catalog\Model\ProductFactory $factory,
36-
\Psr\Log\LoggerInterface $logger
39+
Context $context,
40+
Registry $registry,
41+
ProductFactory $factory,
42+
LoggerInterface $logger
3743
) {
3844
$this->registry = $registry;
3945
$this->factory = $factory;
@@ -54,7 +60,7 @@ protected function _isAllowed()
5460
/**
5561
* Get associated grouped products grid popup
5662
*
57-
* @return void
63+
* @return \Magento\Framework\View\Result\Layout
5864
*/
5965
public function execute()
6066
{
@@ -84,8 +90,8 @@ public function execute()
8490
$product->setAttributeSetId($setId);
8591
}
8692
$this->registry->register('current_product', $product);
87-
88-
$this->_view->loadLayout(false);
89-
$this->_view->renderLayout();
93+
/** @var \Magento\Framework\View\Result\Layout $resultLayout */
94+
$resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
95+
return $resultLayout;
9096
}
9197
}

app/code/Magento/GroupedProduct/Test/Unit/Controller/Adminhtml/Edit/PopupTest.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\GroupedProduct\Test\Unit\Controller\Adminhtml\Edit;
77

8+
use Magento\Framework\Controller\ResultFactory;
9+
810
class PopupTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -17,6 +19,11 @@ class PopupTest extends \PHPUnit_Framework_TestCase
1719
*/
1820
protected $action;
1921

22+
/**
23+
* @var \Magento\Backend\App\Action\Context
24+
*/
25+
protected $context;
26+
2027
/**
2128
* @var \PHPUnit_Framework_MockObject_MockObject
2229
*/
@@ -33,25 +40,46 @@ class PopupTest extends \PHPUnit_Framework_TestCase
3340
protected $registry;
3441

3542
/**
36-
* @var \PHPUnit_Framework_MockObject_MockObject
43+
* @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject
44+
*/
45+
protected $resultFactoryMock;
46+
47+
/**
48+
* @var \Magento\Framework\View\Result\Layout|\PHPUnit_Framework_MockObject_MockObject
3749
*/
38-
protected $view;
50+
protected $resultLayoutMock;
3951

4052
protected function setUp()
4153
{
4254
$this->request = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false);
4355
$this->factory = $this->getMock('Magento\Catalog\Model\ProductFactory', ['create'], [], '', false);
4456
$this->registry = $this->getMock('Magento\Framework\Registry', [], [], '', false);
45-
$this->view = $this->getMock('Magento\Framework\App\ViewInterface', [], [], '', false);
57+
$this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory')
58+
->disableOriginalConstructor()
59+
->getMock();
60+
$this->resultLayoutMock = $this->getMockBuilder('Magento\Framework\View\Result\Layout')
61+
->disableOriginalConstructor()
62+
->getMock();
63+
64+
$this->resultFactoryMock->expects($this->any())
65+
->method('create')
66+
->with(ResultFactory::TYPE_LAYOUT, [])
67+
->willReturn($this->resultLayoutMock);
4668

4769
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
70+
$this->context = $this->objectManager->getObject(
71+
'Magento\Backend\App\Action\Context',
72+
[
73+
'request' => $this->request,
74+
'resultFactory' => $this->resultFactoryMock
75+
]
76+
);
4877
$this->action = $this->objectManager->getObject(
4978
'Magento\GroupedProduct\Controller\Adminhtml\Edit\Popup',
5079
[
51-
'request' => $this->request,
80+
'context' => $this->context,
5281
'factory' => $this->factory,
53-
'registry' => $this->registry,
54-
'view' => $this->view
82+
'registry' => $this->registry
5583
]
5684
);
5785
}
@@ -90,10 +118,7 @@ public function testPopupActionNoProductId()
90118
$this->request->expects($this->at(3))->method('getParam')->with('set')->will($this->returnValue($setId));
91119
$this->registry->expects($this->once())->method('register')->with('current_product', $product);
92120

93-
$this->view->expects($this->once())->method('loadLayout')->with(false);
94-
$this->view->expects($this->once())->method('renderLayout');
95-
96-
$this->action->execute();
121+
$this->assertSame($this->resultLayoutMock, $this->action->execute());
97122
}
98123

99124
public function testPopupActionWithProductIdNoSetId()
@@ -130,9 +155,6 @@ public function testPopupActionWithProductIdNoSetId()
130155
$this->request->expects($this->at(3))->method('getParam')->with('set')->will($this->returnValue($setId));
131156
$this->registry->expects($this->once())->method('register')->with('current_product', $product);
132157

133-
$this->view->expects($this->once())->method('loadLayout')->with(false);
134-
$this->view->expects($this->once())->method('renderLayout');
135-
136-
$this->action->execute();
158+
$this->assertSame($this->resultLayoutMock, $this->action->execute());
137159
}
138160
}

app/code/Magento/ImportExport/Controller/Adminhtml/Export.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
namespace Magento\ImportExport\Controller\Adminhtml;
7+
8+
use Magento\Backend\App\Action;
69

710
/**
811
* Export controller
9-
*
10-
* @author Magento Core Team <core@magentocommerce.com>
1112
*/
12-
namespace Magento\ImportExport\Controller\Adminhtml;
13-
14-
class Export extends \Magento\Backend\App\Action
13+
class Export extends Action
1514
{
1615
/**
1716
* Check access (in the ACL) for current user
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,57 @@
11
<?php
22
/**
3-
*
43
* Copyright © 2015 Magento. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\ImportExport\Controller\Adminhtml\Export;
87

8+
use Magento\Framework\Controller\ResultFactory;
9+
use Magento\ImportExport\Controller\Adminhtml\Export as ExportController;
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Framework\App\Response\Http\FileFactory;
12+
use Magento\ImportExport\Model\Export as ExportModel;
913
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\Exception\LocalizedException;
1015

11-
class Export extends \Magento\ImportExport\Controller\Adminhtml\Export
16+
class Export extends ExportController
1217
{
1318
/**
1419
* @var \Magento\Framework\App\Response\Http\FileFactory
1520
*/
16-
protected $_fileFactory;
21+
protected $fileFactory;
1722

1823
/**
1924
* @param \Magento\Backend\App\Action\Context $context
2025
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
2126
*/
2227
public function __construct(
23-
\Magento\Backend\App\Action\Context $context,
24-
\Magento\Framework\App\Response\Http\FileFactory $fileFactory
28+
Context $context,
29+
FileFactory $fileFactory
2530
) {
26-
$this->_fileFactory = $fileFactory;
31+
$this->fileFactory = $fileFactory;
2732
parent::__construct($context);
2833
}
2934

3035
/**
3136
* Load data with filter applying and create file for download.
3237
*
33-
* @return $this
38+
* @return \Magento\Backend\Model\View\Result\Redirect
3439
*/
3540
public function execute()
3641
{
37-
if ($this->getRequest()->getPost(\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP)) {
42+
if ($this->getRequest()->getPost(ExportModel::FILTER_ELEMENT_GROUP)) {
3843
try {
3944
/** @var $model \Magento\ImportExport\Model\Export */
4045
$model = $this->_objectManager->create('Magento\ImportExport\Model\Export');
4146
$model->setData($this->getRequest()->getParams());
4247

43-
return $this->_fileFactory->create(
48+
return $this->fileFactory->create(
4449
$model->getFileName(),
4550
$model->export(),
4651
DirectoryList::VAR_DIR,
4752
$model->getContentType()
4853
);
49-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
54+
} catch (LocalizedException $e) {
5055
$this->messageManager->addError($e->getMessage());
5156
} catch (\Exception $e) {
5257
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
@@ -55,6 +60,9 @@ public function execute()
5560
} else {
5661
$this->messageManager->addError(__('Please correct the data sent.'));
5762
}
58-
return $this->_redirect('adminhtml/*/index');
63+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
64+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
65+
$resultRedirect->setPath('adminhtml/*/index');
66+
return $resultRedirect;
5967
}
6068
}
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
<?php
22
/**
3-
*
43
* Copyright © 2015 Magento. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\ImportExport\Controller\Adminhtml\Export;
87

9-
class GetFilter extends \Magento\ImportExport\Controller\Adminhtml\Export
8+
use Magento\ImportExport\Controller\Adminhtml\Export as ExportController;
9+
use Magento\Framework\Controller\ResultFactory;
10+
11+
class GetFilter extends ExportController
1012
{
1113
/**
1214
* Get grid-filter of entity attributes action.
1315
*
14-
* @return void
16+
* @return \Magento\Framework\Controller\ResultInterface
1517
*/
1618
public function execute()
1719
{
1820
$data = $this->getRequest()->getParams();
1921
if ($this->getRequest()->isXmlHttpRequest() && $data) {
2022
try {
21-
$this->_view->loadLayout();
22-
23+
/** @var \Magento\Framework\View\Result\Layout $resultLayout */
24+
$resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
2325
/** @var $attrFilterBlock \Magento\ImportExport\Block\Adminhtml\Export\Filter */
24-
$attrFilterBlock = $this->_view->getLayout()->getBlock('export.filter');
26+
$attrFilterBlock = $resultLayout->getLayout()->getBlock('export.filter');
2527
/** @var $export \Magento\ImportExport\Model\Export */
2628
$export = $this->_objectManager->create('Magento\ImportExport\Model\Export');
2729
$export->setData($data);
2830

2931
$export->filterAttributeCollection(
3032
$attrFilterBlock->prepareCollection($export->getEntityAttributeCollection())
3133
);
32-
$this->_view->renderLayout();
33-
return;
34+
return $resultLayout;
3435
} catch (\Exception $e) {
3536
$this->messageManager->addError($e->getMessage());
3637
}
3738
} else {
3839
$this->messageManager->addError(__('Please correct the data sent.'));
3940
}
40-
$this->_redirect('adminhtml/*/index');
41+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
42+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
43+
$resultRedirect->setPath('adminhtml/*/index');
44+
return $resultRedirect;
4145
}
4246
}

0 commit comments

Comments
 (0)