Skip to content

Commit 506a60c

Browse files
author
okarpenko
committed
Merge branch 'develop' of https://github.corp.magento.com/magento2/magento2ce into BUGS
2 parents 12489bf + 180ca97 commit 506a60c

File tree

6 files changed

+370
-47
lines changed

6 files changed

+370
-47
lines changed

app/code/Magento/Backend/App/Area/FrontNameResolver.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
2424
*/
2525
const AREA_CODE = 'adminhtml';
2626

27+
/**
28+
* @var array
29+
*/
30+
protected $standardPorts = ['http' => '80', 'https' => '443'];
31+
2732
/**
2833
* @var string
2934
*/
@@ -42,21 +47,21 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
4247
protected $deploymentConfig;
4348

4449
/** @var ScopeConfigInterface */
45-
private $configInterface;
50+
private $scopeConfig;
4651

4752
/**
4853
* @param \Magento\Backend\App\Config $config
4954
* @param DeploymentConfig $deploymentConfig
50-
* @param ScopeConfigInterface $configInterface
55+
* @param ScopeConfigInterface $scopeConfig
5156
*/
5257
public function __construct(
5358
\Magento\Backend\App\Config $config,
5459
DeploymentConfig $deploymentConfig,
55-
ScopeConfigInterface $configInterface
60+
ScopeConfigInterface $scopeConfig
5661
) {
5762
$this->config = $config;
5863
$this->defaultFrontName = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME);
59-
$this->configInterface = $configInterface;
64+
$this->scopeConfig = $scopeConfig;
6065
}
6166

6267
/**
@@ -79,13 +84,30 @@ public function getFrontName($checkHost = false)
7984

8085
/**
8186
* Return whether the host from request is the backend host
87+
*
8288
* @return bool
8389
*/
8490
public function isHostBackend()
8591
{
86-
$backendUrl = $this->configInterface->getValue(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE);
87-
$backendHost = parse_url(trim($backendUrl), PHP_URL_HOST);
92+
$backendUrl = $this->scopeConfig->getValue(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE);
8893
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
89-
return (strcasecmp($backendHost, $host) === 0);
94+
return stripos($this->getHostWithPort($backendUrl), $host) !== false;
95+
}
96+
97+
/**
98+
* Get host with port
99+
*
100+
* @param string $url
101+
* @return mixed|string
102+
*/
103+
private function getHostWithPort($url)
104+
{
105+
$scheme = parse_url(trim($url), PHP_URL_SCHEME);
106+
$host = parse_url(trim($url), PHP_URL_HOST);
107+
$port = parse_url(trim($url), PHP_URL_PORT);
108+
if (!$port) {
109+
$port = isset($this->standardPorts[$scheme]) ? $this->standardPorts[$scheme] : null;
110+
}
111+
return isset($port) ? $host . ':' . $port : $host;
90112
}
91113
}

app/code/Magento/Backend/Test/Unit/App/Area/FrontNameResolverTest.php

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@
77

88
use Magento\Backend\App\Area\FrontNameResolver;
99
use Magento\Backend\Setup\ConfigOptionsList;
10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Store\Model\ScopeInterface;
12+
use Magento\Store\Model\Store;
1013

