Skip to content

Commit 0a86722

Browse files
committed
Merge remote-tracking branch 'falcon/MAGETWO-69854' into falcons-pr-bugfixes-2
2 parents 7019f99 + a9273b9 commit 0a86722

File tree

12 files changed

+267
-248
lines changed

12 files changed

+267
-248
lines changed

app/code/Magento/Config/Console/Command/ConfigSet/ConfigSetProcessorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface ConfigSetProcessorInterface
2020
/**
2121
* Processes config:set command.
2222
*
23-
* @param string $path The configuration path in format section/group/field_name
23+
* @param string $path The configuration path in format group/section/field_name
2424
* @param string $value The configuration value
2525
* @param string $scope The configuration scope (default, website, or store)
2626
* @param string $scopeCode The scope code

app/code/Magento/Config/Console/Command/ConfigSet/ProcessorFacade.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Config\Console\Command\ConfigSet;
77

88
use Magento\Config\Console\Command\ConfigSetCommand;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
910
use Magento\Framework\App\Scope\ValidatorInterface;
1011
use Magento\Config\Model\Config\PathValidator;
1112
use Magento\Framework\Exception\LocalizedException;
@@ -14,6 +15,7 @@
1415
use Magento\Framework\Exception\ValidatorException;
1516
use Magento\Deploy\Model\DeploymentConfig\Hash;
1617
use Magento\Config\App\Config\Type\System;
18+
use Magento\Framework\App\Config;
1719

1820
/**
1921
* Processor facade for config:set command.
@@ -57,22 +59,32 @@ class ProcessorFacade
5759
*/
5860
private $hash;
5961

62+
/**
63+
* The application config storage.
64+
*
65+
* @var ScopeConfigInterface
66+
*/
67+
private $scopeConfig;
68+
6069
/**
6170
* @param ValidatorInterface $scopeValidator The scope validator
6271
* @param PathValidator $pathValidator The path validator
6372
* @param ConfigSetProcessorFactory $configSetProcessorFactory The factory for config:set processors
6473
* @param Hash $hash The hash manager
74+
* @param ScopeConfigInterface $scopeConfig The application config storage
6575
*/
6676
public function __construct(
6777
ValidatorInterface $scopeValidator,
6878
PathValidator $pathValidator,
6979
ConfigSetProcessorFactory $configSetProcessorFactory,
70-
Hash $hash
80+
Hash $hash,
81+
ScopeConfigInterface $scopeConfig
7182
) {
7283
$this->scopeValidator = $scopeValidator;
7384
$this->pathValidator = $pathValidator;
7485
$this->configSetProcessorFactory = $configSetProcessorFactory;
7586
$this->hash = $hash;
87+
$this->scopeConfig = $scopeConfig;
7688
}
7789

