Skip to content

Commit 1609ec3

Browse files
Deprecate \Magento\Framework\UrlInterface::getRouteUrl
1 parent 7247297 commit 1609ec3

File tree

8 files changed

+62
-11
lines changed

8 files changed

+62
-11
lines changed

app/code/Magento/Backend/Helper/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function generateResetPasswordLinkToken()
195195
*/
196196
public function getHomePageUrl()
197197
{
198-
return $this->_backendUrl->getRouteUrl('adminhtml');
198+
return $this->_backendUrl->getUrl('adminhtml');
199199
}
200200

201201
/**

dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/AuthTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function testLoggedLoginAction()
9191
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
9292
\Magento\Backend\Model\UrlInterface::class
9393
);
94+
$backendUrlModel->turnOffSecretKey();
9495
$url = $backendUrlModel->getStartupPageUrl();
9596
$expected = $backendUrlModel->getUrl($url);
9697
$this->assertRedirect($this->stringStartsWith($expected));
@@ -137,6 +138,11 @@ public function testLogoutAction()
137138
{
138139
$this->_login();
139140
$this->dispatch('backend/admin/auth/logout');
141+
/** @var $backendUrlModel \Magento\Backend\Model\UrlInterface */
142+
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
143+
\Magento\Backend\Model\UrlInterface::class
144+
);
145+
$backendUrlModel->turnOffSecretKey();
140146
$this->assertRedirect(
141147
$this->equalTo(
142148
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
@@ -156,6 +162,11 @@ public function testDeniedJsonAction()
156162
{
157163
$this->_login();
158164
$this->dispatch('backend/admin/auth/deniedJson');
165+
/** @var $backendUrlModel \Magento\Backend\Model\UrlInterface */
166+
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
167+
\Magento\Backend\Model\UrlInterface::class
168+
);
169+
$backendUrlModel->turnOffSecretKey();
159170
$data = [
160171
'ajaxExpired' => 1,
161172
'ajaxRedirect' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
@@ -176,6 +187,11 @@ public function testDeniedIframeAction()
176187
{
177188
$this->_login();
178189
$this->dispatch('backend/admin/auth/deniedIframe');
190+
/** @var $backendUrlModel \Magento\Backend\Model\UrlInterface */
191+
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
192+
\Magento\Backend\Model\UrlInterface::class
193+
);
194+
$backendUrlModel->turnOffSecretKey();
179195
$homeUrl = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
180196
\Magento\Backend\Helper\Data::class
181197
)->getHomePageUrl();

dev/tests/integration/testsuite/Magento/Backend/Helper/DataTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ public function testGetCurrentUserId()
108108
/**
109109
* perform login
110110
*/
111-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
112-
\Magento\Backend\Model\UrlInterface::class
113-
)->turnOffSecretKey();
111+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
112+
$objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOffSecretKey();
114113

115114
$auth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Backend\Model\Auth::class);
116115
$auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
@@ -120,9 +119,7 @@ public function testGetCurrentUserId()
120119
* perform logout
121120
*/
122121
$auth->logout();
123-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
124-
\Magento\Backend\Model\UrlInterface::class
125-
)->turnOnSecretKey();
122+
$objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOnSecretKey();
126123

127124
$this->assertFalse($this->_helper->getCurrentUserId());
128125
}
@@ -141,8 +138,11 @@ public function testPrepareFilterString()
141138

