Skip to content

Commit cfdbe77

Browse files
author
He, Joan(johe)
committed
Merge pull request #390 from magento-extensibility/MAGETWO-39119
[Extensibility] Bug fix
2 parents 13a70f1 + acb7622 commit cfdbe77

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

app/code/Magento/PageCache/Block/Javascript.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public function getScriptOptions()
2727
),
2828
'handles' => $this->_layout->getUpdate()->getHandles(),
2929
'originalRequest' => [
30-
'route' => $this->getRequest()->getRouteName(),
30+
'route' => $this->getRequest()->getRouteName(),
3131
'controller' => $this->getRequest()->getControllerName(),
32-
'action' => $this->getRequest()->getActionName(),
32+
'action' => $this->getRequest()->getActionName(),
33+
'uri' => $this->getRequest()->getRequestUri(),
3334
],
3435
'versionCookieName' => \Magento\Framework\App\PageCache\Version::COOKIE_NAME
3536
];

app/code/Magento/PageCache/Controller/Block/Render.php

+4
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ public function execute()
2424
$currentRoute = $this->getRequest()->getRouteName();
2525
$currentControllerName = $this->getRequest()->getControllerName();
2626
$currentActionName = $this->getRequest()->getActionName();
27+
$currentRequestUri = $this->getRequest()->getRequestUri();
2728

2829
$origRequest = $this->getRequest()->getParam('originalRequest');
2930
$origRequest = json_decode($origRequest, true);
3031
$this->getRequest()->setRouteName($origRequest['route']);
3132
$this->getRequest()->setControllerName($origRequest['controller']);
3233
$this->getRequest()->setActionName($origRequest['action']);
34+
$this->getRequest()->setRequestUri($origRequest['uri']);
35+
3336
/** @var \Magento\Framework\View\Element\BlockInterface[] $blocks */
3437
$blocks = $this->_getBlocks();
3538
$data = [];
@@ -41,6 +44,7 @@ public function execute()
4144
$this->getRequest()->setRouteName($currentRoute);
4245
$this->getRequest()->setControllerName($currentControllerName);
4346
$this->getRequest()->setActionName($currentActionName);
47+
$this->getRequest()->setRequestUri($currentRequestUri);
4448

4549
$this->getResponse()->setPrivateHeaders(\Magento\PageCache\Helper\Data::PRIVATE_MAX_AGE_CACHE);
4650
$this->translateInline->processResponseBody($data);

app/code/Magento/PageCache/Test/Unit/Block/JavascriptTest.php

