Skip to content

Commit

Permalink
Merge pull request #390 from magento-extensibility/MAGETWO-39119
Browse files Browse the repository at this point in the history
[Extensibility] Bug fix
  • Loading branch information
He, Joan(johe) committed Jun 29, 2015
2 parents 13a70f1 + acb7622 commit cfdbe77
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 19 deletions.
5 changes: 3 additions & 2 deletions app/code/Magento/PageCache/Block/Javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public function getScriptOptions()
),
'handles' => $this->_layout->getUpdate()->getHandles(),
'originalRequest' => [
'route' => $this->getRequest()->getRouteName(),
'route' => $this->getRequest()->getRouteName(),
'controller' => $this->getRequest()->getControllerName(),
'action' => $this->getRequest()->getActionName(),
'action' => $this->getRequest()->getActionName(),
'uri' => $this->getRequest()->getRequestUri(),
],
'versionCookieName' => \Magento\Framework\App\PageCache\Version::COOKIE_NAME
];
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/PageCache/Controller/Block/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ public function execute()
$currentRoute = $this->getRequest()->getRouteName();
$currentControllerName = $this->getRequest()->getControllerName();
$currentActionName = $this->getRequest()->getActionName();
$currentRequestUri = $this->getRequest()->getRequestUri();

$origRequest = $this->getRequest()->getParam('originalRequest');
$origRequest = json_decode($origRequest, true);
$this->getRequest()->setRouteName($origRequest['route']);
$this->getRequest()->setControllerName($origRequest['controller']);
$this->getRequest()->setActionName($origRequest['action']);
$this->getRequest()->setRequestUri($origRequest['uri']);

/** @var \Magento\Framework\View\Element\BlockInterface[] $blocks */
$blocks = $this->_getBlocks();
$data = [];
Expand All @@ -41,6 +44,7 @@ public function execute()
$this->getRequest()->setRouteName($currentRoute);
$this->getRequest()->setControllerName($currentControllerName);
$this->getRequest()->setActionName($currentActionName);
$this->getRequest()->setRequestUri($currentRequestUri);