142139
public function testGetHomePageUrl()
143140
{
141+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
142+
$objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOffSecretKey();
143+
144144
$this->assertStringEndsWith(
145-
'index.php/backend/admin/',
145+
'index.php/backend/admin/index/index/',
146146
$this->_helper->getHomePageUrl(),
147147
'Incorrect home page URL'
148148
);

dev/tests/integration/testsuite/Magento/Framework/UrlTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
namespace Magento\Framework;
77

8-
use Zend\Stdlib\Parameters;
98
use Magento\TestFramework\Helper\Bootstrap;
9+
use Zend\Stdlib\Parameters;
1010

1111
class UrlTest extends \PHPUnit\Framework\TestCase
1212
{
@@ -231,6 +231,9 @@ public function testSetGetActionName()
231231
/**
232232
* Note: isolation flushes the URL memory cache
233233
* @magentoAppIsolation enabled
234+
*
235+
* @deprecated 101.0.1 getRouteUrl method will become private, and will disappear from the interface, url
236+
* creation is centralized through getUrl method
234237
*/
235238
public function testGetRouteUrl()
236239
{

dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/AuthTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public function testForgotpasswordAction()
3333
{
3434
$this->getRequest()->setPostValue('email', '[email protected]');
3535
$this->dispatch('backend/admin/auth/forgotpassword');
36+
37+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
38+
$objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOffSecretKey();
39+
3640
$this->assertRedirect(
3741
$this->equalTo(
3842
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
@@ -60,6 +64,10 @@ public function testEmailSendForgotPasswordAction()
6064

6165
$this->getRequest()->setPostValue('email', '[email protected]');
6266
$this->dispatch('backend/admin/auth/forgotpassword');
67+
68+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
69+
$objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOffSecretKey();
70+
6371
$this->assertRedirect(
6472
$this->equalTo(
6573
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
@@ -157,6 +165,7 @@ public function testResetPasswordPostAction($password, $passwordConfirmation, $i
157165
/** @var \Magento\Backend\Helper\Data $backendHelper */
158166
$backendHelper = $objectManager->get(\Magento\Backend\Helper\Data::class);
159167
if ($isPasswordChanged) {
168+
$objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOffSecretKey();
160169
$this->assertRedirect($this->equalTo($backendHelper->getHomePageUrl()));
161170
} else {
162171
$this->assertRedirect(
@@ -204,6 +213,7 @@ public function testResetPasswordPostActionWithDummyToken()
204213
);
205214

206215
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
216+
$objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOffSecretKey();
207217

208218
/** @var \Magento\Backend\Helper\Data $backendHelper */
209219
$backendHelper = $objectManager->get(\Magento\Backend\Helper\Data::class);

lib/internal/Magento/Framework/Test/Unit/UrlTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ public function getRebuiltUrlDataProvider()
515515
];
516516
}
517517

518+
/**
519+
* Retrieve route URL test
520+
*
521+
* @deprecated 101.0.1 getRouteUrl method will become private, and will disappear from the interface, url
522+
* creation is centralized through getUrl method
523+
*/
518524
public function testGetRouteUrlWithValidUrl()
519525
{
520526
$model = $this->getUrlModel(['routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(false)]);

lib/internal/Magento/Framework/Url.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,14 +734,28 @@ protected function _getRouteParams()
734734
* @param string $routePath
735735
* @param array $routeParams
736736
* @return string
737+
* @deprecated 101.0.1 getRouteUrl method will become private, and will disappear from the interface, url
738+
* creation is centralized through getUrl method
737739
*/
738740
public function getRouteUrl($routePath = null, $routeParams = null)
741+
{
742+
return $this->getRouteUrlByParams($routePath, $routeParams);
743+
}
744+
745+
/**
746+
* Retrieve route URL
747+
*
748+
* @param string $routePath
749+
* @param array $routeParams
750+
* @return string
751+
*/
752+
private function getRouteUrlByParams($routePath = null, $routeParams = null)
739753
{
740754
if (filter_var($routePath, FILTER_VALIDATE_URL)) {
741755
return $routePath;
742756
}
743757

744-
$this->getRouteParamsResolver()->unsetData('route_params');
758+
$this->getRouteParamsResolver()->setRouteParams([]);
745759

746760
if (isset($routeParams['_direct'])) {
747761
if (is_array($routeParams)) {
@@ -931,7 +945,7 @@ private function createUrl($routePath = null, array $routeParams = null)
931945
$noSid = (bool)$routeParams['_nosid'];
932946
unset($routeParams['_nosid']);
933947
}
934-
$url = $this->getRouteUrl($routePath, $routeParams);
948+
$url = $this->getRouteUrlByParams($routePath, $routeParams);
935949

936950
/**
937951
* Apply query params, need call after getRouteUrl for rewrite _current values

lib/internal/Magento/Framework/UrlInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public function getCurrentUrl();
7777
* @param string $routePath
7878
* @param array $routeParams
7979
* @return string
80+
* @deprecated 101.0.1 getRouteUrl method will become private, and will disappear from the interface, url
81+
* creation is centralized through getUrl method
8082
*/
8183
public function getRouteUrl($routePath = null, $routeParams = null);
8284

0 commit comments

Comments
 (0)