Skip to content

Commit c895589

Browse files
author
Oleksandr Iegorov
committed
Merge branch 'MAGETWO-83094' of https://github.com/magento-tango/magento2ce into MAGETWO-83094-PR
2 parents 814c791 + 2e000c4 commit c895589

File tree

3 files changed

+79
-45
lines changed

3 files changed

+79
-45
lines changed

app/code/Magento/Backend/Model/Url.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,33 +189,30 @@ public function getUrl($routePath = null, $routeParams = null)
189189
}
190190

191191
$cacheSecretKey = false;
192-
if (is_array($routeParams) && isset($routeParams['_cache_secret_key'])) {
192+
if (isset($routeParams['_cache_secret_key'])) {
193193
unset($routeParams['_cache_secret_key']);
194194
$cacheSecretKey = true;
195195
}
196196
$result = parent::getUrl($routePath, $routeParams);
197197
if (!$this->useSecretKey()) {
198198
return $result;
199199
}
200+
200201
$this->_setRoutePath($routePath);
201202
$routeName = $this->_getRouteName('*');
202203
$controllerName = $this->_getControllerName(self::DEFAULT_CONTROLLER_NAME);
203204
$actionName = $this->_getActionName(self::DEFAULT_ACTION_NAME);
204-
if ($cacheSecretKey) {
205-
$secret = [self::SECRET_KEY_PARAM_NAME => "\${$routeName}/{$controllerName}/{$actionName}\$"];
206-
} else {
207-
$secret = [
208-
self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($routeName, $controllerName, $actionName),
209-
];
210-
}
211-
if (is_array($routeParams)) {
212-
$routeParams = array_merge($secret, $routeParams);
213-
} else {
214-
$routeParams = $secret;
215-
}
216-
if (is_array($this->_getRouteParams())) {
217-
$routeParams = array_merge($this->_getRouteParams(), $routeParams);
205+
if (!isset($routeParams[self::SECRET_KEY_PARAM_NAME])) {
206+
if (!is_array($routeParams)) {
207+
$routeParams = [];
208+
}
209+
210+
$secretKey = $cacheSecretKey
211+
? "\${$routeName}/{$controllerName}/{$actionName}\$"
212+
: $this->getSecretKey($routeName, $controllerName, $actionName);
213+
$routeParams[self::SECRET_KEY_PARAM_NAME] = $secretKey;
218214
}
215+
219216
return parent::getUrl("{$routeName}/{$controllerName}/{$actionName}", $routeParams);
220217
}
221218

dev/tests/integration/testsuite/Magento/Backend/Model/UrlTest.php

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
*/
66
namespace Magento\Backend\Model;
77

8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\Framework\App\RequestInterface;
10+
use Magento\Framework\Url\ParamEncoder;
11+
use Magento\Framework\Session\SessionManagerInterface;
12+
use Magento\Framework\Encryption\EncryptorInterface;
13+
814
/**
915
* Test class for \Magento\Backend\Model\UrlInterface.
1016
*
@@ -13,16 +19,19 @@
1319
class UrlTest extends \PHPUnit_Framework_TestCase
1420
{
1521
/**
16-
* @var \Magento\Backend\Model\UrlInterface
22+
* @var RequestInterface
23+
*/
24+
private $request;
25+
26+
/**
27+
* @var UrlInterface
1728
*/
1829
protected $_model;
1930

2031
protected function setUp()
2132
{
22-
parent::setUp();
23-
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
24-
'Magento\Backend\Model\UrlInterface'
25-
);
33+
$this->request = Bootstrap::getObjectManager()->get(RequestInterface::class);
34+
$this->_model = Bootstrap::getObjectManager()->create(UrlInterface::class);
2635
}
2736

