Skip to content

Commit 99bc84d

Browse files
author
Yuri Kovsher
committed
Merge remote-tracking branch 'tango-ce/MAGETWO-33064-obsolete-test' into MAGETWO-32571
2 parents 08fef81 + e44a3cb commit 99bc84d

File tree

6 files changed

+184
-6
lines changed

6 files changed

+184
-6
lines changed

app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteStore.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public function execute()
1616
$itemId = $this->getRequest()->getParam('item_id', null);
1717
if (!($model = $this->_objectManager->create('Magento\Store\Model\Store')->load($itemId))) {
1818
$this->messageManager->addError(__('Unable to proceed. Please, try again.'));
19-
$this->_redirect('adminhtml/*/');
2019
/** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */
2120
$redirectResult = $this->resultRedirectFactory->create();
2221
return $redirectResult->setPath('adminhtml/*/');

app/code/Magento/Catalog/Controller/Category/View.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ class View extends \Magento\Framework\App\Action\Action
5252
*/
5353
protected $resultPageFactory;
5454

55+
/**
56+
* @var \Magento\Framework\Controller\Result\ForwardFactory
57+
*/
58+
protected $resultForwardFactory;
59+
60+
/**
61+
* @var \Magento\Framework\Controller\Result\RedirectFactory
62+
*/
63+
protected $resultRedirectFactory;
64+
5565
/**
5666
* Catalog Layer Resolver
5767
*
@@ -73,8 +83,10 @@ class View extends \Magento\Framework\App\Action\Action
7383
* @param \Magento\Framework\Registry $coreRegistry
7484
* @param \Magento\Framework\Store\StoreManagerInterface $storeManager
7585
* @param \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator
76-
* @param Resolver $layerResolver
7786
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
87+
* @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory
88+
* @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory
89+
* @param Resolver $layerResolver
7890
* @param CategoryRepositoryInterface $categoryRepository
7991
*/
8092
public function __construct(
@@ -85,6 +97,8 @@ public function __construct(
8597
\Magento\Framework\Store\StoreManagerInterface $storeManager,
8698
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
8799
PageFactory $resultPageFactory,
100+
\Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
101+
\Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory,
88102
Resolver $layerResolver,
89103
CategoryRepositoryInterface $categoryRepository
90104
) {
@@ -95,6 +109,8 @@ public function __construct(
95109
$this->_coreRegistry = $coreRegistry;
96110
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
97111
$this->resultPageFactory = $resultPageFactory;
112+
$this->resultForwardFactory = $resultForwardFactory;
113+
$this->resultRedirectFactory = $resultRedirectFactory;
98114
$this->layerResolver = $layerResolver;
99115
$this->categoryRepository = $categoryRepository;
100116
}
@@ -137,15 +153,14 @@ protected function _initCategory()
137153
/**
138154
* Category view action
139155
*
140-
* @return \Magento\Framework\View\Result\Page
156+
* @return \Magento\Framework\Controller\ResultInterface
141157
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
142158
* @SuppressWarnings(PHPMD.NPathComplexity)
143159
*/
144160
public function execute()
145161
{
146162
if ($this->_request->getParam(\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED)) {
147-
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
148-
return;
163+
return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl());
149164
}
150165
$category = $this->_initCategory();
151166
if ($category) {
@@ -192,7 +207,7 @@ public function execute()
192207
$page->getLayout()->initMessages();
193208
return $page;
194209
} elseif (!$this->getResponse()->isRedirect()) {
195-
$this->_forward('noroute');
210+
return $this->resultForwardFactory->create()->forward('noroute');
196211
}
197212
}
198213
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Test\Legacy;
8+
9+
/**
10+
* Temporary test that will be removed in scope of MAGETWO-28356.
11+
* Test verifies obsolete usages in modules that were refactored to work with ResultInterface.
12+
*/
13+
class ObsoleteResponseTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var array
17+
*/
18+
protected $obsoleteMethods = [];
19+
20+
/**
21+
* @var array
22+
*/
23+
protected $filesBlackList = [];
24+
25+
/**
26+
* @var string
27+
*/
28+
protected $appPath;
29+
30+
protected function setUp()
31+
{
32+
$this->appPath = \Magento\Framework\Test\Utility\Files::init()->getPathToSource();
33+
$this->obsoleteMethods = include __DIR__ . '/_files/response/obsolete_response_methods.php';
34+
$this->filesBlackList = $this->getBlackList();
35+
}
36+
37+
/**
38+
* Test verify that obsolete methods do not appear in refactored folders
39+
*/
40+
public function testObsoleteResponseMethods()
41+
{
42+
$invoker = new \Magento\Framework\Test\Utility\AggregateInvoker($this);
43+
$invoker(
44+
function ($file) {
45+
$content = file_get_contents($file);
46+
foreach ($this->obsoleteMethods as $method) {
47+
$quotedMethod = preg_quote($method, '/');
48+
$this->assertSame(
49+
0,
50+
preg_match('/(?<=[a-z\\d_:]|->|function\\s)' . $quotedMethod . '\\s*\\(/iS', $content),
51+
"File: $file\nContains obsolete method: $method . "
52+
);
53+
}
54+
},
55+
$this->modulesFilesDataProvider()
56+
);
57+
}
58+
59+
/**
60+
* Return refactored files
61+
*
62+
* @return array
63+
*/
64+
public function modulesFilesDataProvider()
65+
{
66+
$filesList = [];
67+
68+
foreach ($this->getFilesData('whitelist/refactored_modules*') as $refactoredFolder) {
69+
$files = \Magento\Framework\Test\Utility\Files::init()->getFiles(
70+
[$this->appPath . $refactoredFolder],
71+
'*.php'
72+
);
73+
$filesList = array_merge($filesList, $files);
74+
}
75+
76+
$result = array_map('realpath', $filesList);
77+
$result = array_diff($result, $this->filesBlackList);
78+
return \Magento\Framework\Test\Utility\Files::composeDataSets($result);
79+
}
80+
81+
/**
82+
* @return array
83+
*/
84+
protected function getBlackList()
85+
{
86+
$blackListFiles = [];
87+
foreach ($this->getFilesData('blacklist/files_list*') as $file) {
88+
$blackListFiles[] = realpath($this->appPath . $file);
89+
}
90+
return $blackListFiles;
91+
}
92+
93+
/**
94+
* @param string $filePattern
95+
* @return array
96+
*/
97+
protected function getFilesData($filePattern)
98+
{
99+
$result = [];
100+
foreach (glob(__DIR__ . '/_files/response/' . $filePattern) as $file) {
101+
$fileData = include $file;
102+
$result = array_merge($result, $fileData);
103+
}
104+
return $result;
105+
}
106+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Temporary implementation that will be removed in scope of MAGETWO-28356.
9+
*
10+
* Files that temporary excluded from results
11+
*/
12+
return [
13+
'/app/code/Magento/Backend/Model/View.php',
14+
'/app/code/Magento/Backend/App/AbstractAction.php',
15+
'/app/code/Magento/Backend/App/Response/Http/FileFactory.php',
16+
'/app/code/Magento/Backend/Block/Widget.php',
17+
'/app/code/Magento/Backend/Block/System/Config/Dwstree.php',
18+
];
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Temporary implementation that will be removed in scope of MAGETWO-28356.
9+
*
10+
* Obsolete methods for refactored modules
11+
*/
12+
return [
13+
'loadLayout',
14+
'renderLayout',
15+
'_redirect',
16+
'_forward',
17+
'_setActiveMenu',
18+
'_addBreadcrumb',
19+
'_addContent',
20+
'_addLeft',
21+
'_addJs',
22+
'_moveBlockToContainer',
23+
];
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Temporary implementation that will be removed in scope of MAGETWO-28356.
9+
*
10+
* Modules that were refactored and use ResultInterface
11+
*/
12+
return [
13+
'/app/code/Magento/Catalog',
14+
'/app/code/Magento/Backend',
15+
'/app/code/Magento/Sales',
16+
'/app/code/Magento/Customer',
17+
];

0 commit comments

Comments
 (0)