+19-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ protected function setUp()
5454
'getControllerName',
5555
'getModuleName',
5656
'getActionName',
57+
'getRequestUri',
5758
'getParam',
5859
'setParams',
5960
'getParams',
6061
'setModuleName',
6162
'isSecure',
6263
'setActionName',
64+
'setRequestUri',
6365
'getCookie'
6466
],
6567
[],
@@ -122,6 +124,9 @@ public function testGetScriptOptions($isSecure, $url, $expectedResult)
122124
$this->requestMock->expects($this->once())
123125
->method('getActionName')
124126
->will($this->returnValue('action'));
127+
$this->requestMock->expects($this->once())
128+
->method('getRequestUri')
129+
->will($this->returnValue('uri'));
125130
$this->urlBuilderMock->expects($this->once())
126131
->method('getUrl')
127132
->willReturn($url);
@@ -153,10 +158,11 @@ public function getScriptOptionsDataProvider()
153158
* @param string $route
154159
* @param string $controller
155160
* @param string $action
161+
* @param string $uri
156162
* @param string $expectedResult
157163
* @dataProvider getScriptOptionsPrivateContentDataProvider
158164
*/
159-
public function testGetScriptOptionsPrivateContent($url, $route, $controller, $action, $expectedResult)
165+
public function testGetScriptOptionsPrivateContent($url, $route, $controller, $action, $uri, $expectedResult)
160166
{
161167
$handles = [
162168
'some',
@@ -179,6 +185,10 @@ public function testGetScriptOptionsPrivateContent($url, $route, $controller, $a
179185
->method('getActionName')
180186
->will($this->returnValue($action));
181187

188+
$this->requestMock->expects($this->once())
189+
->method('getRequestUri')
190+
->will($this->returnValue($uri));
191+
182192
$this->urlBuilderMock->expects($this->once())
183193
->method('getUrl')
184194
->willReturn($url);
@@ -191,14 +201,17 @@ public function testGetScriptOptionsPrivateContent($url, $route, $controller, $a
191201

192202
public function getScriptOptionsPrivateContentDataProvider()
193203
{
204+
// @codingStandardsIgnoreStart
194205
return [
195206
'http' => [
196-
'url' => 'http://some-name.com/page_cache/block/render',
197-
'route' => 'route',
198-
'controller' => 'controller',
199-
'action' => 'action',
200-
'expectedResult' => '~"originalRequest":{"route":"route","controller":"controller","action":"action"}~'
207+
'url' => 'http://some-name.com/page_cache/block/render',
208+
'route' => 'route',
209+
'controller' => 'controller',
210+
'action' => 'action',
211+
'uri' => 'uri',
212+
'expectedResult' => '~"originalRequest":{"route":"route","controller":"controller","action":"action","uri":"uri"}~'
201213
],
202214
];
215+
//@codingStandardsIgnoreEnd
203216
}
204217
}

app/code/Magento/PageCache/Test/Unit/Controller/Block/RenderTest.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ public function testExecuteNotAjax()
8888
public function testExecuteNoParams()
8989
{
9090
$this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true));
91-
$this->requestMock->expects($this->at(8))
91+
$this->requestMock->expects($this->at(10))
9292
->method('getParam')
9393
->with($this->equalTo('blocks'), $this->equalTo(''))
9494
->will($this->returnValue(''));
95-
$this->requestMock->expects($this->at(9))
95+
$this->requestMock->expects($this->at(11))
9696
->method('getParam')
9797
->with($this->equalTo('handles'), $this->equalTo(''))
9898
->will($this->returnValue(''));
@@ -103,7 +103,7 @@ public function testExecute()
103103
{
104104
$blocks = ['block1', 'block2'];
105105
$handles = ['handle1', 'handle2'];
106-
$originalRequest = '{"route":"route","controller":"controller","action":"action"}';
106+
$originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}';
107107
$expectedData = ['block1' => 'data1', 'block2' => 'data2'];
108108

109109
$blockInstance1 = $this->getMock(
@@ -136,15 +136,18 @@ public function testExecute()
136136
->method('getActionName')
137137
->will($this->returnValue('render'));
138138
$this->requestMock->expects($this->at(4))
139+
->method('getRequestUri')
140+
->will($this->returnValue('uri'));
141+
$this->requestMock->expects($this->at(5))
139142
->method('getParam')
140143
->with($this->equalTo('originalRequest'))
141144
->will($this->returnValue($originalRequest));
142145

143-
$this->requestMock->expects($this->at(8))
146+
$this->requestMock->expects($this->at(10))
144147
->method('getParam')
145148
->with($this->equalTo('blocks'), $this->equalTo(''))
146149
->will($this->returnValue(json_encode($blocks)));
147-
$this->requestMock->expects($this->at(9))
150+
$this->requestMock->expects($this->at(11))
148151
->method('getParam')
149152
->with($this->equalTo('handles'), $this->equalTo(''))
150153
->will($this->returnValue(json_encode($handles)));

dev/tests/integration/testsuite/Magento/Framework/Url/Helper/DataTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@ class DataTest extends \PHPUnit_Framework_TestCase
1414

1515
protected function setUp()
1616
{
17-
$_SERVER['HTTP_HOST'] = 'example.com';
18-
$_SERVER['REQUEST_URI'] = '/fancy_uri';
1917
$this->_helper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
2018
'Magento\Framework\Url\Helper\Data'
2119
);
2220
}
2321

2422
public function testGetCurrentBase64Url()
2523
{
26-
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MQ,,', $this->_helper->getCurrentBase64Url());
24+
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MS8,', $this->_helper->getCurrentBase64Url());
2725
}
2826

2927
public function testGetEncodedUrl()
3028
{
31-
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MQ,,', $this->_helper->getEncodedUrl());
29+
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MS8,', $this->_helper->getEncodedUrl());
3230
$this->assertEquals('aHR0cDovL2V4YW1wbGUuY29tLw,,', $this->_helper->getEncodedUrl('http://example.com/'));
3331
}
3432
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected function getUrlModel($arguments = [])
121121
public function testGetCurrentUrl($httpHost, $url)
122122
{
123123
$requestMock = $this->getRequestMock();
124-
$requestMock->expects($this->once())->method('getServer')->with('REQUEST_URI')->willReturn('/fancy_uri');
124+
$requestMock->expects($this->once())->method('getRequestUri')->willReturn('/fancy_uri');
125125
$requestMock->expects($this->once())->method('getScheme')->will($this->returnValue('http'));
126126
$requestMock->expects($this->once())->method('getHttpHost')->will($this->returnValue($httpHost));
127127
$model = $this->getUrlModel(['request' => $requestMock]);

lib/internal/Magento/Framework/Url.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ public function getCurrentUrl()
10451045
$port = ':' . $httpHostWithPort[1];
10461046
}
10471047
}
1048-
return $this->_request->getScheme() . '://' . $httpHost . $port . $this->_request->getServer('REQUEST_URI');
1048+
return $this->_request->getScheme() . '://' . $httpHost . $port . $this->_request->getRequestUri();
10491049
}
10501050

10511051
/**

0 commit comments

Comments
 (0)