Skip to content

Commit

Permalink
Merge pull request #217 from magento-ogre/PR_Branch
Browse files Browse the repository at this point in the history
[Ogre] Magento CLI, Deployment Configuration Management Command
  • Loading branch information
mazhalai committed Apr 8, 2015
2 parents c915f36 + 45c2142 commit af0a10d
Show file tree
Hide file tree
Showing 108 changed files with 3,429 additions and 1,943 deletions.
4 changes: 3 additions & 1 deletion app/code/Magento/AdminNotification/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\AdminNotification\Model;

use Magento\Framework\Config\ConfigOptionsList;

/**
* AdminNotification Feed model
*
Expand Down Expand Up @@ -135,7 +137,7 @@ public function checkUpdate()

$feedXml = $this->getFeedData();

$installDate = strtotime($this->_deploymentConfig->get('install/date'));
$installDate = strtotime($this->_deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE));

if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
foreach ($feedXml->channel->item as $item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\AdminNotification\Test\Unit\Model;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\Config\ConfigOptionsList;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -140,7 +141,8 @@ public function testCheckUpdate($callInbox, $curlRequest)
$this->backendConfig->expects($this->at(1))->method('getValue')
->will($this->returnValue('http://feed.magento.com'));
$this->deploymentConfig->expects($this->once())->method('get')
->with('install/date')->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC'));
->with(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)
->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC'));
if ($callInbox) {
$this->inboxFactory->expects($this->once())->method('create')
->will(($this->returnValue($this->inboxModel)));
Expand Down
5 changes: 2 additions & 3 deletions app/code/Magento/Backend/App/Area/FrontNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace Magento\Backend\App\Area;

use Magento\Backend\Setup\ConfigOptionsList;
use Magento\Framework\App\DeploymentConfig;

class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolverInterface
Expand All @@ -15,8 +16,6 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver

const XML_PATH_CUSTOM_ADMIN_PATH = 'admin/url/custom_path';

const PARAM_BACKEND_FRONT_NAME = 'backend/frontName';

/**
* Backend area code
*/
Expand Down Expand Up @@ -46,7 +45,7 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
public function __construct(\Magento\Backend\App\Config $config, DeploymentConfig $deploymentConfig)
{
$this->config = $config;
$this->defaultFrontName = $deploymentConfig->get(self::PARAM_BACKEND_FRONT_NAME);
$this->defaultFrontName = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions app/code/Magento/Backend/Helper/Dashboard/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Backend\Helper\Dashboard;

use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Config\ConfigOptionsList;

/**
* Data helper for dashboard
Expand All @@ -22,11 +23,6 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
*/
protected $_installDate;

/**
* Configuration key to installation date
*/
const INSTALL_DATE = 'install/date';

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
Expand All @@ -45,7 +41,7 @@ public function __construct(
parent::__construct(
$context
);
$this->_installDate = $deploymentConfig->get(self::INSTALL_DATE);
$this->_installDate = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE);
$this->_storeManager = $storeManager;
}

Expand Down
74 changes: 74 additions & 0 deletions app/code/Magento/Backend/Setup/ConfigOptionsList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Setup;

use Magento\Framework\Config\Data\ConfigData;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Setup\ConfigOptionsListInterface;
use Magento\Framework\Setup\Option\TextConfigOption;
use Magento\Framework\App\DeploymentConfig;

/*
* Deployment configuration options needed for Backend module
*/
class ConfigOptionsList implements ConfigOptionsListInterface
{
/**
* Input key for the options
*/
const INPUT_KEY_BACKEND_FRONTNAME = 'backend_frontname';

/**
* Path to the values in the deployment config
*/
const CONFIG_PATH_BACKEND_FRONTNAME = 'backend/frontName';

/**
* {@inheritdoc}
*/
public function getOptions()
{
return [
new TextConfigOption(
self::INPUT_KEY_BACKEND_FRONTNAME,
TextConfigOption::FRONTEND_WIZARD_TEXT,
self::CONFIG_PATH_BACKEND_FRONTNAME,
'Backend frontname',
'admin'
)
];
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function createConfig(array $options, DeploymentConfig $deploymentConfig)
{
$configData = new ConfigData(ConfigFilePool::APP_CONFIG);

if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])) {
$configData->set(self::CONFIG_PATH_BACKEND_FRONTNAME, $options[self::INPUT_KEY_BACKEND_FRONTNAME]);
}

return [$configData];
}

/**
* {@inheritdoc}
*/
public function validate(array $options)
{
$errors = [];
if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])
&& !preg_match('/^[a-zA-Z0-9_]+$/', $options[self::INPUT_KEY_BACKEND_FRONTNAME])
) {
$errors[] = "Invalid backend frontname '{$options[self::INPUT_KEY_BACKEND_FRONTNAME]}'";
}

return $errors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Backend\Test\Unit\App\Area;

use Magento\Backend\App\Area\FrontNameResolver;
use Magento\Backend\Setup\ConfigOptionsList;

class FrontNameResolverTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -29,10 +30,10 @@ protected function setUp()
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
$deploymentConfigMock->expects($this->once())
->method('get')
->with(FrontNameResolver::PARAM_BACKEND_FRONT_NAME)
->with(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME)
->will($this->returnValue($this->_defaultFrontName));
$this->_configMock = $this->getMock('\Magento\Backend\App\Config', [], [], '', false);
$this->_model = new \Magento\Backend\App\Area\FrontNameResolver($this->_configMock, $deploymentConfigMock);
$this->_model = new FrontNameResolver($this->_configMock, $deploymentConfigMock);
}

public function testIfCustomPathUsed()
Expand Down
93 changes: 93 additions & 0 deletions app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Test\Unit\Setup;

