-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #588 from magento-ogre/PR_Branch
[Ogres] PR for Sprint 36
- Loading branch information
Showing
75 changed files
with
1,780 additions
and
740 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Backend\Model; | ||
|
||
use Magento\Framework\App\Router\PathConfigInterface; | ||
use Magento\Store\Model\Store; | ||
|
||
/** | ||
* Path config to be used in adminhtml area | ||
*/ | ||
class AdminPathConfig implements PathConfigInterface | ||
{ | ||
/** | ||
* @var \Magento\Framework\App\Config\ScopeConfigInterface | ||
*/ | ||
protected $coreConfig; | ||
|
||
/** | ||
* @var \Magento\Backend\App\ConfigInterface | ||
*/ | ||
protected $backendConfig; | ||
|
||
/** | ||
* @var \Magento\Framework\UrlInterface | ||
*/ | ||
protected $url; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig | ||
* @param \Magento\Backend\App\ConfigInterface $backendConfig | ||
* @param \Magento\Framework\UrlInterface $url | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\Config\ScopeConfigInterface $coreConfig, | ||
\Magento\Backend\App\ConfigInterface $backendConfig, | ||
\Magento\Framework\UrlInterface $url | ||
) { | ||
$this->coreConfig = $coreConfig; | ||
$this->backendConfig = $backendConfig; | ||
$this->url = $url; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param \Magento\Framework\App\RequestInterface $request | ||
* @return string | ||
*/ | ||
public function getCurrentSecureUrl(\Magento\Framework\App\RequestInterface $request) | ||
{ | ||
return $this->url->getBaseUrl('link', true) . ltrim($request->getPathInfo(), '/'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param string $path | ||
* @return bool | ||
*/ | ||
public function shouldBeSecure($path) | ||
{ | ||
return parse_url( | ||
(string)$this->coreConfig->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default'), | ||
PHP_URL_SCHEME | ||
) === 'https' | ||
|| $this->backendConfig->isSetFlag(Store::XML_PATH_SECURE_IN_ADMINHTML) | ||
&& parse_url( | ||
(string)$this->coreConfig->getValue(Store::XML_PATH_SECURE_BASE_URL, 'default'), | ||
PHP_URL_SCHEME | ||
) === 'https'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return string | ||
*/ | ||
public function getDefaultPath() | ||
{ | ||
return $this->backendConfig->getValue('web/default/admin'); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
app/code/Magento/Backend/Test/Unit/Model/AdminPathConfigTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Backend\Test\Unit\Model; | ||
|
||
use Magento\Backend\Model\AdminPathConfig; | ||
use Magento\Store\Model\Store; | ||
|
||
class AdminPathConfigTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $coreConfig; | ||
|
||
/** | ||
* @var \Magento\Backend\App\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $backendConfig; | ||
|
||
/** | ||
* @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $url; | ||
|
||
/** | ||
* @var AdminPathConfig | ||
*/ | ||
protected $adminPathConfig; | ||
|
||
public function setUp() | ||
{ | ||
$this->coreConfig = $this->getMockForAbstractClass( | ||
'Magento\Framework\App\Config\ScopeConfigInterface', | ||
[], | ||
'', | ||
false | ||
); | ||
$this->backendConfig = $this->getMockForAbstractClass('Magento\Backend\App\ConfigInterface', [], '', false); | ||
$this->url = $this->getMockForAbstractClass( | ||
'Magento\Framework\UrlInterface', | ||
[], | ||
'', | ||
false, | ||
true, | ||
true, | ||
['getBaseUrl'] | ||
); | ||
$this->adminPathConfig = new AdminPathConfig($this->coreConfig, $this->backendConfig, $this->url); | ||
} | ||
|
||
public function testGetCurrentSecureUrl() | ||
{ | ||
$request = $this->getMockForAbstractClass( | ||
'Magento\Framework\App\RequestInterface', | ||
[], | ||
'', | ||
false, | ||
true, | ||
true, | ||
['getPathInfo'] | ||
); | ||
$request->expects($this->once())->method('getPathInfo')->willReturn('/info'); | ||
$this->url->expects($this->once())->method('getBaseUrl')->with('link', true)->willReturn('localhost/'); | ||
$this->assertEquals('localhost/info', $this->adminPathConfig->getCurrentSecureUrl($request)); | ||
} | ||
|
||
/** | ||
* @param $unsecureBaseUrl | ||
* @param $useSecureInAdmin | ||
* @param $secureBaseUrl | ||
* @param $expected | ||
* @dataProvider shouldBeSecureDataProvider | ||
*/ | ||
public function testShouldBeSecure($unsecureBaseUrl, $useSecureInAdmin, $secureBaseUrl, $expected) | ||
{ | ||
$coreConfigValueMap = [ | ||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default', null, $unsecureBaseUrl], | ||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default', null, $secureBaseUrl], | ||
]; | ||
$this->coreConfig->expects($this->any())->method('getValue')->will($this->returnValueMap($coreConfigValueMap)); | ||
$this->backendConfig->expects($this->any())->method('isSetFlag')->willReturn($useSecureInAdmin); | ||
$this->assertEquals($expected, $this->adminPathConfig->shouldBeSecure('')); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function shouldBeSecureDataProvider() | ||
{ | ||
return [ | ||
['http://localhost/', false, 'default', false], | ||
['http://localhost/', true, 'default', false], | ||
['https://localhost/', false, 'default', true], | ||
['https://localhost/', true, 'default', true], | ||
['http://localhost/', false, 'https://localhost/', false], | ||
['http://localhost/', true, 'https://localhost/', true], | ||
['https://localhost/', true, 'https://localhost/', true], | ||
]; | ||
} | ||
|
||
public function testGetDefaultPath() | ||
{ | ||
$this->backendConfig->expects($this->once()) | ||
->method('getValue') | ||
->with('web/default/admin') | ||
->willReturn('default/path'); | ||
$this->assertEquals('default/path', $this->adminPathConfig->getDefaultPath()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.