Skip to content

Commit 6df7cc3

Browse files
MAGETWO-69430: Magento allows to save not valid data using config:set command
1 parent bbbdcf7 commit 6df7cc3

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,13 @@ public function process($path, $value, $scope, $scopeCode)
8181
$backendModel = $this->preparedValueFactory->create($path, $value, $scope, $scopeCode);
8282

8383
if ($backendModel instanceof Value) {
84-
/**
85-
* Temporary solution until Magento introduce unified interface
86-
* for storing system configuration into database and configuration files.
87-
*/
88-
$backendModel->validateBeforeSave();
89-
$backendModel->beforeSave();
84+
$resourceModel = $backendModel->getResource();
85+
$resourceModel->save($backendModel);
9086

9187
$value = $backendModel->getValue();
9288

93-
$backendModel->afterSave();
94-
95-
/**
96-
* Because FS does not support transactions,
97-
* we'll write value just after all validations are triggered.
98-
*/
9989
$this->deploymentConfigWriter->saveConfig(
100-
[ConfigFilePool::APP_ENV => $this->arrayManager->set($configPath, [], $value)],
101-
false
90+
[ConfigFilePool::APP_ENV => $this->arrayManager->set($configPath, [], $value)]
10291
);
10392
}
10493
} catch (\Exception $exception) {

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\App\DeploymentConfig;
1414
use Magento\Framework\Config\File\ConfigFilePool;
1515
use Magento\Framework\Exception\FileSystemException;
16+
use Magento\Framework\Model\ResourceModel\AbstractResource;
1617
use Magento\Framework\Stdlib\ArrayManager;
1718
use Magento\Store\Model\ScopeInterface;
1819
use PHPUnit_Framework_MockObject_MockObject as Mock;
@@ -55,6 +56,11 @@ class LockProcessorTest extends \PHPUnit_Framework_TestCase
5556
*/
5657
private $valueMock;
5758

59+
/**
60+
* @var AbstractResource|Mock
61+
*/
62+
private $resourceMock;
63+
5864
/**
5965
* @inheritdoc
6066
*/
@@ -73,9 +79,13 @@ protected function setUp()
7379
->disableOriginalConstructor()
7480
->getMock();
7581
$this->valueMock = $this->getMockBuilder(Value::class)
76-
->setMethods(['validateBeforeSave', 'beforeSave', 'setValue', 'getValue', 'afterSave'])
82+
->setMethods(['save', 'getResource', 'setValue', 'getValue', 'afterSave'])
7783
->disableOriginalConstructor()
7884
->getMock();
85+
$this->resourceMock = $this->getMockBuilder(AbstractResource::class)
86+
->setMethods(['save'])
87+
->disableOriginalConstructor()
88+
->getMockForAbstractClass();
7989

8090
$this->model = new LockProcessor(
8191
$this->preparedValueFactory,
@@ -120,6 +130,12 @@ public function testProcess($path, $value, $scope, $scopeCode)
120130
$this->valueMock->expects($this->once())
121131
->method('getValue')
122132
->willReturn($value);
133+
$this->valueMock->expects($this->once())
134+
->method('getResource')
135+
->willReturn($this->resourceMock);
136+
$this->resourceMock->expects($this->once())
137+
->method('save')
138+
->with($this->valueMock);
123139
$this->deploymentConfigWriterMock->expects($this->once())
124140
->method('saveConfig')
125141
->with(
@@ -138,12 +154,6 @@ public function testProcess($path, $value, $scope, $scopeCode)
138154
],
139155
false
140156
);
141-
$this->valueMock->expects($this->once())
142-
->method('validateBeforeSave');
143-
$this->valueMock->expects($this->once())
144-
->method('beforeSave');
145-
$this->valueMock->expects($this->once())
146-
->method('afterSave');
147157

148158
$this->model->process($path, $value, $scope, $scopeCode);
149159
}
@@ -175,6 +185,12 @@ public function testProcessNotReadableFs()
175185
$this->valueMock->expects($this->once())
176186
->method('getValue')
177187
->willReturn($value);
188+
$this->valueMock->expects($this->once())
189+
->method('getResource')
190+
->willReturn($this->resourceMock);
191+
$this->resourceMock->expects($this->once())
192+
->method('save')
193+
->with($this->valueMock);
178194
$this->configPathResolver->expects($this->once())
179195
->method('resolve')
180196
->willReturn('system/default/test/test/test');
@@ -207,9 +223,10 @@ public function testCustomException()
207223
$this->arrayManagerMock->expects($this->never())
208224
->method('set');
209225
$this->valueMock->expects($this->once())
210-
->method('getValue');
211-
$this->valueMock->expects($this->once())
212-
->method('afterSave')
226+
->method('getResource')
227+
->willReturn($this->resourceMock);
228+
$this->resourceMock->expects($this->once())
229+
->method('save')
213230
->willThrowException(new \Exception('Invalid values'));
214231
$this->deploymentConfigWriterMock->expects($this->never())
215232
->method('saveConfig');

0 commit comments

Comments
 (0)