$this->getResponse()->setPrivateHeaders(\Magento\PageCache\Helper\Data::PRIVATE_MAX_AGE_CACHE);
$this->translateInline->processResponseBody($data);
Expand Down
25 changes: 19 additions & 6 deletions app/code/Magento/PageCache/Test/Unit/Block/JavascriptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ protected function setUp()
'getControllerName',
'getModuleName',
'getActionName',
'getRequestUri',
'getParam',
'setParams',
'getParams',
'setModuleName',
'isSecure',
'setActionName',
'setRequestUri',
'getCookie'
],
[],
Expand Down Expand Up @@ -122,6 +124,9 @@ public function testGetScriptOptions($isSecure, $url, $expectedResult)
$this->requestMock->expects($this->once())
->method('getActionName')
->will($this->returnValue('action'));
$this->requestMock->expects($this->once())
->method('getRequestUri')
->will($this->returnValue('uri'));
$this->urlBuilderMock->expects($this->once())
->method('getUrl')
->willReturn($url);
Expand Down Expand Up @@ -153,10 +158,11 @@ public function getScriptOptionsDataProvider()
* @param string $route
* @param string $controller
* @param string $action
* @param string $uri
* @param string $expectedResult
* @dataProvider getScriptOptionsPrivateContentDataProvider
*/
public function testGetScriptOptionsPrivateContent($url, $route, $controller, $action, $expectedResult)
public function testGetScriptOptionsPrivateContent($url, $route, $controller, $action, $uri, $expectedResult)
{
$handles = [
'some',
Expand All @@ -179,6 +185,10 @@ public function testGetScriptOptionsPrivateContent($url, $route, $controller, $a
->method('getActionName')
->will($this->returnValue($action));

$this->requestMock->expects($this->once())
->method('getRequestUri')
->will($this->returnValue($uri));

$this->urlBuilderMock->expects($this->once())
->method('getUrl')
->willReturn($url);
Expand All @@ -191,14 +201,17 @@ public function testGetScriptOptionsPrivateContent($url, $route, $controller, $a

public function getScriptOptionsPrivateContentDataProvider()
{
// @codingStandardsIgnoreStart
return [
'http' => [
'url' => 'http://some-name.com/page_cache/block/render',
'route' => 'route',
'controller' => 'controller',
'action' => 'action',
'expectedResult' => '~"originalRequest":{"route":"route","controller":"controller","action":"action"}~'
'url' => 'http://some-name.com/page_cache/block/render',
'route' => 'route',
'controller' => 'controller',
'action' => 'action',
'uri' => 'uri',
'expectedResult' => '~"originalRequest":{"route":"route","controller":"controller","action":"action","uri":"uri"}~'
],
];
//@codingStandardsIgnoreEnd
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public function testExecuteNotAjax()
public function testExecuteNoParams()
{
$this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true));
$this->requestMock->expects($this->at(8))
$this->requestMock->expects($this->at(10))
->method('getParam')
->with($this->equalTo('blocks'), $this->equalTo(''))
->will($this->returnValue(''));
$this->requestMock->expects($this->at(9))
$this->requestMock->expects($this->at(11))
->method('getParam')
->with($this->equalTo('handles'), $this->equalTo(''))
->will($this->returnValue(''));
Expand All @@ -103,7 +103,7 @@ public function testExecute()
{
$blocks = ['block1', 'block2'];
$handles = ['handle1', 'handle2'];
$originalRequest = '{"route":"route","controller":"controller","action":"action"}';
$originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}';
$expectedData = ['block1' => 'data1', 'block2' => 'data2'];

$blockInstance1 = $this->getMock(
Expand Down Expand Up @@ -136,15 +136,18 @@ public function testExecute()
->method('getActionName')
->will($this->returnValue('render'));
$this->requestMock->expects($this->at(4))
->method('getRequestUri')
->will($this->returnValue('uri'));
$this->requestMock->expects($this->at(5))
->method('getParam')
->with($this->equalTo('originalRequest'))
->will($this->returnValue($originalRequest));

$this->requestMock->expects($this->at(8))
$this->requestMock->expects($this->at(10))
->method('getParam')
->with($this->equalTo('blocks'), $this->equalTo(''))
->will($this->returnValue(json_encode($blocks)));
$this->requestMock->expects($this->at(9))
$this->requestMock->expects($this->at(11))
->method('getParam')
->with($this->equalTo('handles'), $this->equalTo(''))
->will($this->returnValue(json_encode($handles)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ class DataTest extends \PHPUnit_Framework_TestCase

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

public function testGetCurrentBase64Url()
{
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MQ,,', $this->_helper->getCurrentBase64Url());
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MS8,', $this->_helper->getCurrentBase64Url());
}

public function testGetEncodedUrl()
{
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MQ,,', $this->_helper->getEncodedUrl());
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MS8,', $this->_helper->getEncodedUrl());
$this->assertEquals('aHR0cDovL2V4YW1wbGUuY29tLw,,', $this->_helper->getEncodedUrl('http://example.com/'));
}
}
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Test/Unit/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function getUrlModel($arguments = [])
public function testGetCurrentUrl($httpHost, $url)
{
$requestMock = $this->getRequestMock();
$requestMock->expects($this->once())->method('getServer')->with('REQUEST_URI')->willReturn('/fancy_uri');
$requestMock->expects($this->once())->method('getRequestUri')->willReturn('/fancy_uri');
$requestMock->expects($this->once())->method('getScheme')->will($this->returnValue('http'));
$requestMock->expects($this->once())->method('getHttpHost')->will($this->returnValue($httpHost));
$model = $this->getUrlModel(['request' => $requestMock]);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ public function getCurrentUrl()
$port = ':' . $httpHostWithPort[1];
}
}
return $this->_request->getScheme() . '://' . $httpHost . $port . $this->_request->getServer('REQUEST_URI');
return $this->_request->getScheme() . '://' . $httpHost . $port . $this->_request->getRequestUri();
}

/**
Expand Down

0 comments on commit cfdbe77

Please sign in to comment.