7890
/**
@@ -109,6 +121,10 @@ public function process($path, $value, $scope, $scopeCode, $lock)
109121

110122
$this->hash->regenerate(System::CONFIG_TYPE);
111123

124+
if ($this->scopeConfig instanceof Config) {
125+
$this->scopeConfig->clean();
126+
}
127+
112128
return $message;
113129
}
114130
}

app/code/Magento/Config/Model/Config/Backend/Currency/AbstractCurrency.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class AbstractCurrency extends \Magento\Framework\App\Config\Value
2525
*/
2626
protected function _getAllowedCurrencies()
2727
{
28-
if ($this->getData('groups/options/fields/allow/inherit')) {
28+
if (!$this->isFormData() || $this->getData('groups/options/fields/allow/inherit')) {
2929
return explode(
3030
',',
3131
(string)$this->_config->getValue(
@@ -62,7 +62,8 @@ protected function _getInstalledCurrencies()
6262
*/
6363
protected function _getCurrencyBase()
6464
{
65-
if (!($value = $this->getData('groups/options/fields/base/value'))) {
65+
$value = $this->getData('groups/options/fields/base/value');
66+
if (!$this->isFormData() || !$value) {
6667
$value = $this->_config->getValue(
6768
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
6869
$this->getScope(),
@@ -79,7 +80,7 @@ protected function _getCurrencyBase()
7980
*/
8081
protected function _getCurrencyDefault()
8182
{
82-
if (!($value = $this->getData('groups/options/fields/default/value'))) {
83+
if (!$this->isFormData() || !($value = $this->getData('groups/options/fields/default/value'))) {
8384
$value = $this->_config->getValue(
8485
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT,
8586
$this->getScope(),
@@ -88,4 +89,14 @@ protected function _getCurrencyDefault()
8889
}
8990
return strval($value);
9091
}
92+
93+
/**
94+
* Check whether field saved from Admin form with other currency data or as single field, e.g. from CLI command
95+
*
96+
* @return bool True in case when field was saved from Admin form
97+
*/
98+
private function isFormData()
99+
{
100+
return $this->getData('groups/options/fields') !== null;
101+
}
91102
}

app/code/Magento/Config/Model/Config/Backend/Currency/Allow.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public function __construct(
5454
public function afterSave()
5555
{
5656
$exceptions = [];
57-
foreach ($this->_getAllowedCurrencies() as $currencyCode) {
57+
$allowedCurrencies = $this->_getAllowedCurrencies();
58+
foreach ($allowedCurrencies as $currencyCode) {
5859
if (!in_array($currencyCode, $this->_getInstalledCurrencies())) {
5960
$exceptions[] = __(
6061
'Selected allowed currency "%1" is not available in installed currencies.',
@@ -63,7 +64,7 @@ public function afterSave()
6364
}
6465
}
6566

66-
if (!in_array($this->_getCurrencyDefault(), $this->_getAllowedCurrencies())) {
67+
if (!in_array($this->_getCurrencyDefault(), $allowedCurrencies)) {
6768
$exceptions[] = __(
6869
'Default display currency "%1" is not available in allowed currencies.',
6970
$this->_localeCurrency->getCurrency($this->_getCurrencyDefault())->getName()
@@ -76,4 +77,22 @@ public function afterSave()
7677

7778
return parent::afterSave();
7879
}
80+
81+
/**
82+
* @inheritdoc
83+
*/
84+
protected function _getAllowedCurrencies()
85+
{
86+
$value = $this->getValue();
87+
$isFormData = $this->getData('groups/options/fields') !== null;
88+
if ($isFormData && $this->getData('groups/options/fields/allow/inherit')) {
89+
$value = (string)$this->_config->getValue(
90+
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW,
91+
$this->getScope(),
92+
$this->getScopeId()
93+
);
94+
}
95+
96+
return explode(',', $value);
97+
}
7998
}

app/code/Magento/Config/Model/Config/Importer/SaveProcessor.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
namespace Magento\Config\Model\Config\Importer;
77

8-
use Magento\Config\Model\Config\Backend\Currency\AbstractCurrency;
98
use Magento\Config\Model\PreparedValueFactory;
10-
use Magento\Directory\Model\Currency;
119
use Magento\Framework\App\Config\ScopeConfigInterface;
1210
use Magento\Framework\App\Config\Value;
1311
use Magento\Framework\Stdlib\ArrayUtils;
@@ -103,41 +101,9 @@ private function invokeSave(array $scopeData, $scope, $scopeCode = null)
103101
$backendModel = $this->valueFactory->create($path, $value, $scope, $scopeCode);
104102

105103
if ($backendModel instanceof Value) {
106-
$this->setAdditionalData($backendModel);
107104
$backendModel->beforeSave();
108105
$backendModel->afterSave();
109106
}
110107
}
111108
}
112-
113-
/**
114-
* Adds additional data to backendModel if needed.
115-
*
116-
* Additional data, such as groups is coming within form request.
117-
* There is no possibility to retrieve this data separately, so
118-
* this emulation should be performed to preserve backward compatibility.
119-
*
120-
* @param Value $backendModel Instance of Value
121-
* @return void
122-
*/
123-
private function setAdditionalData(Value $backendModel)
124-
{
125-
// sets allowed currencies before save base or default currency value
126-
if ($backendModel instanceof AbstractCurrency) {
127-
$allowedCurrencies = $this->scopeConfig->getValue(
128-
Currency::XML_PATH_CURRENCY_ALLOW,
129-
$backendModel->getScope(),
130-
$backendModel->getScopeId()
131-
);
132-
$backendModel->addData([
133-
'groups' => [
134-
'options' => [
135-
'fields' => [
136-
'allow' => ['value' => explode(',', $allowedCurrencies)]
137-
]
138-
]
139-
]
140-
]);
141-
}
142-
}
143109
}

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ProcessorFacadeTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
use Magento\Framework\Exception\ConfigurationMismatchException;
1818
use Magento\Deploy\Model\DeploymentConfig\Hash;
1919
use Magento\Config\App\Config\Type\System;
20+
use Magento\Framework\App\Config;
2021
use PHPUnit_Framework_MockObject_MockObject as Mock;
2122

2223
/**
2324
* Test for ProcessorFacade.
2425
*
2526
* @see ProcessorFacade
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628
*/
2729
class ProcessorFacadeTest extends \PHPUnit_Framework_TestCase
2830
{
@@ -56,6 +58,11 @@ class ProcessorFacadeTest extends \PHPUnit_Framework_TestCase
5658
*/
5759
private $hashMock;
5860

61+
/**
62+
* @var Config|Mock
63+
*/
64+
private $configMock;
65+
5966
/**
6067
* @inheritdoc
6168
*/
@@ -79,12 +86,16 @@ protected function setUp()
7986
$this->hashMock = $this->getMockBuilder(Hash::class)
8087
->disableOriginalConstructor()
8188
->getMock();
89+
$this->configMock = $this->getMockBuilder(Config::class)
90+
->disableOriginalConstructor()
91+
->getMock();
8292

8393
$this->model = new ProcessorFacade(
8494
$this->scopeValidatorMock,
8595
$this->pathValidatorMock,
8696
$this->configSetProcessorFactoryMock,
87-
$this->hashMock
97+
$this->hashMock,
98+
$this->configMock
8899
);
89100
}
90101

@@ -106,6 +117,8 @@ public function testProcess()
106117
$this->hashMock->expects($this->once())
107118
->method('regenerate')
108119
->with(System::CONFIG_TYPE);
120+
$this->configMock->expects($this->once())
121+
->method('clean');
109122

110123
$this->assertSame(
111124
'Value was saved.',
@@ -156,6 +169,8 @@ public function testProcessWithConfigurationMismatchException()
156169
->willThrowException(new ConfigurationMismatchException(__('Some error')));
157170
$this->processorMock->expects($this->never())
158171
->method('process');
172+
$this->configMock->expects($this->never())
173+
->method('clean');
159174

160175
$this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, false);
161176
}
@@ -180,6 +195,8 @@ public function testProcessWithCouldNotSaveException()
180195
->method('process')
181196
->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)
182197
->willThrowException(new CouldNotSaveException(__('Some error')));
198+
$this->configMock->expects($this->never())
199+
->method('clean');
183200

184201
$this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, false);
185202
}
@@ -196,6 +213,8 @@ public function testExecuteLock()
196213
$this->processorMock->expects($this->once())
197214
->method('process')
198215
->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
216+
$this->configMock->expects($this->once())
217+
->method('clean');
199218

200219
$this->assertSame(
201220
'Value was saved and locked.',

app/code/Magento/Config/Test/Unit/Model/Config/Importer/SaveProcessorTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function setUp()
6767
->getMock();
6868
$this->currencyValueMock = $this->getMockBuilder(Base::class)
6969
->disableOriginalConstructor()
70-
->setMethods(['getScope', 'getScopeId', 'beforeSave', 'afterSave', 'addData'])
70+
->setMethods(['beforeSave', 'afterSave'])
7171
->getMock();
7272
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
7373
->getMockForAbstractClass();
@@ -97,15 +97,6 @@ public function testProcess()
9797
$value1 = clone $this->valueMock;
9898
$value2 = clone $this->valueMock;
9999

100-
$this->currencyValueMock->expects($this->once())
101-
->method('getScope')
102-
->willReturn('default');
103-
$this->currencyValueMock->expects($this->once())
104-
->method('getScopeId')
105-
->willReturn(null);
106-
$this->currencyValueMock->expects($this->once())
107-
->method('addData')
108-
->with(['groups' => ['options' => ['fields' => ['allow' => ['value' => ['EUR', 'USD']]]]]]);
109100
$this->arrayUtilsMock->expects($this->exactly(2))
110101
->method('flatten')
111102
->willReturnMap([
@@ -128,12 +119,11 @@ public function testProcess()
128119
['web/unsecure/base_url' => 'http://magento3.local/']
129120
]
130121
]);
131-
$this->scopeConfigMock->expects($this->exactly(4))
122+
$this->scopeConfigMock->expects($this->exactly(3))
132123
->method('getValue')
133124
->willReturnMap([
134125
['web/unsecure/base_url', 'default', null, 'http://magento2.local/'],
135126
['currency/options/base', 'default', null, 'EUR'],
136-
['currency/options/allow', 'default', null, 'EUR,USD'],
137127
['web/unsecure/base_url', 'websites', 'base', 'http://magento3.local/']
138128
]);
139129
$this->valueFactoryMock->expects($this->exactly(3))

app/code/Magento/CurrencySymbol/Observer/CurrencyDisplayOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
3333
{
3434
$baseCode = $observer->getEvent()->getBaseCode();
3535
$currencyOptions = $observer->getEvent()->getCurrencyOptions();
36-
$currencyOptions->setData($this->getCurrencyOptions($baseCode));
36+
$currencyOptions->addData($this->getCurrencyOptions($baseCode));
3737

3838
return $this;
3939
}

app/code/Magento/CurrencySymbol/Test/Unit/Observer/CurrencyDisplayOptionsTest.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ protected function setUp()
7979

8080
public function testCurrencyDisplayOptionsEmpty()
8181
{
82-
$sampleCurrencyOptionObject = new \Magento\Framework\DataObject;
82+
$baseData = [
83+
\Magento\Framework\Locale\Currency::CURRENCY_OPTION_NAME => 'US Dollar'
84+
];
85+
$sampleCurrencyOptionObject = new \Magento\Framework\DataObject($baseData);
8386
//Return invalid value
8487
$this->mockEvent->expects($this->once())->method('getBaseCode')->willReturn(null);
8588
$this->mockEvent->expects($this->once())->method('getCurrencyOptions')->willReturn($sampleCurrencyOptionObject);
@@ -88,21 +91,27 @@ public function testCurrencyDisplayOptionsEmpty()
8891
$this->observer->execute($this->mockEventObserver);
8992

9093
// Check if option set is empty
91-
$this->assertEquals([], $sampleCurrencyOptionObject->getData());
94+
$this->assertEquals($baseData, $sampleCurrencyOptionObject->getData());
9295
}
9396

9497
public function testCurrencyDisplayOptions()
9598
{
96-
$sampleCurrencyOptionObject = new \Magento\Framework\DataObject;
99+
$baseData = [
100+
\Magento\Framework\Locale\Currency::CURRENCY_OPTION_NAME => 'US Dollar'
101+
];
102+
$sampleCurrencyOptionObject = new \Magento\Framework\DataObject($baseData);
97103
$sampleCurrency = 'USD';
98104
$sampleCurrencySymbol = '$';
99105

100-
$expectedCurrencyOptions = [
101-
\Magento\Framework\Locale\Currency::CURRENCY_OPTION_SYMBOL => $sampleCurrencySymbol,
102-
\Magento\Framework\Locale\Currency::CURRENCY_OPTION_DISPLAY => \Magento\Framework\Currency::USE_SYMBOL
103-
];
106+
$expectedCurrencyOptions = array_merge(
107+
$baseData,
108+
[
109+
\Magento\Framework\Locale\Currency::CURRENCY_OPTION_NAME => 'US Dollar',
110+
\Magento\Framework\Locale\Currency::CURRENCY_OPTION_SYMBOL => $sampleCurrencySymbol,
111+
\Magento\Framework\Locale\Currency::CURRENCY_OPTION_DISPLAY => \Magento\Framework\Currency::USE_SYMBOL
112+
]
113+
);
104114

105-
//Return invalid value
106115
$this->mockEvent->expects($this->once())->method('getBaseCode')->willReturn($sampleCurrency);
107116
$this->mockEvent->expects($this->once())->method('getCurrencyOptions')->willReturn($sampleCurrencyOptionObject);
108117
$this->mockSymbol->expects($this->once())
@@ -112,7 +121,6 @@ public function testCurrencyDisplayOptions()
112121

113122
$this->observer->execute($this->mockEventObserver);
114123

115-
// Check if option set is empty
116124
$this->assertEquals($expectedCurrencyOptions, $sampleCurrencyOptionObject->getData());
117125
}
118126
}

0 commit comments

Comments
 (0)