Skip to content

Commit d18f569

Browse files
author
Dale Sikkema
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-40265-exposed-resources
2 parents 8bc8431 + 3cf2916 commit d18f569

File tree

75 files changed

+1780
-740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1780
-740
lines changed

app/code/Magento/Backend/App/Router.php

-96
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,11 @@
1010

1111
class Router extends \Magento\Framework\App\Router\Base
1212
{
13-
/**
14-
* @var \Magento\Backend\App\ConfigInterface
15-
*/
16-
protected $_backendConfig;
17-
1813
/**
1914
* @var \Magento\Framework\UrlInterface $url
2015
*/
2116
protected $_url;
2217

23-
/**
24-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
25-
*/
26-
protected $_coreConfig;
27-
2818
/**
2919
* List of required request parameters
3020
* Order sensitive
@@ -46,92 +36,6 @@ class Router extends \Magento\Framework\App\Router\Base
4636
*/
4737
protected $pathPrefix = \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE;
4838

49-
/**
50-
* @param \Magento\Framework\App\Router\ActionList $actionList
51-
* @param \Magento\Framework\App\ActionFactory $actionFactory
52-
* @param \Magento\Framework\App\DefaultPathInterface $defaultPath
53-
* @param \Magento\Framework\App\ResponseFactory $responseFactory
54-
* @param \Magento\Framework\App\Route\ConfigInterface $routeConfig
55-
* @param \Magento\Framework\UrlInterface $url
56-
* @param string $routerId
57-
* @param \Magento\Framework\Code\NameBuilder $nameBuilder
58-
* @param \Magento\Framework\App\Router\PathConfigInterface $pathConfig
59-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig
60-
* @param \Magento\Backend\App\ConfigInterface $backendConfig
61-
*
62-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
63-
*/
64-
public function __construct(
65-
\Magento\Framework\App\Router\ActionList $actionList,
66-
\Magento\Framework\App\ActionFactory $actionFactory,
67-
\Magento\Framework\App\DefaultPathInterface $defaultPath,
68-
\Magento\Framework\App\ResponseFactory $responseFactory,
69-
\Magento\Framework\App\Route\ConfigInterface $routeConfig,
70-
\Magento\Framework\UrlInterface $url,
71-
$routerId,
72-
\Magento\Framework\Code\NameBuilder $nameBuilder,
73-
\Magento\Framework\App\Router\PathConfigInterface $pathConfig,
74-
\Magento\Framework\App\Config\ScopeConfigInterface $coreConfig,
75-
\Magento\Backend\App\ConfigInterface $backendConfig
76-
) {
77-
parent::__construct(
78-
$actionList,
79-
$actionFactory,
80-
$defaultPath,
81-
$responseFactory,
82-
$routeConfig,
83-
$url,
84-
$routerId,
85-
$nameBuilder,
86-
$pathConfig
87-
);
88-
$this->_coreConfig = $coreConfig;
89-
$this->_backendConfig = $backendConfig;
90-
$this->_url = $url;
91-
}
92-
93-
/**
94-
* Get router default request path
95-
* @return string
96-
*/
97-
protected function _getDefaultPath()
98-
{
99-
return (string)$this->_backendConfig->getValue('web/default/admin');
100-
}
101-
102-
/**
103-
* Check whether URL for corresponding path should use https protocol
104-
*
105-
* @param string $path
106-
* @return bool
107-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
108-
*/
109-
protected function _shouldBeSecure($path)
110-
{
111-
return substr(
112-
(string)$this->_coreConfig->getValue('web/unsecure/base_url', 'default'),
113-
0,
114-
5
115-
) === 'https' || $this->_backendConfig->isSetFlag(
116-
'web/secure/use_in_adminhtml'
117-
) && substr(
118-
(string)$this->_coreConfig->getValue('web/secure/base_url', 'default'),
119-
0,
120-
5
121-
) === 'https';
122-
}
123-
124-
/**
125-
* Retrieve current secure url
126-
*
127-
* @param \Magento\Framework\App\RequestInterface $request
128-
* @return string
129-
*/
130-
protected function _getCurrentSecureUrl($request)
131-
{
132-
return $this->_url->getBaseUrl('link', true) . ltrim($request->getPathInfo(), '/');
133-
}
134-
13539
/**
13640
* Check whether redirect should be used for secure routes
13741
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Model;
7+
8+
use Magento\Framework\App\Router\PathConfigInterface;
9+
use Magento\Store\Model\Store;
10+
11+
/**
12+
* Path config to be used in adminhtml area
13+
*/
14+
class AdminPathConfig implements PathConfigInterface
15+
{
16+
/**
17+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
18+
*/
19+
protected $coreConfig;
20+
21+
/**
22+
* @var \Magento\Backend\App\ConfigInterface
23+
*/
24+
protected $backendConfig;
25+
26+
/**
27+
* @var \Magento\Framework\UrlInterface
28+
*/
29+
protected $url;
30+
31+
/**
32+
* Constructor
33+
*
34+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig
35+
* @param \Magento\Backend\App\ConfigInterface $backendConfig
36+
* @param \Magento\Framework\UrlInterface $url
37+
*/
38+
public function __construct(
39+
\Magento\Framework\App\Config\ScopeConfigInterface $coreConfig,
40+
\Magento\Backend\App\ConfigInterface $backendConfig,
41+
\Magento\Framework\UrlInterface $url
42+
) {
43+
$this->coreConfig = $coreConfig;
44+
$this->backendConfig = $backendConfig;
45+
$this->url = $url;
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*
51+
* @param \Magento\Framework\App\RequestInterface $request
52+
* @return string
53+
*/
54+
public function getCurrentSecureUrl(\Magento\Framework\App\RequestInterface $request)
55+
{
56+
return $this->url->getBaseUrl('link', true) . ltrim($request->getPathInfo(), '/');
57+
}
58+
59+
/**
60+
* {@inheritdoc}
61+
*
62+
* @param string $path
63+
* @return bool
64+
*/
65+
public function shouldBeSecure($path)
66+
{
67+
return parse_url(
68+
(string)$this->coreConfig->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default'),
69+
PHP_URL_SCHEME
70+
) === 'https'
71+
|| $this->backendConfig->isSetFlag(Store::XML_PATH_SECURE_IN_ADMINHTML)
72+
&& parse_url(
73+
(string)$this->coreConfig->getValue(Store::XML_PATH_SECURE_BASE_URL, 'default'),
74+
PHP_URL_SCHEME
75+
) === 'https';
76+
}
77+
78+
/**
79+
* {@inheritdoc}
80+
*
81+
* @return string
82+
*/
83+
public function getDefaultPath()
84+
{
85+
return $this->backendConfig->getValue('web/default/admin');
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Test\Unit\Model;
7+
8+
use Magento\Backend\Model\AdminPathConfig;
9+
use Magento\Store\Model\Store;
10+
11+
class AdminPathConfigTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
15+
*/
16+
protected $coreConfig;
17+
18+
/**
19+
* @var \Magento\Backend\App\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $backendConfig;
22+
23+
/**
24+
* @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $url;
27+
28+
/**
29+
* @var AdminPathConfig
30+
*/
31+
protected $adminPathConfig;
32+
33+
public function setUp()
34+
{
35+
$this->coreConfig = $this->getMockForAbstractClass(
36+
'Magento\Framework\App\Config\ScopeConfigInterface',
37+
[],
38+
'',
39+
false
40+
);
41+
$this->backendConfig = $this->getMockForAbstractClass('Magento\Backend\App\ConfigInterface', [], '', false);
42+
$this->url = $this->getMockForAbstractClass(
43+
'Magento\Framework\UrlInterface',
44+
[],
45+
'',
46+
false,
47+
true,
48+
true,
49+
['getBaseUrl']
50+
);
51+
$this->adminPathConfig = new AdminPathConfig($this->coreConfig, $this->backendConfig, $this->url);
52+
}
53+
54+
public function testGetCurrentSecureUrl()
55+
{
56+
$request = $this->getMockForAbstractClass(
57+
'Magento\Framework\App\RequestInterface',
58+
[],
59+
'',
60+
false,
61+
true,
62+
true,
63+
['getPathInfo']
64+
);
65+
$request->expects($this->once())->method('getPathInfo')->willReturn('/info');
66+
$this->url->expects($this->once())->method('getBaseUrl')->with('link', true)->willReturn('localhost/');
67+
$this->assertEquals('localhost/info', $this->adminPathConfig->getCurrentSecureUrl($request));
68+
}
69+
70+
/**
71+
* @param $unsecureBaseUrl
72+
* @param $useSecureInAdmin
73+
* @param $secureBaseUrl
74+
* @param $expected
75+
* @dataProvider shouldBeSecureDataProvider
76+
*/
77+
public function testShouldBeSecure($unsecureBaseUrl, $useSecureInAdmin, $secureBaseUrl, $expected)
78+
{
79+
$coreConfigValueMap = [
80+
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default', null, $unsecureBaseUrl],
81+
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default', null, $secureBaseUrl],
82+
];
83+
$this->coreConfig->expects($this->any())->method('getValue')->will($this->returnValueMap($coreConfigValueMap));
84+
$this->backendConfig->expects($this->any())->method('isSetFlag')->willReturn($useSecureInAdmin);
85+
$this->assertEquals($expected, $this->adminPathConfig->shouldBeSecure(''));
86+
}
87+
88+
/**
89+
* @return array
90+
*/
91+
public function shouldBeSecureDataProvider()
92+
{
93+
return [
94+
['http://localhost/', false, 'default', false],
95+
['http://localhost/', true, 'default', false],
96+
['https://localhost/', false, 'default', true],
97+
['https://localhost/', true, 'default', true],
98+
['http://localhost/', false, 'https://localhost/', false],
99+
['http://localhost/', true, 'https://localhost/', true],
100+
['https://localhost/', true, 'https://localhost/', true],
101+
];
102+
}
103+
104+
public function testGetDefaultPath()
105+
{
106+
$this->backendConfig->expects($this->once())
107+
->method('getValue')
108+
->with('web/default/admin')
109+
->willReturn('default/path');
110+
$this->assertEquals('default/path', $this->adminPathConfig->getDefaultPath());
111+
}
112+
}

app/code/Magento/Backend/etc/adminhtml/di.xml

+1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,5 @@
127127
<argument name="xFrameOpt" xsi:type="const">Magento\Framework\App\Response\XFrameOptPlugin::BACKEND_X_FRAME_OPT</argument>
128128
</arguments>
129129
</type>
130+
<preference for="Magento\Framework\App\Router\PathConfigInterface" type="Magento\Backend\Model\AdminPathConfig" />
130131
</config>

app/code/Magento/Developer/Console/Command/CssDeployCommand.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
219219
]
220220
);
221221

222+
$rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
222223
$sourceFile = $this->assetSource->findSource($asset);
223-
$content = \file_get_contents($sourceFile);
224+
$relativePath = $rootDir->getRelativePath($sourceFile);
225+
$content = $rootDir->readFile($relativePath);
224226

225227
$chain = $this->chainFactory->create(
226228
[
227229
'asset' => $asset,
228230
'origContent' => $content,
229231
'origContentType' => $asset->getContentType(),
230-
'origAssetPath' => $asset->getFilePath()
232+
'origAssetPath' => $relativePath
231233
]
232234
);
233235

234236
$processedCoreFile = $sourceFileGenerator->generateFileTree($chain);
235237

236238
$targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
237-
$rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
238239
$source = $rootDir->getRelativePath($processedCoreFile);
239240
$destination = $asset->getPath();
240241
$rootDir->copyFile($source, $destination, $targetDir);

app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php

+19-7
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public function testExecute()
113113
->method('create')
114114
->with('less')
115115
->willReturn($this->getMock('Magento\Framework\View\Asset\SourceFileGeneratorInterface'));
116+
$asset = $this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface');
117+
$asset->expects($this->once())->method('getContentType')->willReturn('type');
116118
$this->assetRepo->expects($this->once())
117119
->method('createAsset')
118120
->with(
@@ -123,18 +125,28 @@ public function testExecute()
123125
'locale' => 'en_US'
124126
]
125127
)
126-
->willReturn(
127-
$this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface')
128-
);
128+
->willReturn($asset);
129129
$this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null');
130130

131-
$this->chainFactory->expects($this->once())->method('create')->willReturn(
132-
$this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false)
133-
);
131+
$this->chainFactory->expects($this->once())
132+
->method('create')
133+
->with(
134+
[
135+
'asset' => $asset,
136+
'origContent' => 'content',
137+
'origContentType' => 'type',
138+
'origAssetPath' => 'relative/path',
139+
]
140+
)
141+
->willReturn($this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false));
134142

135-
$this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn(
143+
$rootDir = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteInterface', [], [], '', false);
144+
$this->filesystem->expects($this->at(0))->method('getDirectoryWrite')->willReturn($rootDir);
145+
$this->filesystem->expects($this->at(1))->method('getDirectoryWrite')->willReturn(
136146
$this->getMock('\Magento\Framework\Filesystem\Directory\WriteInterface', [], [], '', false)
137147
);
148+
$rootDir->expects($this->atLeastOnce())->method('getRelativePath')->willReturn('relative/path');
149+
$rootDir->expects($this->once())->method('readFile')->willReturn('content');
138150

139151
$this->validator->expects($this->once())->method('isValid')->with('en_US')->willReturn(true);
140152

0 commit comments

Comments
 (0)