init
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Config\App\Config\Type;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Config/_files/config_data.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class SystemTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var System
|
||||
*/
|
||||
private $system;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->system = $this->objectManager->create(System::class);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
unset($_ENV['CONFIG__STORES__DEFAULT__ABC__QRS__XYZ']);
|
||||
}
|
||||
|
||||
public function testGetValueDefaultScope()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'value1.db.default.test',
|
||||
$this->system->get('default/web/test/test_value_1')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'value1.db.website_base.test',
|
||||
$this->system->get('websites/base/web/test/test_value_1')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'value1.db.store_default.test',
|
||||
$this->system->get('stores/default/web/test/test_value_1')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that configurations added as env variables don't cause the error 'Recursion detected'
|
||||
* after cleaning the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEnvGetValueStoreScope()
|
||||
{
|
||||
$_ENV['CONFIG__STORES__DEFAULT__ABC__QRS__XYZ'] = 'test_env_value';
|
||||
$this->system->clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'value1.db.default.test',
|
||||
$this->system->get('default/web/test/test_value_1')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'test_env_value',
|
||||
$this->system->get('stores/default/abc/qrs/xyz')
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($_ENV['CONFIG__STORES__DEFAULT__ABC__QRS__XYZ']);
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Config\Block\System\Config;
|
||||
|
||||
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
|
||||
|
||||
/**
|
||||
* Backend system config array field renderer for integration test.
|
||||
*/
|
||||
class FieldArray extends AbstractFieldArray
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _toHtml()
|
||||
{
|
||||
$value = '';
|
||||
$element = $this->getElement();
|
||||
if ($element->getValue() && is_array($element->getValue())) {
|
||||
$value = implode('|', $element->getValue());
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<input id="%s" name="%s" value="%s" />',
|
||||
$element->getId(),
|
||||
$element->getName(),
|
||||
$value
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Stub system config form block for integration test
|
||||
*/
|
||||
namespace Magento\Config\Block\System\Config;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.DepthOfInheritance)
|
||||
*/
|
||||
class FormStub extends \Magento\Config\Block\System\Config\Form
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_configDataStub = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_configRootStub = [];
|
||||
|
||||
/**
|
||||
* Sets stub config data
|
||||
*
|
||||
* @param array $configData
|
||||
*/
|
||||
public function setStubConfigData(array $configData = [])
|
||||
{
|
||||
$this->_configDataStub = $configData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets stub config root
|
||||
*
|
||||
* @param array $configRoot
|
||||
* @return void
|
||||
*/
|
||||
public function setStubConfigRoot(array $configRoot = [])
|
||||
{
|
||||
$this->_configRootStub = $configRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize properties of object required for test.
|
||||
*
|
||||
* @return \Magento\Config\Block\System\Config\Form
|
||||
*/
|
||||
protected function _initObjects()
|
||||
{
|
||||
$result = parent::_initObjects();
|
||||
$this->_configData = $this->_configDataStub;
|
||||
$this->_fieldRenderer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Config\Block\System\Config\Form\Field::class
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,605 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Config\Block\System\Config;
|
||||
|
||||
use Magento\Backend\App\Area\FrontNameResolver;
|
||||
use Magento\Framework\App\Cache\State;
|
||||
use Magento\Framework\Config\FileResolverInterface;
|
||||
use Magento\Framework\Config\ScopeInterface;
|
||||
use Magento\Framework\View\Element\Text;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class FormTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Data\FormFactory
|
||||
*/
|
||||
private $formFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Config\Model\Config\Structure\Element\Section
|
||||
*/
|
||||
private $section;
|
||||
|
||||
/**
|
||||
* @var \Magento\Config\Model\Config\Structure\Element\Group
|
||||
*/
|
||||
private $group;
|
||||
|
||||
/**
|
||||
* @var \Magento\Config\Model\Config\Structure\Element\Field
|
||||
*/
|
||||
private $field;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $configData;
|
||||
|
||||
/** @var string Encrypted value stored in config.xml */
|
||||
private static $defaultConfigEncrypted = 'Encrypted value';
|
||||
|
||||
/** @var array Serialized value stored in config.xml */
|
||||
private static $defaultConfigSerialized = ['value1', 'value2'];
|
||||
|
||||
/** @var string Serialized value stored in config.xml */
|
||||
private static $defaultConfigString = 'test config value';
|
||||
|
||||
/** @var string Encrypted value stored in DB */
|
||||
private static $websiteDbEncrypted = 'DB encrypted value';
|
||||
|
||||
/** @var array Serialized value stored in DB */
|
||||
private static $websiteDbSerialized = ['value3', 'value4'];
|
||||
|
||||
/** @var string String value stored in DB */
|
||||
private static $websiteDBString = 'test db value';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->formFactory = $this->objectManager->create(\Magento\Framework\Data\FormFactory::class);
|
||||
}
|
||||
|
||||
public function testDependenceHtml()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\LayoutInterface */
|
||||
$layout = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Layout::class,
|
||||
['area' => 'adminhtml']
|
||||
);
|
||||
Bootstrap::getObjectManager()->get(
|
||||
ScopeInterface::class
|
||||
)->setCurrentScope(
|
||||
FrontNameResolver::AREA_CODE
|
||||
);
|
||||
/** @var $block Form */
|
||||
$block = $layout->createBlock(Form::class, 'block');
|
||||
|
||||
/** @var $childBlock Text */
|
||||
$childBlock = $layout->addBlock(Text::class, 'element_dependence', 'block');
|
||||
|
||||
$expectedValue = 'dependence_html_relations';
|
||||
$this->assertStringNotContainsString($expectedValue, $block->toHtml());
|
||||
|
||||
$childBlock->setText($expectedValue);
|
||||
$this->assertStringContainsString($expectedValue, $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Config\Block\System\Config\Form::initFields
|
||||
* @param string $fieldId uses the test_field_use_config field if true
|
||||
* @param bool $isConfigDataEmpty if the config data array should be empty or not
|
||||
* @param string $configDataValue The value that the field path should be set to in the config data
|
||||
* @param int $valueSelCtr Number of time that value is selected
|
||||
* @param bool $expectedUseDefault
|
||||
* @dataProvider initFieldsUseDefaultCheckboxDataProvider
|
||||
*/
|
||||
public function testInitFieldsUseDefaultCheckbox(
|
||||
$fieldId,
|
||||
$isConfigDataEmpty,
|
||||
$configDataValue,
|
||||
$expectedUseDefault,
|
||||
$valueSelCtr = 1
|
||||
) {
|
||||
$this->_setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue);
|
||||
|
||||
Bootstrap::getObjectManager()->get(
|
||||
ScopeInterface::class
|
||||
)->setCurrentScope(
|
||||
FrontNameResolver::AREA_CODE
|
||||
);
|
||||
$form = $this->formFactory->create();
|
||||
$fieldset = $form->addFieldset($this->section->getId() . '_' . $this->group->getId(), []);
|
||||
|
||||
/* @TODO Eliminate stub by proper mock / config fixture usage */
|
||||
/** @var $block FormStub */
|
||||
$block = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
FormStub::class
|
||||
);
|
||||
$block->setScope(Form::SCOPE_WEBSITES);
|
||||
$block->setStubConfigData($this->configData);
|
||||
$block->initFields($fieldset, $this->group, $this->section);
|
||||
|
||||
$valueSel = sprintf(
|
||||
'//input[@id="%s_%s_%s"]',
|
||||
$this->section->getId(),
|
||||
$this->group->getId(),
|
||||
$this->field->getId()
|
||||
);
|
||||
$valueDisabledSel = sprintf('%s[@disabled="disabled"]', $valueSel);
|
||||
$useDefaultSel = sprintf(
|
||||
'//input[@id="%s_%s_%s_inherit" and contains(@class,"checkbox")]',
|
||||
$this->section->getId(),
|
||||
$this->group->getId(),
|
||||
$this->field->getId()
|
||||
);
|
||||
$useDefaultCheckedSel = sprintf('%s[@checked="checked"]', $useDefaultSel);
|
||||
$fieldsetHtml = $fieldset->getElementHtml();
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath('//fieldset', $fieldsetHtml),
|
||||
'Fieldset HTML is invalid'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$valueSelCtr,
|
||||
Xpath::getElementsCountForXpath($valueSel, $fieldsetHtml),
|
||||
'Field input should appear ' . $valueSelCtr . ' times in fieldset HTML'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$valueSelCtr,
|
||||
Xpath::getElementsCountForXpath($useDefaultSel, $fieldsetHtml),
|
||||
'"Use Default" checkbox should appear' . $valueSelCtr . ' times in fieldset HTML.'
|
||||
);
|
||||
|
||||
if ($expectedUseDefault) {
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($useDefaultCheckedSel, $fieldsetHtml),
|
||||
'"Use Default" checkbox should be checked'
|
||||
);
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($valueDisabledSel, $fieldsetHtml),
|
||||
'Field input should be disabled'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
0,
|
||||
Xpath::getElementsCountForXpath($useDefaultCheckedSel, $fieldsetHtml),
|
||||
'"Use Default" checkbox should not be checked'
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
Xpath::getElementsCountForXpath($valueDisabledSel, $fieldsetHtml),
|
||||
'Field input should not be disabled'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function initFieldsUseDefaultCheckboxDataProvider()
|
||||
{
|
||||
return [
|
||||
['test_field', true, null, true],
|
||||
['test_field', false, null, false],
|
||||
['test_field', false, '', false],
|
||||
['test_field', false, 'value', false],
|
||||
['test_field_use_config_module_1', false, 'config value', false],
|
||||
['test_field_use_config_module_0', false, 'config value', false, 0],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Config\Block\System\Config\Form::initFields
|
||||
* @param string $fieldId uses the test_field_use_config field if true
|
||||
* @param bool $isConfigDataEmpty if the config data array should be empty or not
|
||||
* @param string $configDataValue Value that the field path should be set to in the config data
|
||||
* @param int $valueSelCtr Number of time that value is selected
|
||||
* @dataProvider initFieldsUseConfigPathDataProvider
|
||||
* @magentoConfigFixture default/test_config_section/test_group_config_node/test_field_value config value
|
||||
*/
|
||||
public function testInitFieldsUseConfigPath($fieldId, $isConfigDataEmpty, $configDataValue, $valueSelCtr = 1)
|
||||
{
|
||||
$this->_setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue);
|
||||
|
||||
Bootstrap::getObjectManager()->get(
|
||||
ScopeInterface::class
|
||||
)->setCurrentScope(
|
||||
FrontNameResolver::AREA_CODE
|
||||
);
|
||||
$form = $this->formFactory->create();
|
||||
$fieldset = $form->addFieldset($this->section->getId() . '_' . $this->group->getId(), []);
|
||||
|
||||
/* @TODO Eliminate stub by proper mock / config fixture usage */
|
||||
/** @var $block FormStub */
|
||||
$block = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
FormStub::class
|
||||
);
|
||||
$block->setScope(Form::SCOPE_DEFAULT);
|
||||
$block->setStubConfigData($this->configData);
|
||||
$block->initFields($fieldset, $this->group, $this->section);
|
||||
|
||||
$valueSel = sprintf(
|
||||
'//input[@id="%s_%s_%s"]',
|
||||
$this->section->getId(),
|
||||
$this->group->getId(),
|
||||
$this->field->getId()
|
||||
);
|
||||
$fieldsetHtml = $fieldset->getElementHtml();
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
'//fieldset',
|
||||
$fieldsetHtml
|
||||
),
|
||||
'Fieldset HTML is invalid'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$valueSelCtr,
|
||||
Xpath::getElementsCountForXpath(
|
||||
$valueSel,
|
||||
$fieldsetHtml
|
||||
),
|
||||
'Field input should appear ' . $valueSelCtr . ' times in fieldset HTML'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function initFieldsUseConfigPathDataProvider()
|
||||
{
|
||||
return [
|
||||
['test_field', true, null],
|
||||
['test_field', false, null],
|
||||
['test_field', false, ''],
|
||||
['test_field', false, 'value'],
|
||||
['test_field_use_config_module_1', false, 'config value'],
|
||||
['test_field_use_config_module_0', false, 'config value', 0]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases with retrieving config data with backend models for different scopes.
|
||||
* Config data are stored in config.xml and database.
|
||||
*
|
||||
* @param string $fieldId
|
||||
* @param string $expectedConfigValue
|
||||
* @param string $currentScope
|
||||
* @param string $currentScopeCode
|
||||
* @param bool $isDbOverrideValue whether values should be overridden in the database for the current scope
|
||||
*
|
||||
* @dataProvider initFieldsWithBackendModelDataProvider
|
||||
* @covers \Magento\Config\Block\System\Config\Form::initFields
|
||||
*/
|
||||
public function testInitFieldsWithBackendModel(
|
||||
$fieldId,
|
||||
$expectedConfigValue,
|
||||
$currentScope,
|
||||
$currentScopeCode,
|
||||
$isDbOverrideValue
|
||||
) {
|
||||
$this->_setupFieldsInheritCheckbox($fieldId, false, $expectedConfigValue);
|
||||
|
||||
if ($isDbOverrideValue) {
|
||||
$backendModel = $this->field->getAttribute('backend_model') ?: \Magento\Framework\App\Config\Value::class;
|
||||
$path = $this->section->getId() . '/' . $this->group->getId() . '/' . $this->field->getId();
|
||||
$model = Bootstrap::getObjectManager()->create($backendModel);
|
||||
$model->setPath($path);
|
||||
$model->setScopeId($currentScopeCode);
|
||||
$model->setScope($currentScope);
|
||||
$model->setScopeCode($currentScopeCode);
|
||||
$model->setValue($expectedConfigValue);
|
||||
$model->save();
|
||||
}
|
||||
|
||||
$this->registerTestConfigXmlMetadata();
|
||||
Bootstrap::getObjectManager()->get(\Magento\TestFramework\App\Config::class)->clean();
|
||||
|
||||
$form = $this->formFactory->create();
|
||||
$fieldset = $form->addFieldset($this->section->getId() . '_' . $this->group->getId(), []);
|
||||
|
||||
/** @var $block FormStub */
|
||||
$block = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
FormStub::class
|
||||
);
|
||||
|
||||
$block->setScope($currentScope);
|
||||
$block->setScopeCode($currentScopeCode);
|
||||
$block->setStubConfigData($this->configData);
|
||||
$block->initFields($fieldset, $this->group, $this->section);
|
||||
|
||||
$fieldsetHtml = $fieldset->getElementHtml();
|
||||
|
||||
$elementId = $this->section->getId() . '_' . $this->group->getId() . '_' . $this->field->getId();
|
||||
if (is_array($expectedConfigValue)) {
|
||||
$expectedConfigValue = implode('|', $expectedConfigValue);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expectedConfigValue,
|
||||
$this->getElementAttributeValueById($fieldsetHtml, $elementId)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides config data variations with different data types and scopes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function initFieldsWithBackendModelDataProvider()
|
||||
{
|
||||
return [
|
||||
/** Values stored in config.xml only for default scope, then retrieved for default scope. */
|
||||
['test_field_encrypted', self::$defaultConfigEncrypted, FormStub::SCOPE_DEFAULT, 0, false],
|
||||
['test_field_serialized', self::$defaultConfigSerialized, FormStub::SCOPE_DEFAULT, 0, false],
|
||||
['test_field', self::$defaultConfigString, FormStub::SCOPE_DEFAULT, 0, false],
|
||||
|
||||
/** Values stored in config.xml only for default scope, then retrieved for website scope. */
|
||||
['test_field_encrypted', self::$defaultConfigEncrypted, FormStub::SCOPE_WEBSITES, 1, false],
|
||||
['test_field_serialized', self::$defaultConfigSerialized, FormStub::SCOPE_WEBSITES, 1, false],
|
||||
['test_field', self::$defaultConfigString, FormStub::SCOPE_WEBSITES, 1, false],
|
||||
|
||||
/**
|
||||
* Values stored in config.xml for default scope and in database for website scope,
|
||||
* then retrieved for website scope.
|
||||
*/
|
||||
['test_field_encrypted', self::$websiteDbEncrypted, FormStub::SCOPE_WEBSITES, 1, true],
|
||||
['test_field_serialized', self::$websiteDbSerialized, FormStub::SCOPE_WEBSITES, 1, true],
|
||||
['test_field', self::$websiteDBString, FormStub::SCOPE_WEBSITES, 1, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fieldId uses the test_field_use_config field if true
|
||||
* @param bool $isConfigDataEmpty if the config data array should be empty or not
|
||||
* @param string $configDataValue the value that the field path should be set to in the config data
|
||||
*/
|
||||
protected function _setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue)
|
||||
{
|
||||
Bootstrap::getInstance()->reinitialize([
|
||||
State::PARAM_BAN_CACHE => true,
|
||||
]);
|
||||
Bootstrap::getObjectManager()
|
||||
->get(ScopeInterface::class)
|
||||
->setCurrentScope(FrontNameResolver::AREA_CODE);
|
||||
Bootstrap::getObjectManager()->get(\Magento\Framework\App\AreaList::class)
|
||||
->getArea(FrontNameResolver::AREA_CODE)
|
||||
->load(\Magento\Framework\App\Area::PART_CONFIG);
|
||||
|
||||
$fileResolverMock = $this->getMockBuilder(
|
||||
\Magento\Framework\App\Config\FileResolver::class
|
||||
)->disableOriginalConstructor()->getMock();
|
||||
$fileIteratorFactory = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Config\FileIteratorFactory::class
|
||||
);
|
||||
$fileIterator = $fileIteratorFactory->create(
|
||||
[__DIR__ . '/_files/test_system.xml']
|
||||
);
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($fileIterator);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$structureReader = $objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure\Reader::class,
|
||||
['fileResolver' => $fileResolverMock]
|
||||
);
|
||||
$structureData = $objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure\Data::class,
|
||||
['reader' => $structureReader]
|
||||
);
|
||||
/** @var \Magento\Config\Model\Config\Structure $structure */
|
||||
$structure = $objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure::class,
|
||||
['structureData' => $structureData]
|
||||
);
|
||||
|
||||
$this->section = $structure->getElement('test_section');
|
||||
|
||||
$this->group = $structure->getElement('test_section/test_group');
|
||||
|
||||
$this->field = $structure->getElement('test_section/test_group/' . $fieldId);
|
||||
|
||||
$fieldPath = $this->field->getConfigPath();
|
||||
|
||||
if ($isConfigDataEmpty) {
|
||||
$this->configData = [];
|
||||
} else {
|
||||
$this->configData = [$fieldPath => $configDataValue];
|
||||
}
|
||||
}
|
||||
|
||||
public function testInitFormAddsFieldsets()
|
||||
{
|
||||
Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\ResponseInterface::class
|
||||
)->headersSentThrowsException = false;
|
||||
Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\RequestInterface::class
|
||||
)->setParam(
|
||||
'section',
|
||||
'general'
|
||||
);
|
||||
/** @var $block Form */
|
||||
$block = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
Form::class
|
||||
);
|
||||
$block->initForm();
|
||||
$expectedIds = [
|
||||
'general_country' => [
|
||||
'general_country_default' => 'select',
|
||||
'general_country_allow' => 'select',
|
||||
'general_country_optional_zip_countries' => 'select',
|
||||
'general_country_eu_countries' => 'select',
|
||||
],
|
||||
'general_region' => [
|
||||
'general_region_state_required' => 'select',
|
||||
'general_region_display_all' => 'select',
|
||||
],
|
||||
'general_locale' => [
|
||||
'general_locale_timezone' => 'select',
|
||||
'general_locale_code' => 'select',
|
||||
'general_locale_firstday' => 'select',
|
||||
'general_locale_weekend' => 'select',
|
||||
],
|
||||
'general_restriction' => [
|
||||
'general_restriction_is_active' => 'select',
|
||||
'general_restriction_mode' => 'select',
|
||||
'general_restriction_http_redirect' => 'select',
|
||||
'general_restriction_cms_page' => 'select',
|
||||
'general_restriction_http_status' => 'select',
|
||||
],
|
||||
'general_store_information' => [
|
||||
'general_store_information_name' => 'text',
|
||||
'general_store_information_phone' => 'text',
|
||||
'general_store_information_merchant_country' => 'select',
|
||||
'general_store_information_merchant_vat_number' => 'text',
|
||||
'general_store_information_validate_vat_number' => 'text',
|
||||
'general_store_information_address' => 'textarea',
|
||||
],
|
||||
'general_single_store_mode' => ['general_single_store_mode_enabled' => 'select'],
|
||||
];
|
||||
$elements = $block->getForm()->getElements();
|
||||
foreach ($elements as $element) {
|
||||
/** @var $element \Magento\Framework\Data\Form\Element\Fieldset */
|
||||
$this->assertInstanceOf(
|
||||
\Magento\Framework\Data\Form\Element\Fieldset::class,
|
||||
$element
|
||||
);
|
||||
$this->assertArrayHasKey($element->getId(), $expectedIds);
|
||||
$fields = $element->getElements();
|
||||
$this->assertEquals(count($expectedIds[$element->getId()]), count($fields));
|
||||
foreach ($element->getElements() as $field) {
|
||||
$this->assertArrayHasKey($field->getId(), $expectedIds[$element->getId()]);
|
||||
$this->assertEquals($expectedIds[$element->getId()][$field->getId()], $field->getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add metadata from test_config.xml to metadataConfigTypeProcessor.
|
||||
*/
|
||||
private function registerTestConfigXmlMetadata()
|
||||
{
|
||||
/** @var \Magento\Framework\Encryption\EncryptorInterface $encryptor */
|
||||
$encryptor = Bootstrap::getObjectManager()->get(\Magento\Framework\Encryption\EncryptorInterface::class);
|
||||
$this->setEncryptedValue(
|
||||
$encryptor->encrypt(self::$defaultConfigEncrypted)
|
||||
);
|
||||
|
||||
$fileResolver = Bootstrap::getObjectManager()->create(FileResolverInterface::class);
|
||||
$directories = $fileResolver->get('config.xml', 'global');
|
||||
|
||||
$property = new \ReflectionProperty($directories, 'paths');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue(
|
||||
$directories,
|
||||
array_merge($property->getValue($directories), [__DIR__ . '/_files/test_config.xml'])
|
||||
);
|
||||
|
||||
$fileResolverMock = $this->getMockForAbstractClass(FileResolverInterface::class);
|
||||
$fileResolverMock->method('get')->willReturn($directories);
|
||||
|
||||
$initialReader = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Config\Initial\Reader::class,
|
||||
['fileResolver' => $fileResolverMock]
|
||||
);
|
||||
|
||||
$initialConfig = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Config\Initial::class,
|
||||
['reader' => $initialReader]
|
||||
);
|
||||
$metadataConfigTypeProcessor = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Config\MetadataConfigTypeProcessor::class,
|
||||
['initialConfig' => $initialConfig]
|
||||
);
|
||||
|
||||
$composite = Bootstrap::getObjectManager()->get('systemConfigPostProcessorComposite');
|
||||
$property = new \ReflectionProperty($composite, 'processors');
|
||||
$property->setAccessible(true);
|
||||
$processors = $property->getValue($composite);
|
||||
$processors['metadata'] = $metadataConfigTypeProcessor;
|
||||
$property->setValue($composite, $processors);
|
||||
|
||||
Bootstrap::getObjectManager()->get(\Magento\TestFramework\App\State::class)
|
||||
->setAreaCode(FrontNameResolver::AREA_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds element by id and returns value of attribute value property.
|
||||
*
|
||||
* @param string $html
|
||||
* @param string $nodeId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getElementAttributeValueById($html, $nodeId)
|
||||
{
|
||||
$domDocument = new \DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$domDocument->loadHTML($html);
|
||||
libxml_use_internal_errors(false);
|
||||
$element = $domDocument->getElementById($nodeId);
|
||||
|
||||
return $element ? $element->attributes->getNamedItem('value')->nodeValue : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Save encrypted value to test_config.xml
|
||||
*
|
||||
* @param string $encryptedValue
|
||||
*/
|
||||
private function setEncryptedValue($encryptedValue)
|
||||
{
|
||||
$config = simplexml_load_file(__DIR__ . '/_files/test_config.xml');
|
||||
$config->default->test_section->test_group->test_field_encrypted = $encryptedValue;
|
||||
$config->asXml(__DIR__ . '/_files/test_config.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$reflection = new \ReflectionObject($this);
|
||||
foreach ($reflection->getProperties() as $property) {
|
||||
if (!$property->isStatic() && 0 !== strpos($property->getDeclaringClass()->getName(), 'PHPUnit')) {
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($this, null);
|
||||
}
|
||||
}
|
||||
$this->setEncryptedValue('{ENCRYPTED_VALUE}');
|
||||
|
||||
$configResourceModel = Bootstrap::getObjectManager()->get(\Magento\Config\Model\ResourceModel\Config::class);
|
||||
foreach (['test_field_encrypted', 'test_field_serialized', 'test_field'] as $field) {
|
||||
$path = 'test_section/test_group/' . $field;
|
||||
$configResourceModel->deleteConfig($path, FormStub::SCOPE_WEBSITES, 1);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
|
||||
<default>
|
||||
<test_section>
|
||||
<test_group>
|
||||
<test_field_encrypted backend_model="Magento\Config\Model\Config\Backend\Encrypted">{ENCRYPTED_VALUE}</test_field_encrypted>
|
||||
<test_field_serialized>["value1","value2"]</test_field_serialized>
|
||||
<test_field>test config value</test_field>
|
||||
</test_group>
|
||||
</test_section>
|
||||
</default>
|
||||
</config>
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||
<system>
|
||||
<tab id="Test">
|
||||
<label>Test</label>
|
||||
</tab>
|
||||
<section id="test_section" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="0">
|
||||
<label>Test Section</label>
|
||||
<tab>Test</tab>
|
||||
|
||||
<group id="test_group" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="10">
|
||||
<label>Test Group</label>
|
||||
<field id="test_field_encrypted" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
|
||||
<label>Test Field</label>
|
||||
<config_path>test_section/test_group/test_field_encrypted</config_path>
|
||||
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
|
||||
</field>
|
||||
<field id="test_field_serialized" translate="label comment" showInDefault="1" showInWebsite="0" showInStore="0" type="text" sortOrder="20">
|
||||
<label>Test Field</label>
|
||||
<config_path>test_section/test_group/test_field_serialized</config_path>
|
||||
<frontend_model>Magento\Config\Block\System\Config\FieldArray</frontend_model>
|
||||
<backend_model>Magento\Config\Model\Config\Backend\Serialized</backend_model>
|
||||
</field>
|
||||
<field id="test_field" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
|
||||
<label>Test Field</label>
|
||||
<config_path>test_section/test_group/test_field</config_path>
|
||||
</field>
|
||||
<field id="test_field_use_config_module_1" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
|
||||
<label>Test Field</label>
|
||||
<config_path>test_config_section/test_group_config_node/test_field_value</config_path>
|
||||
<if_module_enabled>Magento_Config</if_module_enabled>
|
||||
</field>
|
||||
<field id="test_field_use_config_module_0" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
|
||||
<label>Test Field</label>
|
||||
<config_path>test_config_section/test_group_config_node/test_field_value</config_path>
|
||||
<if_module_enabled>Test_Module</if_module_enabled>
|
||||
</field>
|
||||
</group>
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
+538
@@ -0,0 +1,538 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Config\Console\Command;
|
||||
|
||||
use Magento\Config\Model\Config\Backend\Admin\Custom;
|
||||
use Magento\Config\Model\Config\PathValidator;
|
||||
use Magento\Config\Model\Config\Structure\Converter;
|
||||
use Magento\Config\Model\Config\Structure\Data as StructureData;
|
||||
use Magento\Directory\Model\Currency;
|
||||
use Magento\Framework\App\Config\ConfigPathResolver;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\App\DeploymentConfig\FileReader;
|
||||
use Magento\Framework\App\DeploymentConfig\Writer;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Config\File\ConfigFilePool;
|
||||
use Magento\Framework\Console\Cli;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Stdlib\ArrayManager;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\App\Config\ReinitableConfigInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject as Mock;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Tests the different flows of config:set command.
|
||||
*
|
||||
* @inheritdoc
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class ConfigSetCommandTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var InputInterface|Mock
|
||||
*/
|
||||
private $inputMock;
|
||||
|
||||
/**
|
||||
* @var OutputInterface|Mock
|
||||
*/
|
||||
private $outputMock;
|
||||
|
||||
/**
|
||||
* @var ScopeConfigInterface
|
||||
*/
|
||||
private $scopeConfig;
|
||||
|
||||
/**
|
||||
* @var FileReader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
private $filesystem;
|
||||
|
||||
/**
|
||||
* @var ConfigFilePool
|
||||
*/
|
||||
private $configFilePool;
|
||||
|
||||
/**
|
||||
* @var ArrayManager
|
||||
*/
|
||||
private $arrayManager;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var ReinitableConfigInterface
|
||||
*/
|
||||
private $appConfig;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
Bootstrap::getInstance()->reinitialize();
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->extendSystemStructure();
|
||||
|
||||
$this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
|
||||
$this->reader = $this->objectManager->get(FileReader::class);
|
||||
$this->filesystem = $this->objectManager->get(Filesystem::class);
|
||||
$this->configFilePool = $this->objectManager->get(ConfigFilePool::class);
|
||||
$this->arrayManager = $this->objectManager->get(ArrayManager::class);
|
||||
$this->appConfig = $this->objectManager->get(ReinitableConfigInterface::class);
|
||||
|
||||
// Snapshot of configuration.
|
||||
$this->config = $this->loadConfig();
|
||||
|
||||
// Mocks for objects.
|
||||
$this->inputMock = $this->getMockBuilder(InputInterface::class)
|
||||
->getMockForAbstractClass();
|
||||
$this->outputMock = $this->getMockBuilder(OutputInterface::class)
|
||||
->getMockForAbstractClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
|
||||
$this->configFilePool->getPath(ConfigFilePool::APP_ENV),
|
||||
"<?php\n return array();\n"
|
||||
);
|
||||
/** @var Writer $writer */
|
||||
$writer = $this->objectManager->get(Writer::class);
|
||||
$writer->saveConfig([ConfigFilePool::APP_ENV => $this->config]);
|
||||
$this->appConfig->reinit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add test system structure to main system structure
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function extendSystemStructure()
|
||||
{
|
||||
$document = new \DOMDocument();
|
||||
$document->load(__DIR__ . '/../../_files/system.xml');
|
||||
$converter = $this->objectManager->get(Converter::class);
|
||||
$systemConfig = $converter->convert($document);
|
||||
$structureData = $this->objectManager->get(StructureData::class);
|
||||
$structureData->merge($systemConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function loadConfig()
|
||||
{
|
||||
return $this->reader->load(ConfigFilePool::APP_ENV);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests lockable flow.
|
||||
* Expects to save value and then error on saving duplicate value.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $value
|
||||
* @param string $scope
|
||||
* @param string $scopeCode
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider runLockDataProvider
|
||||
*/
|
||||
public function testRunLockEnv($path, $value, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null)
|
||||
{
|
||||
$this->inputMock->expects($this->any())
|
||||
->method('getArgument')
|
||||
->willReturnMap([
|
||||
[ConfigSetCommand::ARG_PATH, $path],
|
||||
[ConfigSetCommand::ARG_VALUE, $value]
|
||||
]);
|
||||
$this->inputMock->expects($this->any())
|
||||
->method('getOption')
|
||||
->willReturnMap([
|
||||
[ConfigSetCommand::OPTION_LOCK_ENV, true],
|
||||
[ConfigSetCommand::OPTION_SCOPE, $scope],
|
||||
[ConfigSetCommand::OPTION_SCOPE_CODE, $scopeCode]
|
||||
]);
|
||||
$this->outputMock->expects($this->exactly(2))
|
||||
->method('writeln')
|
||||
->withConsecutive(
|
||||
['<info>Value was saved in app/etc/env.php and locked.</info>'],
|
||||
['<info>Value was saved in app/etc/env.php and locked.</info>']
|
||||
);
|
||||
|
||||
/** @var ConfigSetCommand $command */
|
||||
$command = $this->objectManager->create(ConfigSetCommand::class);
|
||||
/** @var ConfigPathResolver $resolver */
|
||||
$resolver = $this->objectManager->get(ConfigPathResolver::class);
|
||||
$status = $command->run($this->inputMock, $this->outputMock);
|
||||
$configPath = $resolver->resolve($path, $scope, $scopeCode, 'system');
|
||||
|
||||
$this->assertSame(Cli::RETURN_SUCCESS, $status);
|
||||
$this->assertSame($value, $this->arrayManager->get($configPath, $this->loadConfig()));
|
||||
|
||||
$status = $command->run($this->inputMock, $this->outputMock);
|
||||
$this->appConfig->reinit();
|
||||
|
||||
$this->assertSame(Cli::RETURN_SUCCESS, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves variations with path, value, scope and scope code.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function runLockDataProvider()
|
||||
{
|
||||
return [
|
||||
['general/region/display_all', '1'],
|
||||
['general/region/state_required', 'BR,FR', ScopeInterface::SCOPE_WEBSITE, 'base'],
|
||||
['admin/security/use_form_key', '0'],
|
||||
['general/group/subgroup/field', 'default_value'],
|
||||
['general/group/subgroup/field', 'website_value', ScopeInterface::SCOPE_WEBSITE, 'base'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the extended flow.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $value
|
||||
* @param string $scope
|
||||
* @param string $scopeCode
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider runExtendedDataProvider
|
||||
*/
|
||||
public function testRunExtended(
|
||||
$path,
|
||||
$value,
|
||||
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
$scopeCode = null
|
||||
) {
|
||||
$arguments = [
|
||||
[ConfigSetCommand::ARG_PATH, $path],
|
||||
[ConfigSetCommand::ARG_VALUE, $value]
|
||||
];
|
||||
$options = [
|
||||
[ConfigSetCommand::OPTION_SCOPE, $scope],
|
||||
[ConfigSetCommand::OPTION_SCOPE_CODE, $scopeCode]
|
||||
];
|
||||
$optionsLock = array_merge($options, [[ConfigSetCommand::OPTION_LOCK_ENV, true]]);
|
||||
|
||||
/** @var ConfigPathResolver $resolver */
|
||||
$resolver = $this->objectManager->get(ConfigPathResolver::class);
|
||||
/** @var array $configPath */
|
||||
$configPath = $resolver->resolve($path, $scope, $scopeCode, 'system');
|
||||
|
||||
$this->runCommand($arguments, $options, '<info>Value was saved.</info>');
|
||||
$this->runCommand($arguments, $options, '<info>Value was saved.</info>');
|
||||
|
||||
$this->assertSame(
|
||||
$value,
|
||||
$this->scopeConfig->getValue($path, $scope, $scopeCode)
|
||||
);
|
||||
$this->assertNull($this->arrayManager->get($configPath, $this->loadConfig()));
|
||||
|
||||
$this->runCommand($arguments, $optionsLock, '<info>Value was saved in app/etc/env.php and locked.</info>');
|
||||
$this->runCommand($arguments, $optionsLock, '<info>Value was saved in app/etc/env.php and locked.</info>');
|
||||
|
||||
$this->assertSame($value, $this->arrayManager->get($configPath, $this->loadConfig()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs pre-configured command.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param array $options
|
||||
* @param string $expectedMessage
|
||||
* @param int $expectedCode
|
||||
*/
|
||||
private function runCommand(
|
||||
array $arguments,
|
||||
array $options,
|
||||
$expectedMessage = '',
|
||||
$expectedCode = Cli::RETURN_SUCCESS
|
||||
) {
|
||||
$input = clone $this->inputMock;
|
||||
$output = clone $this->outputMock;
|
||||
|
||||
$input->expects($this->any())
|
||||
->method('getArgument')
|
||||
->willReturnMap($arguments);
|
||||
$input->expects($this->any())
|
||||
->method('getOption')
|
||||
->willReturnMap($options);
|
||||
$output->expects($this->once())
|
||||
->method('writeln')
|
||||
->with($expectedMessage);
|
||||
|
||||
/** @var ConfigSetCommand $command */
|
||||
$command = $this->objectManager->create(ConfigSetCommand::class);
|
||||
$status = $command->run($input, $output);
|
||||
$this->appConfig->reinit();
|
||||
|
||||
$this->assertSame($expectedCode, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves variations with path, value, scope and scope code.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function runExtendedDataProvider()
|
||||
{
|
||||
return $this->runLockDataProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path Config path
|
||||
* @param string $value Value of config is tried to be set
|
||||
* @param string $message Message command output
|
||||
* @param string $scope
|
||||
* @param $scopeCode string|null
|
||||
* @dataProvider configSetValidationErrorDataProvider
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testConfigSetValidationError(
|
||||
$path,
|
||||
$value,
|
||||
$message,
|
||||
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
$scopeCode = null
|
||||
) {
|
||||
$this->setConfigFailure($path, $value, $message, $scope, $scopeCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConfigSetValidationError
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function configSetValidationErrorDataProvider()
|
||||
{
|
||||
return [
|
||||
//wrong value for URL - checked by backend model of URL field
|
||||
[
|
||||
Custom::XML_PATH_UNSECURE_BASE_URL,
|
||||
'value',
|
||||
'Invalid Base URL. Value must be a URL or one of placeholders: {{base_url}}'
|
||||
],
|
||||
//set not existed field path
|
||||
[
|
||||
'test/test/test',
|
||||
'value',
|
||||
'The "test/test/test" path doesn\'t exist. Verify and try again.'
|
||||
],
|
||||
//wrong scope or scope code
|
||||
[
|
||||
Custom::XML_PATH_GENERAL_LOCALE_CODE,
|
||||
'en_UK',
|
||||
'A scope is missing. Enter a scope and try again.',
|
||||
''
|
||||
],
|
||||
[
|
||||
Custom::XML_PATH_GENERAL_LOCALE_CODE,
|
||||
'en_UK',
|
||||
'A scope code is missing. Enter a code and try again.',
|
||||
ScopeInterface::SCOPE_WEBSITE
|
||||
],
|
||||
[
|
||||
Custom::XML_PATH_GENERAL_LOCALE_CODE,
|
||||
'en_UK',
|
||||
'A scope code is missing. Enter a code and try again.',
|
||||
ScopeInterface::SCOPE_STORE
|
||||
],
|
||||
[
|
||||
Custom::XML_PATH_GENERAL_LOCALE_CODE,
|
||||
'en_UK',
|
||||
'The "wrong_scope" value doesn\'t exist. Enter another value and try again.',
|
||||
'wrong_scope',
|
||||
'base'
|
||||
],
|
||||
[
|
||||
Custom::XML_PATH_GENERAL_LOCALE_CODE,
|
||||
'en_UK',
|
||||
'The "wrong_website_code" value doesn\'t exist. Enter another value and try again.',
|
||||
ScopeInterface::SCOPE_WEBSITE,
|
||||
'wrong_website_code'
|
||||
],
|
||||
[
|
||||
Custom::XML_PATH_GENERAL_LOCALE_CODE,
|
||||
'en_UK',
|
||||
'The "wrong_store_code" value doesn\'t exist. Enter another value and try again.',
|
||||
ScopeInterface::SCOPE_STORE,
|
||||
'wrong_store_code'
|
||||
],
|
||||
[
|
||||
Currency::XML_PATH_CURRENCY_DEFAULT,
|
||||
'GBP',
|
||||
'Sorry, the default display currency you selected is not available in allowed currencies.'
|
||||
],
|
||||
[
|
||||
Currency::XML_PATH_CURRENCY_ALLOW,
|
||||
'GBP',
|
||||
'Default display currency "US Dollar" is not available in allowed currencies.'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving values with successful validation
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testConfigSetCurrency()
|
||||
{
|
||||
/**
|
||||
* Checking saving currency as they are depend on each other.
|
||||
* Default currency can not be changed to new value if this value does not exist in allowed currency
|
||||
* that is why allowed currency is changed first by adding necessary value,
|
||||
* then old value is removed after changing default currency
|
||||
*/
|
||||
$this->setConfigSuccess(Currency::XML_PATH_CURRENCY_ALLOW, 'USD,GBP');
|
||||
$this->setConfigSuccess(Currency::XML_PATH_CURRENCY_DEFAULT, 'GBP');
|
||||
$this->setConfigSuccess(Currency::XML_PATH_CURRENCY_ALLOW, 'GBP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving values with successful validation
|
||||
*
|
||||
* @dataProvider configSetValidDataProvider
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testConfigSetValid()
|
||||
{
|
||||
$this->setConfigSuccess(Custom::XML_PATH_UNSECURE_BASE_URL, 'http://magento2.local/');
|
||||
$this->setConfigSuccess(Custom::XML_PATH_GENERAL_LOCALE_CODE, 'en_UK', ScopeInterface::SCOPE_WEBSITE, 'base');
|
||||
$this->setConfigSuccess(Custom::XML_PATH_GENERAL_LOCALE_CODE, 'en_AU', ScopeInterface::SCOPE_STORE, 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConfigSetValid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function configSetValidDataProvider()
|
||||
{
|
||||
return [
|
||||
[Custom::XML_PATH_UNSECURE_BASE_URL, 'http://magento2.local/'],
|
||||
[Custom::XML_PATH_GENERAL_LOCALE_CODE, 'en_UK', ScopeInterface::SCOPE_WEBSITE, 'base'],
|
||||
[Custom::XML_PATH_GENERAL_LOCALE_CODE, 'en_AU', ScopeInterface::SCOPE_STORE, 'default'],
|
||||
[Custom::XML_PATH_ADMIN_SECURITY_USEFORMKEY, '0']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validate path when field has custom config_path
|
||||
*/
|
||||
public function testValidatePathWithCustomConfigPath(): void
|
||||
{
|
||||
$pathValidator = $this->objectManager->get(PathValidator::class);
|
||||
$this->assertTrue($pathValidator->validate('general/group/subgroup/second_field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration and check this value from DB with success message this command should display
|
||||
*
|
||||
* @param string $path Config path
|
||||
* @param string $value Value of config is tried to be set
|
||||
* @param string $scope
|
||||
* @param string|null $scopeCode
|
||||
*/
|
||||
private function setConfigSuccess(
|
||||
$path,
|
||||
$value,
|
||||
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
$scopeCode = null
|
||||
) {
|
||||
$status = $this->setConfig($path, $value, '<info>Value was saved.</info>', $scope, $scopeCode);
|
||||
$this->assertSame(Cli::RETURN_SUCCESS, $status);
|
||||
$this->assertSame(
|
||||
$value,
|
||||
$this->scopeConfig->getValue($path, $scope, $scopeCode)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration value with some error
|
||||
* and check that this value was not saved to DB and appropriate error message was displayed
|
||||
*
|
||||
* @param string $path Config path
|
||||
* @param string $value Value of config is tried to be set
|
||||
* @param string $message Message command output
|
||||
* @param string $scope
|
||||
* @param string|null $scopeCode
|
||||
*/
|
||||
private function setConfigFailure(
|
||||
$path,
|
||||
$value,
|
||||
$message,
|
||||
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
$scopeCode = null
|
||||
) {
|
||||
$status = $this->setConfig($path, $value, '<error>' . $message . '</error>', $scope, $scopeCode);
|
||||
$this->assertSame(Cli::RETURN_FAILURE, $status);
|
||||
$this->assertNotSame(
|
||||
$value,
|
||||
$this->scopeConfig->getValue($path),
|
||||
"Values are the same '$value' and '{$this->scopeConfig->getValue($path)}' for $path"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path Config path
|
||||
* @param string $value Value of config is tried to be set
|
||||
* @param string $message Message command output
|
||||
* @param string $scope
|
||||
* @param string|null $scopeCode
|
||||
* @return int Status that command returned
|
||||
*/
|
||||
private function setConfig($path, $value, $message, $scope, $scopeCode)
|
||||
{
|
||||
$input = clone $this->inputMock;
|
||||
$output = clone $this->outputMock;
|
||||
$input->expects($this->any())
|
||||
->method('getArgument')
|
||||
->willReturnMap([
|
||||
[ConfigSetCommand::ARG_PATH, $path],
|
||||
[ConfigSetCommand::ARG_VALUE, $value]
|
||||
]);
|
||||
$input->expects($this->any())
|
||||
->method('getOption')
|
||||
->willReturnMap([
|
||||
[ConfigSetCommand::OPTION_SCOPE, $scope],
|
||||
[ConfigSetCommand::OPTION_SCOPE_CODE, $scopeCode]
|
||||
]);
|
||||
$output->expects($this->once())
|
||||
->method('writeln')
|
||||
->with($message);
|
||||
|
||||
/** @var ConfigSetCommand $command */
|
||||
$command = $this->objectManager->create(ConfigSetCommand::class);
|
||||
$status = $command->run($input, $output);
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
+495
@@ -0,0 +1,495 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Config\Console\Command;
|
||||
|
||||
use Magento\Config\Model\Config\Structure;
|
||||
use Magento\Framework\App\DeploymentConfig\FileReader;
|
||||
use Magento\Framework\App\DeploymentConfig\Writer;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Config\File\ConfigFilePool;
|
||||
use Magento\Framework\Console\Cli;
|
||||
use Magento\Framework\Exception\FileSystemException;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\Store\Test\Fixture\Group;
|
||||
use Magento\Store\Test\Fixture\Store;
|
||||
use Magento\Store\Test\Fixture\Website;
|
||||
use Magento\TestFramework\Fixture\AppArea;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Fixture\DbIsolation;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Config\Console\Command\ConfigShowCommand.
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class ConfigShowCommandTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var CommandTester
|
||||
*/
|
||||
private $commandTester;
|
||||
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
private $filesystem;
|
||||
|
||||
/**
|
||||
* @var ConfigFilePool
|
||||
*/
|
||||
private $configFilePool;
|
||||
|
||||
/**
|
||||
* @var FileReader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* @var Writer
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $env;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $envConfig;
|
||||
|
||||
/**
|
||||
* @var Structure
|
||||
*/
|
||||
private $structure;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->configFilePool = $objectManager->get(ConfigFilePool::class);
|
||||
$this->filesystem = $objectManager->get(Filesystem::class);
|
||||
$this->reader = $objectManager->get(FileReader::class);
|
||||
$this->writer = $objectManager->get(Writer::class);
|
||||
$this->structure = $objectManager->get(Structure::class);
|
||||
|
||||
$this->config = $this->loadConfig();
|
||||
$this->envConfig = $this->loadEnvConfig();
|
||||
$this->env = $_ENV;
|
||||
|
||||
$config = include __DIR__ . '/../../_files/config.php';
|
||||
$this->writer->saveConfig([ConfigFilePool::APP_CONFIG => $config]);
|
||||
|
||||
$config = include __DIR__ . '/../../_files/env.php';
|
||||
$this->writer->saveConfig([ConfigFilePool::APP_ENV => $config]);
|
||||
|
||||
$_ENV['CONFIG__DEFAULT__WEB__TEST2__TEST_VALUE_4'] = 'value4.env.default.test';
|
||||
$_ENV['CONFIG__WEBSITES__BASE__WEB__TEST2__TEST_VALUE_4'] = 'value4.env.website_base.test';
|
||||
$_ENV['CONFIG__STORES__DEFAULT__WEB__TEST2__TEST_VALUE_4'] = 'value4.env.store_default.test';
|
||||
|
||||
$_ENV['CONFIG__DEFAULT__CAMELCASE__UPPERCASE__SNAKE_CASE'] = 'env.default.test';
|
||||
$_ENV['CONFIG__WEBSITES__SECONDWEBSITE__CAMELCASE__UPPERCASE__SNAKE_CASE'] = 'env.website_secondwebsite.test';
|
||||
$_ENV['CONFIG__STORES__THIRD_STORE__CAMELCASE__UPPERCASE__SNAKE_CASE'] = 'env.store_third_store.test';
|
||||
|
||||
$this->setConfigPaths();
|
||||
|
||||
$command = $objectManager->create(ConfigShowCommand::class);
|
||||
$this->commandTester = new CommandTester($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test execute config show command
|
||||
*
|
||||
* @param string $scope
|
||||
* @param string $scopeCode
|
||||
* @param int $resultCode
|
||||
* @param array $configs
|
||||
* @return void
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Config/_files/config_data.php
|
||||
* @dataProvider executeDataProvider
|
||||
*/
|
||||
public function testExecute($scope, $scopeCode, $resultCode, array $configs): void
|
||||
{
|
||||
$this->setConfigPaths();
|
||||
|
||||
$this->checkConfigs($configs, $scope, $scopeCode, $resultCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set config paths to structure
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setConfigPaths(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(Structure::class);
|
||||
$mappedPaths = $reflection->getProperty('mappedPaths');
|
||||
$mappedPaths->setAccessible(true);
|
||||
$mappedPaths->setValue($this->structure, $this->getConfigPaths());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns config paths
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getConfigPaths(): array
|
||||
{
|
||||
$configs = [
|
||||
'camelCase/UPPERCASE/snake_case',
|
||||
'web/test/test_value_1',
|
||||
'web/test/test_value_2',
|
||||
'web/test2/test_value_3',
|
||||
'web/test2/test_value_4',
|
||||
'web/test/value',
|
||||
'carriers/fedex/account',
|
||||
'paypal/fetch_reports/ftp_password',
|
||||
'camelCase/UPPERCASE',
|
||||
'web/test',
|
||||
'web/test2',
|
||||
'camelCase',
|
||||
'web',
|
||||
];
|
||||
|
||||
return array_flip($configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function executeDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
null,
|
||||
null,
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'web/test/test_value_1' => ['value1.db.default.test'],
|
||||
'web/test/test_value_2' => ['value2.local_config.default.test'],
|
||||
'web/test2/test_value_3' => ['value3.config.default.test'],
|
||||
'web/test2/test_value_4' => ['value4.env.default.test'],
|
||||
'carriers/fedex/account' => ['******'],
|
||||
'paypal/fetch_reports/ftp_password' => ['******'],
|
||||
'web/test' => [
|
||||
'web/test/test_value_1 - value1.db.default.test',
|
||||
'web/test/test_value_2 - value2.local_config.default.test',
|
||||
],
|
||||
'web/test2' => [
|
||||
'web/test2/test_value_3 - value3.config.default.test',
|
||||
'web/test2/test_value_4 - value4.env.default.test',
|
||||
],
|
||||
'web' => [
|
||||
'web/test/test_value_1 - value1.db.default.test',
|
||||
'web/test/test_value_2 - value2.local_config.default.test',
|
||||
'web/test2/test_value_3 - value3.config.default.test',
|
||||
'web/test2/test_value_4 - value4.env.default.test',
|
||||
],
|
||||
'' => [
|
||||
'web/test/test_value_1 - value1.db.default.test',
|
||||
'web/test/test_value_2 - value2.local_config.default.test',
|
||||
'web/test2/test_value_3 - value3.config.default.test',
|
||||
'web/test2/test_value_4 - value4.env.default.test',
|
||||
'carriers/fedex/account - ******',
|
||||
'paypal/fetch_reports/ftp_password - ******',
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
ScopeInterface::SCOPE_WEBSITES,
|
||||
'base',
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'web/test/test_value_1' => ['value1.db.website_base.test'],
|
||||
'web/test/test_value_2' => ['value2.local_config.website_base.test'],
|
||||
'web/test2/test_value_3' => ['value3.config.website_base.test'],
|
||||
'web/test2/test_value_4' => ['value4.env.website_base.test'],
|
||||
'web/test' => [
|
||||
'web/test/test_value_1 - value1.db.website_base.test',
|
||||
'web/test/test_value_2 - value2.local_config.website_base.test',
|
||||
],
|
||||
'web/test2' => [
|
||||
'web/test2/test_value_3 - value3.config.website_base.test',
|
||||
'web/test2/test_value_4 - value4.env.website_base.test',
|
||||
],
|
||||
'web' => [
|
||||
'web/test/test_value_1 - value1.db.website_base.test',
|
||||
'web/test/test_value_2 - value2.local_config.website_base.test',
|
||||
'web/test2/test_value_3 - value3.config.website_base.test',
|
||||
'web/test2/test_value_4 - value4.env.website_base.test',
|
||||
],
|
||||
'' => [
|
||||
'web/test/test_value_1 - value1.db.website_base.test',
|
||||
'web/test/test_value_2 - value2.local_config.website_base.test',
|
||||
'web/test2/test_value_3 - value3.config.website_base.test',
|
||||
'web/test2/test_value_4 - value4.env.website_base.test',
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
ScopeInterface::SCOPE_STORES,
|
||||
'default',
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'web/test/test_value_1' => ['value1.db.store_default.test'],
|
||||
'web/test/test_value_2' => ['value2.local_config.store_default.test'],
|
||||
'web/test2/test_value_3' => ['value3.config.store_default.test'],
|
||||
'web/test2/test_value_4' => ['value4.env.store_default.test'],
|
||||
'web/test' => [
|
||||
'web/test/test_value_1 - value1.db.store_default.test',
|
||||
'web/test/test_value_2 - value2.local_config.store_default.test',
|
||||
],
|
||||
'web/test2' => [
|
||||
'web/test2/test_value_3 - value3.config.store_default.test',
|
||||
'web/test2/test_value_4 - value4.env.store_default.test',
|
||||
],
|
||||
'web' => [
|
||||
'web/test/test_value_1 - value1.db.store_default.test',
|
||||
'web/test/test_value_2 - value2.local_config.store_default.test',
|
||||
'web/test2/test_value_3 - value3.config.store_default.test',
|
||||
'web/test2/test_value_4 - value4.env.store_default.test',
|
||||
],
|
||||
'' => [
|
||||
'web/test/test_value_1 - value1.db.store_default.test',
|
||||
'web/test/test_value_2 - value2.local_config.store_default.test',
|
||||
'web/test2/test_value_3 - value3.config.store_default.test',
|
||||
'web/test2/test_value_4 - value4.env.store_default.test',
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
null,
|
||||
null,
|
||||
Cli::RETURN_FAILURE,
|
||||
[
|
||||
'web/test/test_wrong_value' => [
|
||||
'The "web/test/test_wrong_value" path doesn\'t exist. Verify and try again.'
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'default',
|
||||
null,
|
||||
Cli::RETURN_FAILURE,
|
||||
[
|
||||
'web/test/test_wrong_value' => [
|
||||
'The "web/test/test_wrong_value" path doesn\'t exist. Verify and try again.'
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'default',
|
||||
'scope_code',
|
||||
Cli::RETURN_FAILURE,
|
||||
[
|
||||
'web/test/test_wrong_value' => [
|
||||
'The "default" scope can\'t include a scope code. Try again without entering a scope code.'
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'some_scope',
|
||||
'scope_code',
|
||||
Cli::RETURN_FAILURE,
|
||||
[
|
||||
'web/test/test_wrong_value' => [
|
||||
'The "some_scope" value doesn\'t exist. Enter another value and try again.'
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'websites',
|
||||
'scope_code',
|
||||
Cli::RETURN_FAILURE,
|
||||
[
|
||||
'web/test/test_wrong_value' => [
|
||||
'The "scope_code" value doesn\'t exist. Enter another value and try again.'
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
#[
|
||||
AppArea('frontend'),
|
||||
DbIsolation(false),
|
||||
DataFixture(Website::class, ['code' => 'SecondWebsite'], as: 'website2'),
|
||||
DataFixture(Website::class, ['code' => 'THIRD_WEBSITE'], as: 'website3'),
|
||||
DataFixture(Website::class, ['code' => 'fourthWebsite'], as: 'website4'),
|
||||
DataFixture(Group::class, ['website_id' => '$website2.id$'], 'store_group2'),
|
||||
DataFixture(Group::class, ['website_id' => '$website3.id$'], 'store_group3'),
|
||||
DataFixture(Group::class, ['website_id' => '$website4.id$'], 'store_group4'),
|
||||
DataFixture(Store::class, ['store_group_id' => '$store_group2.id$', 'code' => 'SecondStore'], as: 'store2'),
|
||||
DataFixture(Store::class, ['store_group_id' => '$store_group3.id$', 'code' => 'THIRD_STORE'], as: 'store3'),
|
||||
DataFixture(Store::class, ['store_group_id' => '$store_group4.id$', 'code' => 'fourthStore'], as: 'store4')
|
||||
]
|
||||
public function testExecuteEnvOnWebsitesAndStores()
|
||||
{
|
||||
$this->setConfigPaths();
|
||||
|
||||
$data = $this->configsToCheck();
|
||||
|
||||
foreach ($data as $datum) {
|
||||
$this->checkConfigs($datum[3], $datum[0], $datum[1], $datum[2]);
|
||||
}
|
||||
}
|
||||
|
||||
public function configsToCheck(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
null,
|
||||
null,
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'camelCase/UPPERCASE/snake_case' => ['env.default.test']
|
||||
]
|
||||
],
|
||||
[
|
||||
ScopeInterface::SCOPE_STORES,
|
||||
'default',
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'camelCase/UPPERCASE/snake_case' => ['local_config.store_default.test']
|
||||
]
|
||||
],
|
||||
[
|
||||
ScopeInterface::SCOPE_WEBSITES,
|
||||
'SecondWebsite',
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'camelCase/UPPERCASE/snake_case' => ['env.website_secondwebsite.test']
|
||||
]
|
||||
],
|
||||
[
|
||||
ScopeInterface::SCOPE_STORES,
|
||||
'SecondStore',
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'camelCase/UPPERCASE/snake_case' => ['local_config.store_secondstore.test']
|
||||
]
|
||||
],
|
||||
[
|
||||
ScopeInterface::SCOPE_WEBSITES,
|
||||
'THIRD_WEBSITE',
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'camelCase/UPPERCASE/snake_case' => ['local_config.website_third_website.tes']
|
||||
]
|
||||
],
|
||||
[
|
||||
ScopeInterface::SCOPE_STORES,
|
||||
'THIRD_STORE',
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'camelCase/UPPERCASE/snake_case' => ['env.store_third_store.tes']
|
||||
]
|
||||
],
|
||||
[
|
||||
ScopeInterface::SCOPE_WEBSITES,
|
||||
'fourthWebsite',
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'camelCase/UPPERCASE/snake_case' => ['local_config.website_fourthwebsite.test']
|
||||
]
|
||||
],
|
||||
[
|
||||
ScopeInterface::SCOPE_STORES,
|
||||
'fourthStore',
|
||||
Cli::RETURN_SUCCESS,
|
||||
[
|
||||
'camelCase/UPPERCASE/snake_case' => ['local_config.store_fourthstore.test']
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
private function loadConfig()
|
||||
{
|
||||
return $this->reader->load(ConfigFilePool::APP_CONFIG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
private function loadEnvConfig()
|
||||
{
|
||||
return $this->reader->load(ConfigFilePool::APP_ENV);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $configs
|
||||
* @param $scope
|
||||
* @param $scopeCode
|
||||
* @param $resultCode
|
||||
* @return void
|
||||
*/
|
||||
private function checkConfigs(array $configs, $scope, $scopeCode, $resultCode): void
|
||||
{
|
||||
foreach ($configs as $inputPath => $configValue) {
|
||||
$arguments = [
|
||||
ConfigShowCommand::INPUT_ARGUMENT_PATH => $inputPath
|
||||
];
|
||||
|
||||
if ($scope !== null) {
|
||||
$arguments['--' . ConfigShowCommand::INPUT_OPTION_SCOPE] = $scope;
|
||||
}
|
||||
if ($scopeCode !== null) {
|
||||
$arguments['--' . ConfigShowCommand::INPUT_OPTION_SCOPE_CODE] = $scopeCode;
|
||||
}
|
||||
|
||||
$this->commandTester->execute($arguments);
|
||||
|
||||
$this->assertEquals(
|
||||
$resultCode,
|
||||
$this->commandTester->getStatusCode()
|
||||
);
|
||||
|
||||
$commandOutput = $this->commandTester->getDisplay();
|
||||
|
||||
foreach ($configValue as $value) {
|
||||
$this->assertStringContainsString($value, $commandOutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$_ENV = $this->env;
|
||||
|
||||
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
|
||||
$this->configFilePool->getPath(ConfigFilePool::APP_CONFIG),
|
||||
"<?php\n return array();\n"
|
||||
);
|
||||
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
|
||||
$this->configFilePool->getPath(ConfigFilePool::APP_ENV),
|
||||
"<?php\n return array();\n"
|
||||
);
|
||||
|
||||
$this->writer->saveConfig([ConfigFilePool::APP_CONFIG => $this->config]);
|
||||
$this->writer->saveConfig([ConfigFilePool::APP_ENV => $this->envConfig]);
|
||||
}
|
||||
}
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Config\Controller\Adminhtml\System\Config;
|
||||
|
||||
use Magento\Config\Model\Config\Loader;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\App\ScopeInterface;
|
||||
use Magento\Framework\App\ScopeResolverPool;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* Checks saving and updating of configuration data
|
||||
*
|
||||
* @see \Magento\Config\Controller\Adminhtml\System\Config\Save
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class SaveTest extends AbstractBackendController
|
||||
{
|
||||
/** @var Loader */
|
||||
private $configLoader;
|
||||
|
||||
/** @var ScopeResolverPool */
|
||||
private $scopeResolverPool;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->configLoader = $this->_objectManager->get(Loader::class);
|
||||
$this->scopeResolverPool = $this->_objectManager->get(ScopeResolverPool::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider saveConfigDataProvider
|
||||
* @magentoDbIsolation enabled
|
||||
* @param array $params
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveConfig(array $params, array $post): void
|
||||
{
|
||||
$expectedPathValue = $this->prepareExpectedPathValue($params['section'], $post['groups']);
|
||||
$this->dispatchWithParams($params, $post);
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual((string)__('You saved the configuration.')),
|
||||
MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
$this->assertPathValue($expectedPathValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function saveConfigDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'configure_shipping_origin' => [
|
||||
'params' => ['section' => 'shipping'],
|
||||
'post' => [
|
||||
'groups' => [
|
||||
'origin' => [
|
||||
'fields' => [
|
||||
'country_id' => ['value' => 'CH'],
|
||||
'region_id' => ['value' => '107'],
|
||||
'postcode' => ['value' => '3005'],
|
||||
'city' => ['value' => 'Bern'],
|
||||
'street_line1' => ['value' => 'Weinbergstrasse 4'],
|
||||
'street_line2' => ['value' => 'Suite 1'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'configure_multi_shipping_options' => [
|
||||
'params' => ['section' => 'multishipping'],
|
||||
'post' => [
|
||||
'groups' => [
|
||||
'options' => [
|
||||
'fields' => [
|
||||
'checkout_multiple' => ['value' => '1'],
|
||||
'checkout_multiple_maximum_qty' => ['value' => '99'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'configure_flat_rate_shipping_method' => [
|
||||
'params' => ['section' => 'carriers'],
|
||||
'post' => [
|
||||
'groups' => [
|
||||
'flatrate' => [
|
||||
'fields' => [
|
||||
'active' => ['value' => '1'],
|
||||
'type' => ['value' => 'I'],
|
||||
'price' => ['value' => '5.00'],
|
||||
'sallowspecific' => ['value' => '0'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare expected path value array.
|
||||
*
|
||||
* @param string $section
|
||||
* @param array $groups
|
||||
* @return array
|
||||
*/
|
||||
private function prepareExpectedPathValue(string $section, array $groups): array
|
||||
{
|
||||
foreach ($groups as $groupId => $groupData) {
|
||||
$groupPath = $section . '/' . $groupId;
|
||||
foreach ($groupData['fields'] as $fieldId => $fieldData) {
|
||||
$path = $groupPath . '/' . $fieldId;
|
||||
$expectedData[$groupPath][$path] = $fieldData['value'];
|
||||
}
|
||||
}
|
||||
|
||||
return $expectedData ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the values for the paths in the config data were saved successfully.
|
||||
*
|
||||
* @param array $expectedPathValue
|
||||
* @return void
|
||||
*/
|
||||
private function assertPathValue(array $expectedPathValue): void
|
||||
{
|
||||
$scope = $this->scopeResolverPool->get(ScopeInterface::SCOPE_DEFAULT)->getScope();
|
||||
foreach ($expectedPathValue as $groupPath => $groupData) {
|
||||
$actualPathValue = $this->configLoader->getConfigByPath(
|
||||
$groupPath,
|
||||
$scope->getScopeType(),
|
||||
$scope->getId(),
|
||||
false
|
||||
);
|
||||
foreach ($groupData as $fieldPath => $fieldValue) {
|
||||
$this->assertArrayHasKey(
|
||||
$fieldPath,
|
||||
$actualPathValue,
|
||||
sprintf('The expected config setting was not saved in the database. Path: %s', $fieldPath)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$fieldValue,
|
||||
$actualPathValue[$fieldPath],
|
||||
sprintf('The expected value of the config setting is not correct. Path: %s', $fieldPath)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch request with params
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $postParams
|
||||
* @return void
|
||||
*/
|
||||
private function dispatchWithParams(array $params = [], array $postParams = []): void
|
||||
{
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST)
|
||||
->setParams($params)
|
||||
->setPostValue($postParams);
|
||||
$this->dispatch('backend/admin/system_config/save');
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Config\Controller\Adminhtml\System;
|
||||
|
||||
use Magento\Config\Controller\Adminhtml\System\Config\Save;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ConfigTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Test Configuration page existing.
|
||||
*/
|
||||
public function testEditAction()
|
||||
{
|
||||
$this->dispatch('backend/admin/system_config/edit');
|
||||
$this->assertStringContainsString('<div id="system_config_tabs"', $this->getResponse()->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test redirect after changing base URL.
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testChangeBaseUrl()
|
||||
{
|
||||
$defaultHost = Bootstrap::getObjectManager()->create(\Magento\Framework\Url::class)->getBaseUrl();
|
||||
$newHost = 'm2test123.loc';
|
||||
$request = $this->getRequest();
|
||||
$request->setPostValue(
|
||||
[
|
||||
'groups' =>
|
||||
['unsecure' =>
|
||||
['fields' =>
|
||||
['base_url' =>
|
||||
['value' => 'http://' . $newHost . '/']
|
||||
]
|
||||
]
|
||||
],
|
||||
'config_state' => ['web_unsecure' => 1]
|
||||
]
|
||||
)->setParam(
|
||||
'section',
|
||||
'web'
|
||||
)->setMethod(
|
||||
HttpRequest::METHOD_POST
|
||||
);
|
||||
$this->dispatch('backend/admin/system_config/save');
|
||||
|
||||
$this->assertTrue($this->getResponse()->isRedirect(), 'Redirect was expected, but none was performed.');
|
||||
|
||||
/** @var array|bool $url */
|
||||
$url = parse_url($this->getResponse()->getHeader('Location')->getFieldValue());
|
||||
$this->assertArrayNotHasKey(
|
||||
'query',
|
||||
$url,
|
||||
'No GET params, including "SID", were expected, but somewhat exists'
|
||||
);
|
||||
$this->assertEquals($newHost, $url['host'], 'A new host in the url expected, but there is old one');
|
||||
$this->resetBaseUrl($defaultHost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test saving undeclared configs.
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testSavingUndeclared()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$request->setPostValue([
|
||||
'groups' => [
|
||||
'non_existing' => [
|
||||
'fields' => [
|
||||
'non_existing_field' => [
|
||||
'value' => 'some_value'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$request->setParam('section', 'web');
|
||||
$request->setMethod(HttpRequest::METHOD_POST);
|
||||
/** @var Save $controller */
|
||||
$controller = Bootstrap::getObjectManager()->create(Save::class);
|
||||
$controller->execute();
|
||||
|
||||
$this->assertSessionMessages($this->equalTo(['You saved the configuration.']));
|
||||
/** @var ScopeConfigInterface $scopeConfig */
|
||||
$scopeConfig = Bootstrap::getObjectManager()->get(ScopeConfigInterface::class);
|
||||
$this->assertNull($scopeConfig->getValue('web/non_existing/non_existing_field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset test framework default base url.
|
||||
*
|
||||
* @param string $defaultHost
|
||||
*/
|
||||
protected function resetBaseUrl($defaultHost)
|
||||
{
|
||||
$baseUrlData = [
|
||||
'section' => 'web',
|
||||
'website' => null,
|
||||
'store' => null,
|
||||
'groups' => [
|
||||
'unsecure' => [
|
||||
'fields' => [
|
||||
'base_url' => [
|
||||
'value' => $defaultHost
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
Bootstrap::getObjectManager()->create(\Magento\Config\Model\Config\Factory::class)
|
||||
->create()
|
||||
->addData($baseUrlData)
|
||||
->save();
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Config\Model\Config\Backend\Admin;
|
||||
|
||||
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class RobotsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Config\Model\Config\Backend\Admin\Robots
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Filesystem\Directory\Read
|
||||
*/
|
||||
protected $rootDirectory;
|
||||
|
||||
/**
|
||||
* Initialize model
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->model = $objectManager->create(\Magento\Config\Model\Config\Backend\Admin\Robots::class);
|
||||
$this->model->setPath('design/search_engine_robots/custom_instructions');
|
||||
$this->model->afterLoad();
|
||||
|
||||
$this->rootDirectory = $objectManager->get(Filesystem::class)->getDirectoryRead(DirectoryList::PUB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that default value is empty when robots.txt not exists
|
||||
*
|
||||
* @magentoDataFixture Magento/Config/Model/_files/no_robots_txt.php
|
||||
*/
|
||||
public function testAfterLoadRobotsTxtNotExists()
|
||||
{
|
||||
$this->assertEmpty($this->model->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that default value equals to robots.txt content when it is available
|
||||
*
|
||||
* @magentoDataFixture Magento/Config/Model/_files/robots_txt.php
|
||||
*/
|
||||
public function testAfterLoadRobotsTxtExists()
|
||||
{
|
||||
$value = $this->model->getValue();
|
||||
$this->assertEquals('Sitemap: http://store.com/sitemap.xml', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check robots.txt file generated when robots.txt not exists
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testAfterSaveFileNotExists()
|
||||
{
|
||||
$this->assertFalse($this->rootDirectory->isExist('robots.txt'), 'robots.txt exists');
|
||||
|
||||
$this->_modifyConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check robots.txt file changed when robots.txt exists
|
||||
*
|
||||
* @magentoDataFixture Magento/Config/Model/_files/robots_txt.php
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testAfterSaveFileExists()
|
||||
{
|
||||
$this->assertTrue($this->rootDirectory->isExist('robots.txt'), 'robots.txt not exists');
|
||||
|
||||
$this->_modifyConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify config value and check all changes were written into robots.txt
|
||||
*/
|
||||
protected function _modifyConfig()
|
||||
{
|
||||
$robotsTxt = "User-Agent: *\nDisallow: /checkout";
|
||||
$this->model->setValue($robotsTxt)->save();
|
||||
$file = $this->rootDirectory->getAbsolutePath('robots.txt');
|
||||
$this->assertStringEqualsFile($file, $robotsTxt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove created robots.txt
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
require 'Magento/Config/Model/_files/no_robots_txt.php';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Config\Model\Config\Backend;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class BaseurlTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $value
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider validationDataProvider
|
||||
*/
|
||||
public function testValidation($path, $value)
|
||||
{
|
||||
/** @var $model \Magento\Config\Model\Config\Backend\Baseurl */
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Config\Model\Config\Backend\Baseurl::class
|
||||
);
|
||||
$model->setPath($path)->setValue($value)->save();
|
||||
$this->assertNotEmpty((int)$model->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function validationDataProvider()
|
||||
{
|
||||
$basePlaceholder = '{{base_url}}';
|
||||
$unsecurePlaceholder = '{{unsecure_base_url}}';
|
||||
$unsecureSuffix = '{{unsecure_base_url}}test/';
|
||||
$securePlaceholder = '{{secure_base_url}}';
|
||||
$secureSuffix = '{{secure_base_url}}test/';
|
||||
|
||||
return [
|
||||
['any/path', 'http://example.com/'],
|
||||
['any/path', 'http://example.com/uri/'],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $basePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, $unsecurePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, $unsecureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_STATIC_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_STATIC_URL, $unsecurePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_STATIC_URL, $unsecureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_MEDIA_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_MEDIA_URL, $unsecurePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_MEDIA_URL, $unsecureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $basePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $securePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $secureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, $securePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, $secureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, $securePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, $secureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $unsecurePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $unsecurePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $unsecureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, $unsecurePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, $unsecureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, $unsecurePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, $unsecureSuffix],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $value
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider validationExceptionDataProvider
|
||||
*/
|
||||
public function testValidationException($path, $value)
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
|
||||
/** @var $model \Magento\Config\Model\Config\Backend\Baseurl */
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Config\Model\Config\Backend\Baseurl::class
|
||||
);
|
||||
$model->setPath($path)->setValue($value)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function validationExceptionDataProvider()
|
||||
{
|
||||
$baseSuffix = '{{base_url}}test/';
|
||||
$unsecurePlaceholder = '{{unsecure_base_url}}';
|
||||
$unsecureSuffix = '{{unsecure_base_url}}test/';
|
||||
$unsecureWrongSuffix = '{{unsecure_base_url}}test';
|
||||
$unsecureWrongDomainName = 'http://example.com_test/';
|
||||
$securePlaceholder = '{{secure_base_url}}';
|
||||
$secureSuffix = '{{secure_base_url}}test/';
|
||||
$secureWrongSuffix = '{{secure_base_url}}test';
|
||||
$secureWrongDomainName = 'https://example.com_test/';
|
||||
|
||||
return [
|
||||
['', 'not a valid URL'],
|
||||
['', 'example.com'],
|
||||
['', 'http://example.com'],
|
||||
['', 'http://example.com/uri'],
|
||||
['', $unsecureWrongDomainName],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $baseSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $unsecureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $unsecurePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $unsecureWrongDomainName],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, $baseSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, $unsecureWrongSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_LINK_URL, $unsecureWrongDomainName],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_MEDIA_URL, $unsecureWrongSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_MEDIA_URL, $unsecureWrongDomainName],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_STATIC_URL, $unsecureWrongSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_STATIC_URL, $unsecureWrongDomainName],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $baseSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $secureSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $securePlaceholder],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $secureWrongDomainName],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, ''],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $baseSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $secureWrongSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_LINK_URL, $secureWrongDomainName],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, $secureWrongSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_MEDIA_URL, $secureWrongDomainName],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, $secureWrongSuffix],
|
||||
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_STATIC_URL, $secureWrongDomainName],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Config\Model\Config\Backend;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class EncryptedTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testEncryptionSave()
|
||||
{
|
||||
$originalValue = '1Password';
|
||||
|
||||
/** @var $model \Magento\Config\Model\Config\Backend\Encrypted */
|
||||
$model = Bootstrap::getObjectManager()->create(\Magento\Config\Model\Config\Backend\Encrypted::class);
|
||||
$model->setPath('carriers/usps/password');
|
||||
$model->setScopeId(0);
|
||||
$model->setScope('default');
|
||||
$model->setScopeCode('');
|
||||
$model->setValue($originalValue);
|
||||
$model->save();
|
||||
|
||||
// Pass in the obscured value
|
||||
$model->setPath('carriers/usps/password');
|
||||
$model->setScopeId(0);
|
||||
$model->setScope('default');
|
||||
$model->setScopeCode('');
|
||||
$model->setValue('*****');
|
||||
$model->save();
|
||||
|
||||
//Verify original value is not changed for obscured value
|
||||
$value = $model->load($model->getId())->getValue();
|
||||
$this->assertEquals($originalValue, $value, 'Original value is not expected to change.');
|
||||
|
||||
// Verify if actual value is changed
|
||||
$changedValue = 'newPassword';
|
||||
|
||||
$model->setPath('carriers/usps/password');
|
||||
$model->setScopeId(0);
|
||||
$model->setScope('default');
|
||||
$model->setScopeCode('');
|
||||
$model->setValue($changedValue);
|
||||
$model->save();
|
||||
|
||||
//Verify original value is changed
|
||||
$value = $model->load($model->getId())->getValue();
|
||||
$this->assertEquals($changedValue, $value, 'Original value is expected to change.');
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Config\Model\Config\Backend\Image;
|
||||
|
||||
class AdapterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Config\Model\Config\Backend\Image\Adapter
|
||||
*/
|
||||
protected $_model = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Config\Model\Config\Backend\Image\Adapter::class
|
||||
);
|
||||
$this->_model->setPath('path');
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testExceptionSave()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'The specified image adapter cannot be used because of: Image adapter for \'wrong\' is not setup.'
|
||||
);
|
||||
|
||||
$this->_model->setValue('wrong')->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testCorrectSave()
|
||||
{
|
||||
$this->_model->setValue(\Magento\Framework\Image\Adapter\AdapterInterface::ADAPTER_GD2)->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Config\Model\Config\Export;
|
||||
|
||||
use Magento\Config\Model\Config\TypePool;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CommentTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Comment
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->comment = Bootstrap::getObjectManager()->create(Comment::class);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$sensitivePaths = $this->getSensitivePaths();
|
||||
$comments = $this->comment->get();
|
||||
|
||||
$missedPaths = [];
|
||||
foreach ($sensitivePaths as $sensitivePath) {
|
||||
if (stripos($comments, $sensitivePath) === false) {
|
||||
$missedPaths[] = $sensitivePath;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEmpty(
|
||||
$missedPaths,
|
||||
'Sensitive paths are missed: ' . implode(', ', $missedPaths)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sensitive paths from class that is used to check is path sensitive.
|
||||
*
|
||||
* There is no public method to get this data.
|
||||
* It's why they are read using private method.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSensitivePaths(): array
|
||||
{
|
||||
$typePool = Bootstrap::getObjectManager()->get(TypePool::class);
|
||||
$sensitivePathsReader = \Closure::bind(
|
||||
function () {
|
||||
return $this->getPathsByType(TypePool::TYPE_SENSITIVE);
|
||||
},
|
||||
$typePool,
|
||||
$typePool
|
||||
);
|
||||
|
||||
return $sensitivePathsReader();
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Config\Model\Config\Processor;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
|
||||
class EnvironmentPlaceholderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var EnvironmentPlaceholder
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $env = [];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->model = $this->objectManager->get(EnvironmentPlaceholder::class);
|
||||
$this->env = $_ENV;
|
||||
}
|
||||
|
||||
public function testProcess()
|
||||
{
|
||||
$_ENV = array_merge(
|
||||
$_ENV,
|
||||
[
|
||||
'CONFIG__DEFAULT__WEB__UNSECURE__BASE_URL' => 'http://expected.local',
|
||||
'CONFIG__TEST__TEST__DESIGN__HEADER__WELCOME' => 'Expected header',
|
||||
'TEST__TEST__WEB__SECURE__BASE_URL' => 'http://wrong_pattern.local',
|
||||
'CONFIG__DEFAULT__GENERAL__REGION__DISPLAY_ALL' => 1
|
||||
]
|
||||
);
|
||||
$expected = [
|
||||
'default' => [
|
||||
'web' => [
|
||||
'unsecure' => [
|
||||
'base_url' => 'http://expected.local'
|
||||
],
|
||||
'secure' => [
|
||||
'base_url' => 'https://original.local'
|
||||
]
|
||||
],
|
||||
'general' => [
|
||||
'region' => [
|
||||
'display_all' => 1
|
||||
],
|
||||
],
|
||||
],
|
||||
'test' => [
|
||||
'test' => [
|
||||
'design' => [
|
||||
'header' => [
|
||||
'welcome' => 'Expected header'
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
$config = [
|
||||
'default' => [
|
||||
'web' => [
|
||||
'unsecure' => [
|
||||
'base_url' => 'http://original.local',
|
||||
],
|
||||
'secure' => [
|
||||
'base_url' => 'https://original.local'
|
||||
]
|
||||
]
|
||||
],
|
||||
'test' => [
|
||||
'test' => [
|
||||
'design' => [
|
||||
'header' => [
|
||||
'welcome' => 'Original header'
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->model->process($config)
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$_ENV = $this->env;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Config\Model\Config\Structure\Reader;
|
||||
|
||||
use Magento\Config\Model\Config\Structure\Converter;
|
||||
|
||||
/**
|
||||
* Class ConverterStub used for ReaderTest.
|
||||
*/
|
||||
class ConverterStub extends Converter
|
||||
{
|
||||
/**
|
||||
* Convert dom document wrapper.
|
||||
*
|
||||
* @param \DOMDocument $document
|
||||
* @return array|null
|
||||
*/
|
||||
public function getArrayData(\DOMDocument $document)
|
||||
{
|
||||
return $this->_convertDOMDocument($document);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert dom document.
|
||||
*
|
||||
* @param \DOMNode $source
|
||||
* @return array
|
||||
*/
|
||||
public function convert($source)
|
||||
{
|
||||
return $this->_convertDOMDocument($source);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Config\Model\Config\Structure\Reader;
|
||||
|
||||
use Magento\Config\Model\Config\Structure\Reader;
|
||||
|
||||
/**
|
||||
* Class ReaderStub used for testing protected Reader::_readFiles() method.
|
||||
*/
|
||||
class ReaderStub extends Reader
|
||||
{
|
||||
/**
|
||||
* Wrapper for protected Reader::_readFiles() method.
|
||||
*
|
||||
* @param array $fileList
|
||||
* @return array
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function readFiles(array $fileList)
|
||||
{
|
||||
return $this->_readFiles($fileList);
|
||||
}
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Config\Model\Config\Structure\Reader;
|
||||
|
||||
use Magento\Config\Model\Config\SchemaLocator;
|
||||
use Magento\Framework\App\Utility\Files;
|
||||
use Magento\Framework\Config\Dom;
|
||||
use Magento\Framework\Config\FileResolverInterface;
|
||||
use Magento\Framework\Config\ValidationStateInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\TemplateEngine\Xhtml\CompilerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class ReaderTest check Magento\Config\Model\Config\Structure\Reader::_readFiles() method.
|
||||
*/
|
||||
class ReaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test config location.
|
||||
*
|
||||
* @string
|
||||
*/
|
||||
const CONFIG = '/dev/tests/integration/testsuite/Magento/Config/Model/Config/Structure/Reader/_files/';
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Files
|
||||
*/
|
||||
private $fileUtility;
|
||||
|
||||
/**
|
||||
* @var ValidationStateInterface
|
||||
*/
|
||||
private $validationStateMock;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Config\SchemaLocatorInterface
|
||||
*/
|
||||
private $schemaLocatorMock;
|
||||
|
||||
/**
|
||||
* @var FileResolverInterface
|
||||
*/
|
||||
private $fileResolverMock;
|
||||
|
||||
/**
|
||||
* @var ReaderStub
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* @var ConverterStub
|
||||
*/
|
||||
private $converter;
|
||||
|
||||
/**
|
||||
* @var CompilerInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $compiler;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->fileUtility = Files::init();
|
||||
|
||||
$this->validationStateMock = $this->getMockBuilder(ValidationStateInterface::class)
|
||||
->setMethods(['isValidationRequired'])
|
||||
->getMockForAbstractClass();
|
||||
$this->schemaLocatorMock = $this->getMockBuilder(SchemaLocator::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getPerFileSchema'])
|
||||
->getMock();
|
||||
$this->fileResolverMock = $this->getMockBuilder(FileResolverInterface::class)
|
||||
->getMockForAbstractClass();
|
||||
|
||||
$this->validationStateMock->expects($this->atLeastOnce())
|
||||
->method('isValidationRequired')
|
||||
->willReturn(false);
|
||||
$this->schemaLocatorMock->expects($this->atLeastOnce())
|
||||
->method('getPerFileSchema')
|
||||
->willReturn(false);
|
||||
|
||||
$this->converter = $this->objectManager->create(ConverterStub::class);
|
||||
|
||||
//Isolate test from actual configuration, and leave only sample data.
|
||||
$this->compiler = $this->getMockBuilder(CompilerInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['compile'])
|
||||
->getMockForAbstractClass();
|
||||
|
||||
$this->reader = $this->objectManager->create(
|
||||
ReaderStub::class,
|
||||
[
|
||||
'fileResolver' => $this->fileResolverMock,
|
||||
'converter' => $this->converter,
|
||||
'schemaLocator' => $this->schemaLocatorMock,
|
||||
'validationState' => $this->validationStateMock,
|
||||
'fileName' => 'no_existing_file.xml',
|
||||
'compiler' => $this->compiler,
|
||||
'domDocumentClass' => Dom::class
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The test checks the file structure after processing the nodes responsible for inserting content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testXmlConvertedConfigurationAndCompereStructure()
|
||||
{
|
||||
$actual = $this->reader->readFiles(['actual' => $this->getContent()]);
|
||||
|
||||
$document = new \DOMDocument();
|
||||
$document->loadXML($this->getContent());
|
||||
|
||||
$expected = $this->converter->getArrayData($document);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config sample data for test.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getContent()
|
||||
{
|
||||
$files = $this->fileUtility->getFiles([BP . static::CONFIG], 'config.xml');
|
||||
|
||||
return file_get_contents(reset($files));
|
||||
}
|
||||
}
|
||||
+373
@@ -0,0 +1,373 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||
<system>
|
||||
<section id="payment">
|
||||
<group id="account" translate="label" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
|
||||
<label>Merchant Location</label>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
|
||||
<field id="merchant_country" type="select" translate="label comment" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
|
||||
<label>Merchant Country</label>
|
||||
<comment>If not specified, Default Country from General Config will be used.</comment>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Field\Country</frontend_model>
|
||||
<source_model>Magento\Paypal\Model\System\Config\Source\MerchantCountry</source_model>
|
||||
<backend_model>Magento\Paypal\Model\System\Config\Backend\MerchantCountry</backend_model>
|
||||
<config_path>paypal/general/merchant_country</config_path>
|
||||
</field>
|
||||
</group>
|
||||
<group id="recommended_solutions" translate="label" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Recommended Solutions:</label>
|
||||
<fieldset_css>paypal-top-section paypal-recommended-header</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
|
||||
</group>
|
||||
<group id="other_paypal_payment_solutions" translate="label" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Other PayPal Payment Solutions:</label>
|
||||
<fieldset_css>paypal-top-section paypal-other-header</fieldset_css>
|
||||
<frontend_model>\Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
|
||||
</group>
|
||||
<group id="other_payment_methods" translate="label" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Other Payment Methods:</label>
|
||||
<fieldset_css>paypal-top-section payments-other-header</fieldset_css>
|
||||
<frontend_model>\Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_all_paypal" showInDefault="0" showInWebsite="0" showInStore="0">
|
||||
<include path="Magento_Paypal::system/paypal_payflowpro.xml"/>
|
||||
<include path="Magento_Paypal::system/payflow_link.xml"/>
|
||||
<include path="Magento_Paypal::system/express_checkout.xml"/>
|
||||
<include path="Magento_Paypal::system/payments_pro_hosted_solution.xml"/>
|
||||
<group id="payments_pro_hosted_solution_without_bml" extends="payments_pro_hosted_solution">
|
||||
<group id="pphs_required_settings">
|
||||
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
|
||||
<group id="pphs_advertise_bml" showInDefault="0" showInWebsite="0"/>
|
||||
</group>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_us" extends="payment" showInDefault="0" showInWebsite="0" showInStore="0">
|
||||
<group id="paypal_alternative_payment_methods" sortOrder="5" showInDefault="0" showInWebsite="0" showInStore="0">
|
||||
<group id="express_checkout_us" translate="label comment" extends="payment_all_paypal/express_checkout" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>PayPal Express Checkout</label>
|
||||
<fieldset_css>complex paypal-express-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
|
||||
<comment>Add another payment method to your existing solution or as a stand-alone option.</comment>
|
||||
<help_url>https://merchant.paypal.com/cgi-bin/marketingweb?cmd=_render-content</help_url>
|
||||
<attribute type="shared">0</attribute>
|
||||
<attribute type="activity_path">payment/paypal_express/active</attribute>
|
||||
<attribute type="activity_path">payment/payflow_express/active</attribute>
|
||||
<attribute type="displayIn">recommended_solutions</attribute>
|
||||
</group>
|
||||
</group>
|
||||
<group id="paypal_group_all_in_one" translate="label comment" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label><![CDATA[PayPal All-in-One Payment Solutions <i>Accept and process credit cards and PayPal payments.</i>]]></label>
|
||||
<fieldset_css>complex paypal-other-section paypal-all-in-one-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
|
||||
<comment>Choose a secure bundled payment solution for your business.</comment>
|
||||
<attribute type="displayIn">other_paypal_payment_solutions</attribute>
|
||||
<include path="Magento_Paypal::system/payflow_advanced.xml"/>
|
||||
<group id="wpp_usuk" translate="label" sortOrder="40" extends="payment_us/paypal_payment_gateways/paypal_payflowpro_with_express_checkout">
|
||||
<label>Payments Pro</label>
|
||||
<attribute type="activity_path">payment/paypal_payment_pro/active</attribute>
|
||||
<group id="configuration_details">
|
||||
<comment>https://docs.magento.com/user-guide/payment/paypal-payments-pro.html</comment>
|
||||
</group>
|
||||
<group id="paypal_payflow_required" translate="label" showInDefault="1" showInWebsite="1" sortOrder="10">
|
||||
<field id="enable_paypal_payflow">
|
||||
<attribute type="shared">0</attribute>
|
||||
<config_path>payment/paypal_payment_pro/active</config_path>
|
||||
</field>
|
||||
<group id="paypal_payflow_api_settings" translate="label">
|
||||
<label>Payments Pro and Express Checkout</label>
|
||||
</group>
|
||||
</group>
|
||||
<group id="settings_paypal_payflow" translate="label">
|
||||
<label>Basic Settings - PayPal Payments Pro</label>
|
||||
</group>
|
||||
</group>
|
||||
<group id="wps_express" extends="payment_all_paypal/express_checkout">
|
||||
<label>Payments Standard</label>
|
||||
<comment>Accept credit card and PayPal payments securely.</comment>
|
||||
<attribute type="activity_path">payment/wps_express/active</attribute>
|
||||
<group id="configuration_details">
|
||||
<comment>https://docs.magento.com/user-guide/payment/paypal-payments-standard.html</comment>
|
||||
</group>
|
||||
<group id="express_checkout_required">
|
||||
<group id="express_checkout_required_express_checkout">
|
||||
<label>Payments Standard</label>
|
||||
</group>
|
||||
<field id="enable_in_context_checkout" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="merchant_id" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="enable_express_checkout">
|
||||
<config_path>payment/wps_express/active</config_path>
|
||||
</field>
|
||||
<field id="enable_express_checkout_bml">
|
||||
<config_path>payment/wps_express_bml/active</config_path>
|
||||
</field>
|
||||
</group>
|
||||
<group id="settings_ec">
|
||||
<label>Basic Settings - PayPal Website Payments Standard</label>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
<group id="paypal_payment_gateways" translate="label" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label><![CDATA[PayPal Payment Gateways <i>Process payments using your own internet merchant account.</i>]]></label>
|
||||
<fieldset_css>complex paypal-other-section paypal-gateways-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
|
||||
<attribute type="displayIn">other_paypal_payment_solutions</attribute>
|
||||
<include path="Magento_Paypal::system/paypal_payflowpro_with_express_checkout.xml"/>
|
||||
<group id="payflow_link_us" extends="payment_all_paypal/payflow_link"/>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_gb" extends="payment" showInDefault="0" showInWebsite="0" showInStore="0">
|
||||
<group id="paypal_alternative_payment_methods" sortOrder="5" showInDefault="0" showInWebsite="0" showInStore="0">
|
||||
<group id="express_checkout_gb" translate="label comment" extends="payment_all_paypal/express_checkout" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>PayPal Express Checkout</label>
|
||||
<fieldset_css>complex paypal-express-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
|
||||
<comment>Add another payment method to your existing solution or as a stand-alone option.</comment>
|
||||
<help_url>https://merchant.paypal.com/cgi-bin/marketingweb?cmd=_render-content</help_url>
|
||||
<attribute type="displayIn">recommended_solutions</attribute>
|
||||
<group id="express_checkout_required">
|
||||
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
|
||||
<group id="advertise_bml" showInDefault="0" showInWebsite="0"/>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
<group id="paypal_group_all_in_one" translate="label comment" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label><![CDATA[PayPal All-in-One Payment Solutions <i>Accept and process credit cards and PayPal payments.</i>]]></label>
|
||||
<fieldset_css>complex paypal-other-section paypal-all-in-one-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
|
||||
<comment>Choose a secure bundled payment solution for your business.</comment>
|
||||
<help_url>https://www.paypal-marketing.com/emarketing/partner/na/merchantlineup/home.page#mainTab=checkoutlineup&subTab=newlineup</help_url>
|
||||
<attribute type="displayIn">other_paypal_payment_solutions</attribute>
|
||||
<group id="wpp_usuk" translate="comment" sortOrder="20">
|
||||
<fieldset_css>pp-general-uk</fieldset_css>
|
||||
<demo_link>http://www.youtube.com/watch?v=LBe-TW87eGI&list=PLF18B1094ABCD7CE8&index=1&feature=plpp_video</demo_link>
|
||||
<comment>Accept payments with a completely customizable checkout page.</comment>
|
||||
<group id="wpp_required_settings">
|
||||
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
|
||||
<group id="wpp_advertise_bml" showInDefault="0" showInWebsite="0"/>
|
||||
</group>
|
||||
</group>
|
||||
<include path="Magento_Paypal::system/payments_pro_hosted_solution_with_express_checkout.xml"/>
|
||||
<group id="wps_express" extends="payment_all_paypal/express_checkout" sortOrder="50">
|
||||
<label>Website Payments Standard</label>
|
||||
<comment>Accept credit card and PayPal payments securely.</comment>
|
||||
<attribute type="activity_path">payment/wps_express/active</attribute>
|
||||
<group id="configuration_details">
|
||||
<comment>https://docs.magento.com/user-guide/payment/paypal-payments-standard.html</comment>
|
||||
</group>
|
||||
<group id="express_checkout_required">
|
||||
<group id="express_checkout_required_express_checkout">
|
||||
<label>Website Payments Standard</label>
|
||||
</group>
|
||||
<field id="enable_in_context_checkout" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="merchant_id" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="enable_express_checkout">
|
||||
<config_path>payment/wps_express/active</config_path>
|
||||
</field>
|
||||
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
|
||||
<group id="advertise_bml" showInDefault="0" showInWebsite="0"/>
|
||||
</group>
|
||||
<group id="settings_ec">
|
||||
<label>Basic Settings - PayPal Website Payments Standard</label>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_de" extends="payment" showInDefault="0" showInWebsite="0" showInStore="0">
|
||||
<group id="paypal_payment_solutions" sortOrder="5" showInDefault="0" showInWebsite="0" showInStore="0">
|
||||
<group id="express_checkout_de" translate="label comment" extends="payment_all_paypal/express_checkout" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>PayPal Express Checkout</label>
|
||||
<fieldset_css>complex paypal-express-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
|
||||
<comment>Add another payment method to your existing solution or as a stand-alone option.</comment>
|
||||
<help_url>https://www.paypal-marketing.com/emarketing/partner/na/merchantlineup/home.page#mainTab=checkoutlineup&subTab=newlineup</help_url>
|
||||
<attribute type="displayIn">recommended_solutions</attribute>
|
||||
<group id="express_checkout_required">
|
||||
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
|
||||
<group id="advertise_bml" showInDefault="0" showInWebsite="0"/>
|
||||
</group>
|
||||
<group id="settings_ec">
|
||||
<group id="settings_ec_advanced">
|
||||
<field id="solution_type" showInDefault="0" showInWebsite="0"/>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_other" extends="payment" showInDefault="0" showInWebsite="0" showInStore="0">
|
||||
<group id="express_checkout_other" translate="label comment" sortOrder="5" extends="payment_all_paypal/express_checkout" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>PayPal Express Checkout</label>
|
||||
<fieldset_css>complex paypal-express-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
|
||||
<comment>Add another payment method to your existing solution or as a stand-alone option.</comment>
|
||||
<help_url>https://www.paypal-marketing.com/emarketing/partner/na/merchantlineup/home.page#mainTab=checkoutlineup&subTab=newlineup</help_url>
|
||||
<attribute type="displayIn">recommended_solutions</attribute>
|
||||
<group id="express_checkout_required">
|
||||
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
|
||||
<group id="advertise_bml" showInDefault="0" showInWebsite="0"/>
|
||||
</group>
|
||||
</group>
|
||||
<group id="paypal_group_all_in_one" translate="label comment" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label><![CDATA[PayPal All-in-One Payment Solutions <i>Accept and process credit cards and PayPal payments.</i>]]></label>
|
||||
<fieldset_css>complex paypal-other-section paypal-all-in-one-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
|
||||
<comment>Choose a secure bundled payment solution for your business.</comment>
|
||||
<help_url>https://www.paypal-marketing.com/emarketing/partner/na/merchantlineup/home.page#mainTab=checkoutlineup&subTab=newlineup</help_url>
|
||||
<attribute type="displayIn">other_paypal_payment_solutions</attribute>
|
||||
<group id="wps_other" extends="payment_all_paypal/express_checkout" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Website Payments Standard</label>
|
||||
<fieldset_css>complex</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
|
||||
<comment>Accept credit card and PayPal payments securely.</comment>
|
||||
<attribute type="activity_path">payment/wps_express/active</attribute>
|
||||
<group id="configuration_details">
|
||||
<comment>https://docs.magento.com/user-guide/payment/paypal-payments-standard.html</comment>
|
||||
</group>
|
||||
<group id="express_checkout_required">
|
||||
<group id="express_checkout_required_express_checkout">
|
||||
<label>Website Payments Standard</label>
|
||||
</group>
|
||||
<field id="enable_in_context_checkout" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="merchant_id" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="enable_express_checkout">
|
||||
<config_path>payment/wps_express/active</config_path>
|
||||
</field>
|
||||
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
|
||||
<group id="advertise_bml" showInDefault="0" showInWebsite="0"/>
|
||||
</group>
|
||||
<group id="settings_ec">
|
||||
<label>Basic Settings - PayPal Website Payments Standard</label>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
<group id="paypal_payment_gateways" translate="label comment" sortOrder="8" showInDefault="0" showInWebsite="0" showInStore="0">
|
||||
<label><![CDATA[PayPal Payment Gateways <i>Process payments using your own internet merchant account.</i>]]></label>
|
||||
<fieldset_css>complex paypal-other-section paypal-gateways-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
|
||||
<comment>Process payments using your own internet merchant account.</comment>
|
||||
<help_url>https://merchant.paypal.com/cgi-bin/marketingweb?cmd=_render-content</help_url>
|
||||
<attribute type="displayIn">other_paypal_payment_solutions</attribute>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_ca" extends="payment_other">
|
||||
<group id="express_checkout_other">
|
||||
<attribute type="activity_path">payment/paypal_express/active</attribute>
|
||||
<attribute type="activity_path">payment/payflow_express/active</attribute>
|
||||
</group>
|
||||
<group id="paypal_group_all_in_one">
|
||||
<group id="wps_other" sortOrder="20"/>
|
||||
</group>
|
||||
<group id="paypal_payment_gateways" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<fieldset_css>complex paypal-other-section paypal-gateways-section</fieldset_css>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
|
||||
<label><![CDATA[PayPal Payment Gateways <i>Process payments using your own internet merchant account.</i>]]></label>
|
||||
<group id="wpp_ca" translate="label" extends="payment_all_paypal/paypal_payflowpro" sortOrder="30">
|
||||
<label>Website Payments Pro</label>
|
||||
<attribute type="activity_path">payment/paypal_payment_pro/active</attribute>
|
||||
<group id="configuration_details">
|
||||
<comment>https://docs.magento.com/user-guide/payment/paypal-payments-pro.html</comment>
|
||||
</group>
|
||||
<group id="paypal_payflow_required" translate="label" showInDefault="1" showInWebsite="1" sortOrder="10">
|
||||
<group id="paypal_payflow_api_settings">
|
||||
<label>Payments Pro</label>
|
||||
</group>
|
||||
<field id="enable_in_context_checkout" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="merchant_id" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="enable_paypal_payflow">
|
||||
<frontend_class>paypal-enabler paypal-ec-pe</frontend_class>
|
||||
<attribute type="shared">0</attribute>
|
||||
<config_path>payment/paypal_payment_pro/active</config_path>
|
||||
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Field\Enable\Payment</frontend_model>
|
||||
</field>
|
||||
</group>
|
||||
<group id="settings_paypal_payflow">
|
||||
<label>Basic Settings - PayPal Payments Pro</label>
|
||||
</group>
|
||||
</group>
|
||||
<group id="paypal_payflowpro_ca" extends="payment_all_paypal/paypal_payflowpro" sortOrder="40"/>
|
||||
<group id="payflow_link_ca" extends="payment_all_paypal/payflow_link" sortOrder="50">
|
||||
<group id="payflow_link_required">
|
||||
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
|
||||
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
|
||||
<group id="payflow_link_advertise_bml" showInDefault="0" showInWebsite="0"/>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_au" extends="payment_other">
|
||||
<group id="express_checkout_other"/>
|
||||
<group id="paypal_group_all_in_one">
|
||||
<group id="wps_other" sortOrder="12"/>
|
||||
<group id="payments_pro_hosted_solution_au" extends="payment_all_paypal/payments_pro_hosted_solution_without_bml" sortOrder="10"/>
|
||||
</group>
|
||||
<group id="paypal_payment_gateways" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<group id="paypal_payflowpro_au" extends="payment_all_paypal/paypal_payflowpro" sortOrder="20"/>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_jp" extends="payment_other">
|
||||
<group id="express_checkout_other"/>
|
||||
<group id="paypal_group_all_in_one">
|
||||
<group id="wps_other" sortOrder="12"/>
|
||||
<group id="payments_pro_hosted_solution_jp" extends="payment_all_paypal/payments_pro_hosted_solution_without_bml" sortOrder="10">
|
||||
<label>Website Payments Plus</label>
|
||||
</group>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_fr" extends="payment_other">
|
||||
<group id="express_checkout_other"/>
|
||||
<group id="paypal_group_all_in_one">
|
||||
<group id="wps_other" sortOrder="12"/>
|
||||
<group id="payments_pro_hosted_solution_fr" extends="payment_all_paypal/payments_pro_hosted_solution_without_bml" sortOrder="10">
|
||||
<label>Integral Evolution</label>
|
||||
</group>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_it" extends="payment_other">
|
||||
<group id="express_checkout_other"/>
|
||||
<group id="paypal_group_all_in_one">
|
||||
<group id="wps_other" sortOrder="12"/>
|
||||
<group id="payments_pro_hosted_solution_it" extends="payment_all_paypal/payments_pro_hosted_solution_without_bml" sortOrder="10">
|
||||
<label>Pro</label>
|
||||
</group>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_es" extends="payment_other">
|
||||
<group id="express_checkout_other"/>
|
||||
<group id="paypal_group_all_in_one">
|
||||
<group id="wps_other" sortOrder="12"/>
|
||||
<group id="payments_pro_hosted_solution_es" extends="payment_all_paypal/payments_pro_hosted_solution_without_bml" sortOrder="10">
|
||||
<label>Pasarela integral</label>
|
||||
</group>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_hk" extends="payment_other">
|
||||
<group id="express_checkout_other"/>
|
||||
<group id="paypal_group_all_in_one">
|
||||
<group id="wps_other" sortOrder="12"/>
|
||||
<group id="payments_pro_hosted_solution_hk" extends="payment_all_paypal/payments_pro_hosted_solution_without_bml" sortOrder="10"/>
|
||||
</group>
|
||||
</section>
|
||||
<section id="payment_nz" extends="payment_other">
|
||||
<group id="express_checkout_other"/>
|
||||
<group id="paypal_group_all_in_one">
|
||||
<group id="wps_other"/>
|
||||
</group>
|
||||
<group id="paypal_payment_gateways" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<group id="paypal_payflowpro_nz" extends="payment_all_paypal/paypal_payflowpro"/>
|
||||
</group>
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Config\Model;
|
||||
|
||||
use Magento\Backend\App\Area\FrontNameResolver;
|
||||
use Magento\Config\Model\ResourceModel\Config\Data\Collection;
|
||||
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
|
||||
use Magento\Framework\Config\ScopeInterface;
|
||||
use Magento\Framework\Encryption\EncryptorInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ConfigTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Magento\Config\Model\Config::save
|
||||
* @param array $groups
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider saveWithSingleStoreModeEnabledDataProvider
|
||||
* @magentoConfigFixture current_store general/single_store_mode/enabled 1
|
||||
*/
|
||||
public function testSaveWithSingleStoreModeEnabled($groups)
|
||||
{
|
||||
Bootstrap::getObjectManager()->get(
|
||||
ScopeInterface::class
|
||||
)->setCurrentScope(
|
||||
FrontNameResolver::AREA_CODE
|
||||
);
|
||||
/** @var $_configDataObject Config */
|
||||
$_configDataObject = Bootstrap::getObjectManager()->create(Config::class);
|
||||
$_configData = $_configDataObject->setSection('dev')->setWebsite('base')->load();
|
||||
$this->assertEmpty($_configData);
|
||||
|
||||
$_configDataObject = Bootstrap::getObjectManager()->create(Config::class);
|
||||
$_configDataObject->setSection('dev')->setGroups($groups)->save();
|
||||
|
||||
/** @var $_configDataObject Config */
|
||||
$_configDataObject = Bootstrap::getObjectManager()->create(Config::class);
|
||||
$_configData = $_configDataObject->setSection('dev')->load();
|
||||
$this->assertArrayHasKey('dev/debug/template_hints_admin', $_configData);
|
||||
$this->assertArrayHasKey('dev/debug/template_hints_blocks', $_configData);
|
||||
|
||||
$_configDataObject = Bootstrap::getObjectManager()->create(Config::class);
|
||||
$_configData = $_configDataObject->setSection('dev')->setWebsite('base')->load();
|
||||
$this->assertArrayNotHasKey('dev/debug/template_hints_admin', $_configData);
|
||||
$this->assertArrayNotHasKey('dev/debug/template_hints_blocks', $_configData);
|
||||
}
|
||||
|
||||
public function saveWithSingleStoreModeEnabledDataProvider()
|
||||
{
|
||||
return require __DIR__ . '/_files/config_groups.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Config\Model\Config::save
|
||||
* @param string $section
|
||||
* @param array $groups
|
||||
* @param array $expected
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider saveDataProvider
|
||||
*/
|
||||
public function testSave($section, $groups, $expected)
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var $_configDataObject Config */
|
||||
$_configDataObject = $objectManager->create(Config::class);
|
||||
$_configDataObject->setSection($section)->setWebsite('base')->setGroups($groups)->save();
|
||||
|
||||
foreach ($expected as $group => $expectedData) {
|
||||
$_configDataObject = $objectManager->create(Config::class);
|
||||
$_configData = $_configDataObject->setSection($group)->setWebsite('base')->load();
|
||||
if (array_key_exists('payment/payflow_link/pwd', $_configData)) {
|
||||
$_configData['payment/payflow_link/pwd'] = $objectManager->get(
|
||||
EncryptorInterface::class
|
||||
)->decrypt(
|
||||
$_configData['payment/payflow_link/pwd']
|
||||
);
|
||||
}
|
||||
$this->assertEquals($expectedData, $_configData);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveDataProvider()
|
||||
{
|
||||
return require __DIR__ . '/_files/config_section.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $website
|
||||
* @param string $section
|
||||
* @param array $override
|
||||
* @param array $inherit
|
||||
* @param array $expected
|
||||
* @dataProvider saveWebsiteScopeDataProvider
|
||||
*/
|
||||
public function testSaveUseDefault(
|
||||
string $website,
|
||||
string $section,
|
||||
array $override,
|
||||
array $inherit,
|
||||
array $expected
|
||||
): void {
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Config $config*/
|
||||
$configFactory = $objectManager->create(ConfigFactory::class);
|
||||
$config = $configFactory->create()
|
||||
->setSection($section)
|
||||
->setWebsite($website)
|
||||
->setGroups($override['groups'])
|
||||
->save();
|
||||
|
||||
$paths = array_keys($expected);
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->getConfigValues($config->getScope(), $config->getScopeId(), $paths)
|
||||
);
|
||||
|
||||
$config = $configFactory->create()
|
||||
->setSection($section)
|
||||
->setWebsite($website)
|
||||
->setGroups($inherit['groups'])
|
||||
->save();
|
||||
|
||||
$this->assertEmpty(
|
||||
$this->getConfigValues($config->getScope(), $config->getScopeId(), $paths)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function saveWebsiteScopeDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'website' => 'base',
|
||||
'section' => 'payment',
|
||||
[
|
||||
'groups' => [
|
||||
'account' => [
|
||||
'fields' => [
|
||||
'merchant_country' => ['value' => 'GB'],
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'groups' => [
|
||||
'account' => [
|
||||
'fields' => [
|
||||
'merchant_country' => ['inherit' => 1],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'expected' => [
|
||||
'paypal/general/merchant_country' => 'GB',
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $scope
|
||||
* @param int $scopeId
|
||||
* @param array $paths
|
||||
* @return array
|
||||
*/
|
||||
private function getConfigValues(string $scope, int $scopeId, array $paths): array
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Collection $configCollection */
|
||||
$configCollectionFactory = $objectManager->create(CollectionFactory::class);
|
||||
$configCollection = $configCollectionFactory->create();
|
||||
$configCollection->addFieldToFilter('scope', $scope);
|
||||
$configCollection->addFieldToFilter('scope_id', $scopeId);
|
||||
$configCollection->addFieldToFilter('path', ['in' => $paths]);
|
||||
$result = [];
|
||||
foreach ($configCollection as $data) {
|
||||
$result[$data->getPath()] = $data->getValue();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Config\Model\Data\ReEncryptorList\CoreConfigDataReEncryptor;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Framework\App\Config;
|
||||
use Magento\Framework\App\Config\Initial;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Config\Model\ResourceModel\Config as ConfigResource;
|
||||
use Magento\Config\Model\Config\Backend\Encrypted;
|
||||
use Magento\Framework\Encryption\EncryptorInterface;
|
||||
|
||||
/**
|
||||
* Test for the core configuration re-encryption handler.
|
||||
*/
|
||||
class HandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Config|null
|
||||
*/
|
||||
private ?Config $config;
|
||||
|
||||
/**
|
||||
* @var ConfigResource|null
|
||||
*/
|
||||
private ?ConfigResource $configResource;
|
||||
|
||||
/**
|
||||
* @var EncryptorInterface|null
|
||||
*/
|
||||
private ?EncryptorInterface $encryptor;
|
||||
|
||||
/**
|
||||
* Initialize dependencies
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->config = Bootstrap::getObjectManager()->get(
|
||||
Config::class
|
||||
);
|
||||
|
||||
$this->configResource = Bootstrap::getObjectManager()->get(
|
||||
ConfigResource::class
|
||||
);
|
||||
|
||||
$this->encryptor = Bootstrap::getObjectManager()->get(
|
||||
EncryptorInterface::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ReEncryption for core config data
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testReEncrypt():void
|
||||
{
|
||||
$testConfigPath1 = "test/correct_enc_value";
|
||||
$testConfigPath2 = "test/incorrect_enc_value";
|
||||
$testConfigPath3 = "test/empty_enc_value";
|
||||
|
||||
$this->configResource->saveConfig(
|
||||
$testConfigPath1,
|
||||
$this->encryptor->encrypt("Encrypted Config Value")
|
||||
);
|
||||
$this->configResource->saveConfig(
|
||||
$testConfigPath2,
|
||||
substr_replace(
|
||||
$this->encryptor->encrypt("Encrypted Config Value"),
|
||||
"9",
|
||||
2,
|
||||
1
|
||||
)
|
||||
);
|
||||
$this->configResource->saveConfig($testConfigPath3, "");
|
||||
|
||||
$this->config->clean();
|
||||
|
||||
$configValue1BeforeReEncryption = $this->config->getValue($testConfigPath1);
|
||||
$configValue2BeforeReEncryption = $this->config->getValue($testConfigPath2);
|
||||
|
||||
/** @var Handler $coreConfigDataReEncryptionHandler */
|
||||
$coreConfigDataReEncryptionHandler = Bootstrap::getObjectManager()->create(
|
||||
Handler::class
|
||||
);
|
||||
|
||||
try {
|
||||
$errors = $coreConfigDataReEncryptionHandler->reEncrypt();
|
||||
} catch (\Throwable $e) {
|
||||
$this->fail(
|
||||
sprintf(
|
||||
'Re-encryption failed: %s',
|
||||
$e->getMessage()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Asserting that the handler reacts properly to DB row level errors
|
||||
// during re-encryption.
|
||||
$this->assertEquals(1, count($errors));
|
||||
$this->assertEquals("config_id", $errors[0]->getRowIdField());
|
||||
$this->assertEquals("Not supported cipher version", $errors[0]->getMessage());
|
||||
|
||||
$this->config->clean();
|
||||
|
||||
$configValue1AfterReEncryption = $this->config->getValue($testConfigPath1);
|
||||
$configValue2AfterReEncryption = $this->config->getValue($testConfigPath2);
|
||||
$configValue3AfterReEncryption = $this->config->getValue($testConfigPath3);
|
||||
|
||||
// Asserting changes done by re-encryption the first test configuration value.
|
||||
// Encrypted value that was not empty should not be empty.
|
||||
$this->assertNotEmpty($configValue1AfterReEncryption);
|
||||
// Encrypted value should be changed.
|
||||
$this->assertNotEquals(
|
||||
$configValue1BeforeReEncryption,
|
||||
$configValue1AfterReEncryption
|
||||
);
|
||||
// It still should be possible to decrypt the value.
|
||||
$this->assertEquals(
|
||||
"Encrypted Config Value",
|
||||
$this->encryptor->decrypt($configValue1AfterReEncryption)
|
||||
);
|
||||
|
||||
// Asserting changes done by re-encryption the second test configuration value.
|
||||
// Encrypted field should stay unchanged if DB row level error occurred.
|
||||
$this->assertEquals(
|
||||
$configValue2BeforeReEncryption,
|
||||
$configValue2AfterReEncryption
|
||||
);
|
||||
|
||||
// Asserting changes done by re-encryption the third test configuration value.
|
||||
// Empty or NULL values should stay unchanged.
|
||||
$this->assertEmpty($configValue3AfterReEncryption);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Config\Model\ResourceModel;
|
||||
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Config\Model\ResourceModel\Config
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Config\Model\ResourceModel\Config::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testSaveDeleteConfig()
|
||||
{
|
||||
$connection = $this->_model->getConnection();
|
||||
$select = $connection->select()->from($this->_model->getMainTable())->where('path=?', 'test/config');
|
||||
$this->_model->saveConfig('test/config', 'test', 'default', 0);
|
||||
$this->assertNotEmpty($connection->fetchRow($select));
|
||||
|
||||
$this->_model->deleteConfig('test/config', 'default', 0);
|
||||
$this->assertEmpty($connection->fetchRow($select));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
return [
|
||||
[
|
||||
'groups' => [
|
||||
'restrict' => ['fields' => ['allow_ips' => ['value' => '']]],
|
||||
'debug' => [
|
||||
'fields' => [
|
||||
'template_hints_admin' => ['value' => '0'],
|
||||
'template_hints_blocks' => ['value' => '0'],
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
return [
|
||||
[
|
||||
'section' => 'dev',
|
||||
'groups' => [
|
||||
'log' => [
|
||||
'fields' => [
|
||||
'active' => ['value' => '1'],
|
||||
'file' => ['value' => 'fileName.log'],
|
||||
'exception_file' => ['value' => 'exceptionFileName.log'],
|
||||
],
|
||||
],
|
||||
'debug' => [
|
||||
'fields' => [
|
||||
'template_hints_storefront' => ['value' => '1'],
|
||||
'template_hints_blocks' => ['value' => '0'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'expected' => [
|
||||
'dev/log' => [
|
||||
'dev/log/active' => '1',
|
||||
'dev/log/file' => 'fileName.log',
|
||||
'dev/log/exception_file' => 'exceptionFileName.log',
|
||||
],
|
||||
'dev/debug' => [
|
||||
'dev/debug/template_hints_storefront' => '1',
|
||||
'dev/debug/template_hints_blocks' => '0',
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
/** @var \Magento\Framework\Filesystem\Directory\Write $rootDirectory */
|
||||
$rootDirectory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Filesystem::class
|
||||
)->getDirectoryWrite(
|
||||
DirectoryList::PUB
|
||||
);
|
||||
if ($rootDirectory->isExist('robots.txt')) {
|
||||
$rootDirectory->delete('robots.txt');
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Sitemap: http://store.com/sitemap.xml
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/** @var $fileSystem Filesystem */
|
||||
$fileSystem = Bootstrap::getObjectManager()->get(Filesystem::class);
|
||||
$pubDirectory = $fileSystem->getDirectoryWrite(DirectoryList::PUB);
|
||||
$rootDirectory = $fileSystem->getDirectoryRead(DirectoryList::ROOT);
|
||||
$source = $rootDirectory->getAbsolutePath(__DIR__ . '/robots.txt');
|
||||
$content = $rootDirectory->readFile(__DIR__ . '/robots.txt');
|
||||
$pubDirectory->writeFile('robots.txt', $content);
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
return [
|
||||
'system' => [
|
||||
'default' => [
|
||||
'web' => [
|
||||
'test' => [
|
||||
'test_value_2' => 'value2.local_config.default.test',
|
||||
],
|
||||
'test2' => [
|
||||
'test_value_3' => 'value3.local_config.default.test',
|
||||
'test_value_4' => 'value4.local_config.default.test',
|
||||
],
|
||||
]
|
||||
],
|
||||
'websites' => [
|
||||
'base' => [
|
||||
'web' => [
|
||||
'test' => [
|
||||
'test_value_2' => 'value2.local_config.website_base.test',
|
||||
],
|
||||
'test2' => [
|
||||
'test_value_3' => 'value3.local_config.website_base.test',
|
||||
'test_value_4' => 'value4.local_config.website_base.test',
|
||||
],
|
||||
],
|
||||
],
|
||||
'SecondWebsite' => [
|
||||
'camelCase' => [
|
||||
'UPPERCASE' => [
|
||||
'snake_case' => '',
|
||||
]
|
||||
]
|
||||
],
|
||||
'THIRD_WEBSITE' => [
|
||||
'camelCase' => [
|
||||
'UPPERCASE' => [
|
||||
'snake_case' => 'local_config.website_third_website.test',
|
||||
]
|
||||
]
|
||||
],
|
||||
'fourthWebsite' => [
|
||||
'camelCase' => [
|
||||
'UPPERCASE' => [
|
||||
'snake_case' => 'local_config.website_fourthwebsite.test',
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'stores' => [
|
||||
'default' => [
|
||||
'web' => [
|
||||
'test' => [
|
||||
'test_value_2' => 'value2.local_config.store_default.test',
|
||||
],
|
||||
'test2' => [
|
||||
'test_value_3' => 'value3.local_config.store_default.test',
|
||||
'test_value_4' => 'value4.local_config.store_default.test',
|
||||
],
|
||||
],
|
||||
'camelCase' => [
|
||||
'UPPERCASE' => [
|
||||
'snake_case' => 'local_config.store_default.test'
|
||||
]
|
||||
]
|
||||
],
|
||||
'SecondStore' => [
|
||||
'camelCase' => [
|
||||
'UPPERCASE' => [
|
||||
'snake_case' => 'local_config.store_secondstore.test',
|
||||
]
|
||||
]
|
||||
],
|
||||
'THIRD_STORE' => [
|
||||
'camelCase' => [
|
||||
'UPPERCASE' => [
|
||||
'snake_case' => '',
|
||||
]
|
||||
]
|
||||
],
|
||||
'fourthStore' => [
|
||||
'camelCase' => [
|
||||
'UPPERCASE' => [
|
||||
'snake_case' => 'local_config.store_fourthstore.test',
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Config\Model\Config\Factory;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$configData = [
|
||||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT => [
|
||||
'' => [
|
||||
'web/test/test_value_1' => 'value1.db.default.test',
|
||||
'web/test/test_value_2' => 'value2.db.default.test',
|
||||
'web/test2/test_value_3' => 'value3.db.default.test',
|
||||
'web/test2/test_value_4' => 'value4.db.default.test',
|
||||
'carriers/fedex/account' => 'value5.db.hashed.value',
|
||||
'paypal/fetch_reports/ftp_password' => 'value6.db.hashed.value',
|
||||
]
|
||||
],
|
||||
ScopeInterface::SCOPE_WEBSITES => [
|
||||
'base' => [
|
||||
'web/test/test_value_1' => 'value1.db.website_base.test',
|
||||
'web/test/test_value_2' => 'value2.db.website_base.test',
|
||||
'web/test2/test_value_3' => 'value3.db.website_base.test',
|
||||
'web/test2/test_value_4' => 'value4.db.website_base.test',
|
||||
]
|
||||
],
|
||||
ScopeInterface::SCOPE_STORES => [
|
||||
'default' => [
|
||||
'web/test/test_value_1' => 'value1.db.store_default.test',
|
||||
'web/test/test_value_2' => 'value2.db.store_default.test',
|
||||
'web/test2/test_value_3' => 'value3.db.store_default.test',
|
||||
'web/test2/test_value_4' => 'value4.db.store_default.test',
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Factory $configFactory */
|
||||
$configFactory = $objectManager->create(Factory::class);
|
||||
|
||||
foreach ($configData as $scope => $data) {
|
||||
foreach ($data as $scopeCode => $scopeData) {
|
||||
foreach ($scopeData as $path => $value) {
|
||||
$config = $configFactory->create();
|
||||
$config->setScope($scope);
|
||||
|
||||
if ($scope == ScopeInterface::SCOPE_WEBSITES) {
|
||||
$config->setWebsite($scopeCode);
|
||||
}
|
||||
|
||||
if ($scope == ScopeInterface::SCOPE_STORES) {
|
||||
$config->setStore($scopeCode);
|
||||
}
|
||||
|
||||
$config->setDataByPath($path, $value);
|
||||
$config->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
return [
|
||||
'backend' => [
|
||||
'frontName' => 'admin',
|
||||
],
|
||||
'crypt' => [
|
||||
'key' => 'some_key',
|
||||
],
|
||||
'session' => [
|
||||
'save' => 'files',
|
||||
],
|
||||
'db' => [
|
||||
'table_prefix' => '',
|
||||
'connection' => [],
|
||||
],
|
||||
'resource' => [],
|
||||
'x-frame-options' => 'SAMEORIGIN',
|
||||
'MAGE_MODE' => 'default',
|
||||
'cache_types' => [
|
||||
'config' => 1,
|
||||
'layout' => 1,
|
||||
'block_html' => 1,
|
||||
'collections' => 1,
|
||||
'reflection' => 1,
|
||||
'db_ddl' => 1,
|
||||
'eav' => 1,
|
||||
'customer_notification' => 1,
|
||||
'config_integration' => 1,
|
||||
'config_integration_api' => 1,
|
||||
'full_page' => 1,
|
||||
'translate' => 1,
|
||||
'config_webservice' => 1,
|
||||
],
|
||||
'install' => [
|
||||
'date' => 'Thu, 09 Feb 2017 14:28:00 +0000',
|
||||
],
|
||||
'system' => [
|
||||
'default' => [
|
||||
'web' => [
|
||||
'test2' => [
|
||||
'test_value_3' => 'value3.config.default.test',
|
||||
'test_value_4' => 'value4.config.default.test',
|
||||
],
|
||||
],
|
||||
],
|
||||
'websites' => [
|
||||
'base' => [
|
||||
'web' => [
|
||||
'test2' => [
|
||||
'test_value_3' => 'value3.config.website_base.test',
|
||||
'test_value_4' => 'value4.config.website_base.test',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'stores' => [
|
||||
'default' => [
|
||||
'web' => [
|
||||
'test2' => [
|
||||
'test_value_3' => 'value3.config.store_default.test',
|
||||
'test_value_4' => 'value4.config.store_default.test',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||
<system>
|
||||
<section id="general">
|
||||
<group id="group">
|
||||
<group id="subgroup">
|
||||
<field id="field" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
|
||||
<label>Label</label>
|
||||
</field>
|
||||
<field id="second_field" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
|
||||
<label>Label Second</label>
|
||||
<config_path>custom/config_path/second_field</config_path>
|
||||
</field>
|
||||
</group>
|
||||
</group>
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
Reference in New Issue
Block a user