use Magento\Backend\Setup\ConfigOptionsList;
use Magento\Framework\Config\File\ConfigFilePool;

class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ConfigOptionsList
*/
private $object;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig
*/
private $deploymentConfig;

protected function setUp()
{
$this->object = new ConfigOptionsList();
$this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
}

public function testGetOptions()
{
$options = $this->object->getOptions();
$this->assertInternalType('array', $options);
foreach ($options as $option) {
$this->assertInstanceOf('\Magento\Framework\Setup\Option\AbstractConfigOption', $option);
}
}

public function testCreateConfig()
{
$options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin'];
$actualConfig = $this->object->createConfig($options, $this->deploymentConfig);

$expectedData = [
[
'file' => ConfigFilePool::APP_CONFIG,
'segment' => 'backend',
'data' => [
'backend' => ['frontName' => 'admin']
]
]
];

$this->assertInternalType('array', $actualConfig);
/** @var \Magento\Framework\Config\Data\ConfigData $config */
foreach ($actualConfig as $i => $config) {
$this->assertInstanceOf('\Magento\Framework\Config\Data\ConfigData', $config);
$this->assertSame($expectedData[$i]['file'], $config->getFileKey());
$this->assertSame($expectedData[$i]['data'], $config->getData());
}
}

public function testValidate()
{
$options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin'];
$errors = $this->object->validate($options);
$this->assertEmpty($errors);
}

/**
* @param array $options
* @param string $expectedError
* @dataProvider validateInvalidDataProvider
*/
public function testValidateInvalid(array $options, $expectedError)
{
$errors = $this->object->validate($options);
$this->assertSame([$expectedError], $errors);
}

/**
* @return array
*/
public function validateInvalidDataProvider()
{
return [
[[ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => '**'], "Invalid backend frontname '**'"],
[
[ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'invalid frontname'],
"Invalid backend frontname 'invalid frontname'"
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
namespace Magento\MediaStorage\Model\Config\Source\Storage\Media;

use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\DeploymentConfig\ResourceConfig;
use Magento\Framework\Config\ConfigOptionsList;

class Database implements \Magento\Framework\Option\ArrayInterface
{
/**
* @var DeploymentConfig
*/
protected $_deploymentConfig;
protected $deploymentConfig;

/**
* @param DeploymentConfig $deploymentConfig
*/
public function __construct(DeploymentConfig $deploymentConfig)
{
$this->_deploymentConfig = $deploymentConfig;
$this->deploymentConfig = $deploymentConfig;
}

/**
Expand All @@ -35,10 +35,9 @@ public function __construct(DeploymentConfig $deploymentConfig)
public function toOptionArray()
{
$resourceOptions = [];
$resourceInfo = $this->_deploymentConfig->getSegment(ResourceConfig::CONFIG_KEY);
if (null !== $resourceInfo) {
$resourceConfig = new ResourceConfig($resourceInfo);
foreach (array_keys($resourceConfig->getData()) as $resourceName) {
$resourceConfig = $this->deploymentConfig->get(ConfigOptionsList::KEY_RESOURCE);
if (null !== $resourceConfig) {
foreach (array_keys($resourceConfig) as $resourceName) {
$resourceOptions[] = ['value' => $resourceName, 'label' => $resourceName];
}
sort($resourceOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

namespace Magento\MediaStorage\Test\Unit\Model\Config\Source\Storage\Media;

use Magento\Framework\App\DeploymentConfig\ResourceConfig;
use Magento\Framework\Config\ConfigOptionsList;
use Magento\MediaStorage\Model\Config\Source\Storage\Media\Database;

/**
* Class DatabaseTest
Expand All @@ -23,25 +24,26 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
/**
* @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configMock;
protected $deploymentConfig;

protected function setUp()
{
$this->configMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
$this->configMock->expects(
$this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
$this->deploymentConfig->expects(
$this->any()
)->method(
'getSegment'
'get'
)->with(
ResourceConfig::CONFIG_KEY
'resource'
)->will(
$this->returnValue(
['default_setup' => ['name' => 'default_setup', ResourceConfig::KEY_CONNECTION => 'connect1'],
'custom_resource' => ['name' => 'custom_resource', ResourceConfig::KEY_CONNECTION => 'connect2'],
[
'default_setup' => ['name' => 'default_setup', 'connection' => 'connect1'],
'custom_resource' => ['name' => 'custom_resource', 'connection' => 'connect2'],
]
)
);
$this->mediaDatabase = new \Magento\MediaStorage\Model\Config\Source\Storage\Media\Database($this->configMock);
$this->mediaDatabase = new Database($this->deploymentConfig);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
</type>
<type name="Magento\Backend\App\Area\FrontNameResolver">
<arguments>
<argument name="defaultFrontName" xsi:type="init_parameter">Magento\Backend\App\Area\FrontNameResolver::PARAM_BACKEND_FRONT_NAME</argument>
<argument name="defaultFrontName" xsi:type="init_parameter">Magento\Backend\Setup\ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME</argument>
</arguments>
</type>
<type name="Magento\Framework\App\Cache\State">
Expand Down Expand Up @@ -305,7 +305,6 @@
<arguments>
<argument name="reader" xsi:type="object">Magento\Framework\App\Resource\Config\Reader\Proxy</argument>
<argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Config\Proxy</argument>
<argument name="initialResources" xsi:type="object">Magento\Framework\App\DeploymentConfig\ResourceConfig</argument>
</arguments>
</type>
<type name="Magento\Framework\App\Resource\Config\Reader">
Expand Down
2 changes: 2 additions & 0 deletions bin/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Order deny,allow
Deny from all
Loading

0 comments on commit af0a10d

Please sign in to comment.