2837
/**
@@ -34,6 +43,38 @@ public function testGetUrl()
3443
{
3544
$url = $this->_model->getUrl('adminhtml/auth/login');
3645
$this->assertContains('admin/auth/login/key/', $url);
46+
47+
$routeParams = [
48+
'_escape_params' => false,
49+
'param1' => 'a1=='
50+
];
51+
$url = $this->_model->getUrl('path', $routeParams);
52+
$this->assertContains('/param1/a1==/', $url);
53+
54+
$this->request->setParams(['param2' => 'a2==']);
55+
$routeParams = [
56+
'_current' => true,
57+
'_escape_params' => false,
58+
];
59+
$url = $this->_model->getUrl('path', $routeParams);
60+
$this->assertContains('/param2/a2==/', $url);
61+
62+
/** @var ParamEncoder $paramEncoder */
63+
$paramEncoder = Bootstrap::getObjectManager()->get(ParamEncoder::class);
64+
$routeParams = [
65+
'_escape_params' => true,
66+
'param3' => 'a3=='
67+
];
68+
$url = $this->_model->getUrl('path', $routeParams);
69+
$this->assertContains('/param3/' . $paramEncoder->encode('a3==') . '/', $url);
70+
71+
$this->request->setParams(['param4' => 'a4==']);
72+
$routeParams = [
73+
'_current' => true,
74+
'_escape_params' => true,
75+
];
76+
$url = $this->_model->getUrl('path', $routeParams);
77+
$this->assertContains('/param4/' . $paramEncoder->encode('a4==') . '/', $url);
3778
}
3879

3980
/**
@@ -46,20 +87,17 @@ public function testGetUrl()
4687
*/
4788
public function testGetSecretKey($routeName, $controller, $action, $expectedHash)
4889
{
49-
/** @var $request \Magento\Framework\App\RequestInterface */
50-
$request = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
51-
->create('Magento\Framework\App\RequestInterface');
52-
$request->setControllerName(
90+
$this->request->setControllerName(
5391
'default_controller'
5492
)->setActionName(
5593
'default_action'
5694
)->setRouteName(
5795
'default_router'
5896
);
5997

60-
$this->_model->setRequest($request);
61-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
62-
'Magento\Framework\Session\SessionManagerInterface'
98+
$this->_model->setRequest($this->request);
99+
Bootstrap::getObjectManager()->get(
100+
SessionManagerInterface::class
63101
)->setData(
64102
'_form_key',
65103
'salt'
@@ -72,10 +110,8 @@ public function testGetSecretKey($routeName, $controller, $action, $expectedHash
72110
*/
73111
public function getSecretKeyDataProvider()
74112
{
75-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
76-
77-
/** @var $encryptor \Magento\Framework\Encryption\EncryptorInterface */
78-
$encryptor = $objectManager->get('Magento\Framework\Encryption\EncryptorInterface');
113+
/** @var $encryptor EncryptorInterface */
114+
$encryptor = Bootstrap::getObjectManager()->get(EncryptorInterface::class);
79115

80116
return [
81117
[
@@ -129,19 +165,14 @@ public function getSecretKeyDataProvider()
129165
*/
130166
public function testGetSecretKeyForwarded()
131167
{
132-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
133-
134-
/** @var $encryptor \Magento\Framework\Encryption\EncryptorInterface */
135-
$encryptor = $objectManager->get('Magento\Framework\Encryption\EncryptorInterface');
136-
137-
/** @var $request \Magento\Framework\App\Request\Http */
138-
$request = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
139-
->create('Magento\Framework\App\RequestInterface');
140-
$request->setControllerName('controller')->setActionName('action');
141-
$request->initForward()->setControllerName(uniqid())->setActionName(uniqid());
142-
$this->_model->setRequest($request);
143-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
144-
'Magento\Framework\Session\SessionManagerInterface'
168+
/** @var $encryptor EncryptorInterface */
169+
$encryptor = Bootstrap::getObjectManager()->get(EncryptorInterface::class);
170+
171+
$this->request->setControllerName('controller')->setActionName('action');
172+
$this->request->initForward()->setControllerName(uniqid())->setActionName(uniqid());
173+
$this->_model->setRequest($this->request);
174+
Bootstrap::getObjectManager()->get(
175+
SessionManagerInterface::class
145176
)->setData(
146177
'_form_key',
147178
'salt'

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,14 @@ public function testSaveActionWithValidCustomerDataAndValidAddressData()
217217
$this->assertNotEquals(0, $this->accountManagement->getDefaultBillingAddress($customerId));
218218
$this->assertNull($this->accountManagement->getDefaultShippingAddress($customerId));
219219

220+
$urlPatternParts = [
221+
$this->_baseControllerUrl . 'edit',
222+
'id/' . $customerId,
223+
'back/1',
224+
];
225+
$urlPattern = '/^' . str_replace('/', '\/', implode('(/.*/)|/', $urlPatternParts)) . '/';
220226
$this->assertRedirect(
221-
$this->stringStartsWith($this->_baseControllerUrl . 'edit/id/' . $customerId . '/back/1')
227+
$this->matchesRegularExpression($urlPattern)
222228
);
223229

224230
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */

0 commit comments

Comments
 (0)