Skip to content

Commit 18c719e

Browse files
author
Igor Melnikov
committed
MAGETWO-52923: MAGETWO-52923: [Github] Switching to Varnish causes category menu to force HTTPS links #4540
Unit tests, code style
1 parent 4e526e2 commit 18c719e

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

app/code/Magento/PageCache/Observer/ProcessLayoutRenderElement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ protected function _wrapEsi(
5959
'handles' => json_encode($layout->getUpdate()->getHandles())
6060
]
6161
);
62-
// Varnish does not support esi over https must change to http
63-
$url = (substr($url, 0, 5) === 'https') ? 'http' . substr($url, 5) : $url;
62+
// Varnish does not support ESI over HTTPS must change to HTTP
63+
$url = substr($url, 0, 5) === 'https' ? 'http' . substr($url, 5) : $url;
6464
return sprintf('<esi:include src="%s" />', $url);
6565
}
6666

lib/internal/Magento/Framework/App/Test/Unit/Request/HttpTest.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@ class HttpTest extends \PHPUnit_Framework_TestCase
3232
protected $_infoProcessorMock;
3333

3434
/**
35-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager | \PHPUnit_Framework_MockObject_MockObject
35+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager | \PHPUnit_Framework_MockObject_MockObject
3636
*/
37-
protected $objectManager;
37+
protected $objectManagerMock;
3838

3939
/**
40-
* @var \Magento\Framework\Stdlib\StringUtils | \PHPUnit_Framework_MockObject_MockObject
40+
* @var \Magento\Framework\Stdlib\StringUtils | \PHPUnit_Framework_MockObject_MockObject
4141
*/
4242
protected $converterMock;
4343

44+
/**
45+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
46+
*/
47+
private $objectManager;
48+
4449
/**
4550
* @var array
4651
*/
@@ -58,7 +63,7 @@ protected function setUp()
5863
);
5964
$this->_infoProcessorMock = $this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface');
6065
$this->_infoProcessorMock->expects($this->any())->method('process')->will($this->returnArgument(1));
61-
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
66+
$this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface');
6267
$this->converterMock = $this->getMockBuilder('Magento\Framework\Stdlib\StringUtils')
6368
->disableOriginalConstructor()
6469
->setMethods(['cleanString'])
@@ -67,6 +72,8 @@ protected function setUp()
6772

6873
// Stash the $_SERVER array to protect it from modification in test
6974
$this->serverArray = $_SERVER;
75+
76+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
7077
}
7178

7279
public function tearDown()
@@ -77,23 +84,23 @@ public function tearDown()
7784
/**
7885
* @return \Magento\Framework\App\Request\Http
7986
*/
80-
private function getModel($uri = null, $mockAppConfig = true)
87+
private function getModel($uri = null, $appConfigMock = true)
8188
{
8289

8390
$model = $this->objectManager->getObject(
8491
'Magento\Framework\App\Request\Http',
8592
[
8693
'routeConfig' => $this->_routerListMock,
8794
'pathInfoProcessor' => $this->_infoProcessorMock,
88-
'objectManager' => $this->objectManager,
95+
'objectManager' => $this->objectManagerMock,
8996
'converter' => $this->converterMock,
9097
'uri' => $uri,
9198
]
9299
);
93100

94-
if ($mockAppConfig) {
95-
$mockConfig = $this->getMock(\Magento\Framework\App\Config::class, [], [], '' , false);
96-
$this->objectManager->setBackwardCompatibleProperty($model, 'appConfig', $mockConfig );
101+
if ($appConfigMock) {
102+
$configMock = $this->getMock(\Magento\Framework\App\Config::class, [], [], '' , false);
103+
$this->objectManager->setBackwardCompatibleProperty($model, 'appConfig', $configMock);
97104
}
98105

99106
return $model;
@@ -348,7 +355,7 @@ public function testIsSecure($isSecure, $serverHttps, $headerOffloadKey, $header
348355
->willReturn($configOffloadHeader);
349356

350357
$this->objectManager->setBackwardCompatibleProperty($this->_model, 'appConfig', $configMock);
351-
$this->objectManager->setBackwardCompatibleProperty($this->_model, 'SSLOffloadHeader', null );
358+
$this->objectManager->setBackwardCompatibleProperty($this->_model, 'sslOffloadHeader', null);
352359

353360
$this->_model->getServer()->set($headerOffloadKey, $headerOffloadValue);
354361
$this->_model->getServer()->set('HTTPS', $serverHttps);

lib/internal/Magento/Framework/HTTP/PhpEnvironment/Request.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Request extends \Zend\Http\PhpEnvironment\Request
9898
*
9999
* @var string
100100
*/
101-
protected $SSLOffloadHeader;
101+
protected $sslOffloadHeader;
102102

103103
/**
104104
* @param CookieReaderInterface $cookieReader
@@ -415,41 +415,37 @@ public function isSecure()
415415
return true;
416416
}
417417

418-
return $this->initialRequestSecure($this->getSSLOffloadHeader());
418+
return $this->initialRequestSecure($this->SslOffloadHeader());
419419
}
420420

421421
/***
422-
*
423-
* Get value of SSL offload http header from configuration -- defaults to X-Forwarded-Proto
422+
* Get value of SSL offload http header from configuration - defaults to X-Forwarded-Proto
424423
*
425424
* @return string
426425
*/
427-
private function getSSLOffloadHeader()
426+
private function SslOffloadHeader()
428427
{
429-
430428
// Lets read from db only one time okay.
431-
if ($this->SSLOffloadHeader === null) {
429+
if ($this->sslOffloadHeader === null) {
432430

433-
/* TODO: Untangle Config dependence on Scope, so that this class can be instantiated even if app is not
434-
installed MAGETWO-31756 */
431+
// @todo: Untangle Config dependence on Scope, so that this class can be instantiated even if app is not
432+
// installed MAGETWO-31756
435433
// Check if a proxy sent a header indicating an initial secure request
436-
$this->SSLOffloadHeader = trim(
434+
$this->sslOffloadHeader = trim(
437435
(string)$this->getAppConfig()->getValue(
438436
self::XML_PATH_OFFLOADER_HEADER,
439437
\Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT
440438
)
441439
);
442440
}
443441

444-
return $this->SSLOffloadHeader;
445-
442+
return $this->sslOffloadHeader;
446443
}
447444

448445
/**
449446
* Create an instance of Magento\Framework\App\Config
450447
*
451448
* @return \Magento\Framework\App\Config
452-
*
453449
* @deprecated
454450
*/
455451
private function getAppConfig()

0 commit comments

Comments
 (0)