1114
class FrontNameResolverTest extends \PHPUnit_Framework_TestCase
1215
{
1316
/**
1417
* @var \Magento\Backend\App\Area\FrontNameResolver
1518
*/
16-
protected $_model;
19+
protected $model;
1720

1821
/**
19-
* @var \PHPUnit_Framework_MockObject_MockObject
22+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\App\Config
2023
*/
21-
protected $_configMock;
24+
protected $configMock;
25+
26+
/**
27+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
28+
*/
29+
protected $scopeConfigMock;
2230

2331
/**
2432
* @var string
@@ -27,19 +35,20 @@ class FrontNameResolverTest extends \PHPUnit_Framework_TestCase
2735

2836
protected function setUp()
2937
{
30-
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
38+
/** @var \PHPUnit_Framework_MockObject_MockObject|DeploymentConfig $deploymentConfigMock */
39+
$deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
3140
$deploymentConfigMock->expects($this->once())
3241
->method('get')
3342
->with(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME)
3443
->will($this->returnValue($this->_defaultFrontName));
35-
$this->_configMock = $this->getMock('\Magento\Backend\App\Config', [], [], '', false);
36-
$configMock = $this->getMock('\Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
37-
$this->_model = new FrontNameResolver($this->_configMock, $deploymentConfigMock, $configMock);
44+
$this->configMock = $this->getMock('Magento\Backend\App\Config', [], [], '', false);
45+
$this->scopeConfigMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
46+
$this->model = new FrontNameResolver($this->configMock, $deploymentConfigMock, $this->scopeConfigMock);
3847
}
3948

4049
public function testIfCustomPathUsed()
4150
{
42-
$this->_configMock->expects(
51+
$this->configMock->expects(
4352
$this->at(0)
4453
)->method(
4554
'getValue'
@@ -48,7 +57,7 @@ public function testIfCustomPathUsed()
4857
)->will(
4958
$this->returnValue(true)
5059
);
51-
$this->_configMock->expects(
60+
$this->configMock->expects(
5261
$this->at(1)
5362
)->method(
5463
'getValue'
@@ -57,12 +66,12 @@ public function testIfCustomPathUsed()
5766
)->will(
5867
$this->returnValue('expectedValue')
5968
);
60-
$this->assertEquals('expectedValue', $this->_model->getFrontName());
69+
$this->assertEquals('expectedValue', $this->model->getFrontName());
6170
}
6271

6372
public function testIfCustomPathNotUsed()
6473
{
65-
$this->_configMock->expects(
74+
$this->configMock->expects(
6675
$this->once()
6776
)->method(
6877
'getValue'
@@ -71,6 +80,58 @@ public function testIfCustomPathNotUsed()
7180
)->will(
7281
$this->returnValue(false)
7382
);
74-
$this->assertEquals($this->_defaultFrontName, $this->_model->getFrontName());
83+
$this->assertEquals($this->_defaultFrontName, $this->model->getFrontName());
84+
}
85+
86+
/**
87+
* @param $url
88+
* @param $host
89+
* @dataProvider hostsDataProvider
90+
*/
91+
public function testIsHostBackend($url, $host, $expectedValue)
92+
{
93+
$backendUrl = $url;
94+
$_SERVER['HTTP_HOST'] = $host;
95+
$this->scopeConfigMock->expects($this->once())
96+
->method('getValue')
97+
->with(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE)
98+
->willReturn($backendUrl);
99+
$this->assertEquals($this->model->isHostBackend(), $expectedValue);
100+
}
101+
102+
public function hostsDataProvider()
103+
{
104+
return [
105+
'withoutPort' => [
106+
'url' => 'http://magento2.loc/',
107+
'host' => 'magento2.loc',
108+
'expectedValue' => true
109+
],
110+
'withPort' => [
111+
'url' => 'http://magento2.loc:8080/',
112+
'host' => 'magento2.loc:8080',
113+
'expectedValue' => true
114+
],
115+
'withStandartPortInUrlWithoutPortInHost' => [
116+
'url' => 'http://magento2.loc:80/',
117+
'host' => 'magento2.loc',
118+
'expectedValue' => true
119+
],
120+
'withoutStandartPortInUrlWithPortInHost' => [
121+
'url' => 'https://magento2.loc/',
122+
'host' => 'magento2.loc:443',
123+
'expectedValue' => true
124+
],
125+
'differentHosts' => [
126+
'url' => 'http://m2.loc/',
127+
'host' => 'magento2.loc',
128+
'expectedValue' => false
129+
],
130+
'differentPortsOnOneHost' => [
131+
'url' => 'http://magento2.loc/',
132+
'host' => 'magento2.loc:8080',
133+
'expectedValue' => false
134+
]
135+
];
75136
}
76137
}

app/design/frontend/Magento/luma/web/css/source/_theme.less

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@
249249

250250
@gallery-thumb-border-color-active: @active__color;
251251

252-
// Modal popup
253-
@modal-action-close__font-size: @font-size__base;
254-
@modal-slide-action-close__padding: @modal-slide-header__padding-vertical @modal-popup__padding;
255-
256252
// Checkout tooltip icon
257253
@checkout-tooltip-icon__font-size: 21px;
258254

0 commit comments

Comments
 (0)