Skip to content

Commit

Permalink
Merge pull request #588 from magento-ogre/PR_Branch
Browse files Browse the repository at this point in the history
[Ogres] PR for Sprint 36
  • Loading branch information
mazhalai committed Sep 10, 2015
2 parents c60e131 + e45bd34 commit 3cf2916
Show file tree
Hide file tree
Showing 75 changed files with 1,780 additions and 740 deletions.
96 changes: 0 additions & 96 deletions app/code/Magento/Backend/App/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@

class Router extends \Magento\Framework\App\Router\Base
{
/**
* @var \Magento\Backend\App\ConfigInterface
*/
protected $_backendConfig;

/**
* @var \Magento\Framework\UrlInterface $url
*/
protected $_url;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_coreConfig;

/**
* List of required request parameters
* Order sensitive
Expand All @@ -46,92 +36,6 @@ class Router extends \Magento\Framework\App\Router\Base
*/
protected $pathPrefix = \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE;

/**
* @param \Magento\Framework\App\Router\ActionList $actionList
* @param \Magento\Framework\App\ActionFactory $actionFactory
* @param \Magento\Framework\App\DefaultPathInterface $defaultPath
* @param \Magento\Framework\App\ResponseFactory $responseFactory
* @param \Magento\Framework\App\Route\ConfigInterface $routeConfig
* @param \Magento\Framework\UrlInterface $url
* @param string $routerId
* @param \Magento\Framework\Code\NameBuilder $nameBuilder
* @param \Magento\Framework\App\Router\PathConfigInterface $pathConfig
* @param \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig
* @param \Magento\Backend\App\ConfigInterface $backendConfig
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Framework\App\Router\ActionList $actionList,
\Magento\Framework\App\ActionFactory $actionFactory,
\Magento\Framework\App\DefaultPathInterface $defaultPath,
\Magento\Framework\App\ResponseFactory $responseFactory,
\Magento\Framework\App\Route\ConfigInterface $routeConfig,
\Magento\Framework\UrlInterface $url,
$routerId,
\Magento\Framework\Code\NameBuilder $nameBuilder,
\Magento\Framework\App\Router\PathConfigInterface $pathConfig,
\Magento\Framework\App\Config\ScopeConfigInterface $coreConfig,
\Magento\Backend\App\ConfigInterface $backendConfig
) {
parent::__construct(
$actionList,
$actionFactory,
$defaultPath,
$responseFactory,
$routeConfig,
$url,
$routerId,
$nameBuilder,
$pathConfig
);
$this->_coreConfig = $coreConfig;
$this->_backendConfig = $backendConfig;
$this->_url = $url;
}

/**
* Get router default request path
* @return string
*/
protected function _getDefaultPath()
{
return (string)$this->_backendConfig->getValue('web/default/admin');
}

/**
* Check whether URL for corresponding path should use https protocol
*
* @param string $path
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _shouldBeSecure($path)
{
return substr(
(string)$this->_coreConfig->getValue('web/unsecure/base_url', 'default'),
0,
5
) === 'https' || $this->_backendConfig->isSetFlag(
'web/secure/use_in_adminhtml'
) && substr(
(string)$this->_coreConfig->getValue('web/secure/base_url', 'default'),
0,
5
) === 'https';
}

/**
* Retrieve current secure url
*
* @param \Magento\Framework\App\RequestInterface $request
* @return string
*/
protected function _getCurrentSecureUrl($request)
{
return $this->_url->getBaseUrl('link', true) . ltrim($request->getPathInfo(), '/');
}

/**
* Check whether redirect should be used for secure routes
*
Expand Down
87 changes: 87 additions & 0 deletions app/code/Magento/Backend/Model/AdminPathConfig.php
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 app/code/Magento/Backend/Test/Unit/Model/AdminPathConfigTest.php
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());
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@
<argument name="xFrameOpt" xsi:type="const">Magento\Framework\App\Response\XFrameOptPlugin::BACKEND_X_FRAME_OPT</argument>
</arguments>
</type>
<preference for="Magento\Framework\App\Router\PathConfigInterface" type="Magento\Backend\Model\AdminPathConfig" />
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -219,22 +219,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
]
);

$rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
$sourceFile = $this->assetSource->findSource($asset);
$content = \file_get_contents($sourceFile);
$relativePath = $rootDir->getRelativePath($sourceFile);
$content = $rootDir->readFile($relativePath);

$chain = $this->chainFactory->create(
[
'asset' => $asset,
'origContent' => $content,
'origContentType' => $asset->getContentType(),
'origAssetPath' => $asset->getFilePath()
'origAssetPath' => $relativePath
]
);

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

$targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
$rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $rootDir->getRelativePath($processedCoreFile);
$destination = $asset->getPath();
$rootDir->copyFile($source, $destination, $targetDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public function testExecute()
->method('create')
->with('less')
->willReturn($this->getMock('Magento\Framework\View\Asset\SourceFileGeneratorInterface'));
$asset = $this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface');
$asset->expects($this->once())->method('getContentType')->willReturn('type');
$this->assetRepo->expects($this->once())
->method('createAsset')
->with(
Expand All @@ -123,18 +125,28 @@ public function testExecute()
'locale' => 'en_US'
]
)
->willReturn(
$this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface')
);
->willReturn($asset);
$this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null');

$this->chainFactory->expects($this->once())->method('create')->willReturn(
$this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false)
);
$this->chainFactory->expects($this->once())
->method('create')
->with(
[
'asset' => $asset,
'origContent' => 'content',
'origContentType' => 'type',
'origAssetPath' => 'relative/path',
]
)
->willReturn($this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false));

$this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn(
$rootDir = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteInterface', [], [], '', false);
$this->filesystem->expects($this->at(0))->method('getDirectoryWrite')->willReturn($rootDir);
$this->filesystem->expects($this->at(1))->method('getDirectoryWrite')->willReturn(
$this->getMock('\Magento\Framework\Filesystem\Directory\WriteInterface', [], [], '', false)
);
$rootDir->expects($this->atLeastOnce())->method('getRelativePath')->willReturn('relative/path');
$rootDir->expects($this->once())->method('readFile')->willReturn('content');

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

Expand Down
Loading

0 comments on commit 3cf2916

Please sign in to comment.