66 private $_settingsChecker;
70 $this->_eventManagerMock = $this->createMock(\
Magento\Framework\Event\ManagerInterface::class);
71 $this->_structureReaderMock = $this->createPartialMock(
75 $this->_configStructure = $this->createMock(\
Magento\Config\Model\Config\Structure::class);
77 $this->_structureReaderMock->expects(
82 $this->returnValue($this->_configStructure)
85 $this->_transFactoryMock = $this->createPartialMock(
86 \
Magento\Framework\DB\TransactionFactory::class,
87 [
'create',
'addObject']
89 $this->_appConfigMock = $this->createMock(\
Magento\Framework\
App\Config\ReinitableConfigInterface::class);
90 $this->_configLoaderMock = $this->createPartialMock(
91 \
Magento\Config\Model\Config\Loader::class,
94 $this->_dataFactoryMock = $this->createMock(\
Magento\Framework\
App\Config\ValueFactory::class);
96 $this->_storeManager = $this->getMockForAbstractClass(\
Magento\Store\Model\StoreManagerInterface::class);
98 $this->_settingsChecker = $this
99 ->createMock(\
Magento\Config\Model\Config\
Reader\Source\Deployed\SettingChecker::class);
101 $this->_model = new \Magento\Config\Model\Config(
102 $this->_appConfigMock,
103 $this->_eventManagerMock,
104 $this->_configStructure,
105 $this->_transFactoryMock,
106 $this->_configLoaderMock,
107 $this->_dataFactoryMock,
108 $this->_storeManager,
109 $this->_settingsChecker
115 $this->_configLoaderMock->expects($this->never())->method(
'getConfigByPath');
116 $this->_model->save();
121 $this->_structureReaderMock->expects($this->never())->method(
'getConfiguration');
122 $this->assertNull($this->_model->getSection());
123 $this->assertNull($this->_model->getWebsite());
124 $this->assertNull($this->_model->getStore());
125 $this->_model->save();
126 $this->assertSame(
'', $this->_model->getSection());
127 $this->assertSame(
'', $this->_model->getWebsite());
128 $this->assertSame(
'', $this->_model->getStore());
133 $transactionMock = $this->createMock(\
Magento\Framework\DB\Transaction::class);
135 $this->_transFactoryMock->expects($this->any())->method(
'create')->will($this->returnValue($transactionMock));
137 $this->_configLoaderMock->expects($this->any())->method(
'getConfigByPath')->will($this->returnValue([]));
139 $this->_eventManagerMock->expects(
144 $this->equalTo(
'admin_system_config_changed_section_'),
145 $this->arrayHasKey(
'website')
148 $this->_eventManagerMock->expects(
153 $this->equalTo(
'admin_system_config_changed_section_'),
154 $this->arrayHasKey(
'store')
157 $this->_model->setGroups([
'1' => [
'data']]);
158 $this->_model->save();
163 $transactionMock = $this->createMock(\
Magento\Framework\DB\Transaction::class);
164 $this->_transFactoryMock->expects($this->any())->method(
'create')->will($this->returnValue($transactionMock));
166 $this->_settingsChecker->expects($this->any())->method(
'isReadOnly')->will($this->returnValue(
true));
167 $this->_configLoaderMock->expects($this->any())->method(
'getConfigByPath')->will($this->returnValue([]));
169 $this->_model->setGroups([
'1' => [
'fields' => [
'key' => [
'data']]]]);
170 $this->_model->setSection(
'section');
173 $group->method(
'getPath')->willReturn(
'section/1');
175 $field = $this->createMock(\
Magento\Config\Model\Config\
Structure\Element\Field::class);
176 $field->method(
'getGroupPath')->willReturn(
'section/1');
177 $field->method(
'getId')->willReturn(
'key');
179 $this->_configStructure->expects($this->at(0))
180 ->method(
'getElement')
182 ->will($this->returnValue(
$group));
183 $this->_configStructure->expects($this->at(1))
184 ->method(
'getElement')
186 ->will($this->returnValue(
$group));
187 $this->_configStructure->expects($this->at(2))
188 ->method(
'getElement')
189 ->with(
'section/1/key')
190 ->will($this->returnValue($field));
192 $backendModel = $this->createPartialMock(
196 $this->_dataFactoryMock->expects($this->any())->method(
'create')->will($this->returnValue($backendModel));
198 $this->_transFactoryMock->expects($this->never())->method(
'addObject');
199 $backendModel->expects($this->never())->method(
'addData');
201 $this->_model->save();
206 $transactionMock = $this->createMock(\
Magento\Framework\DB\Transaction::class);
207 $this->_transFactoryMock->expects($this->any())->method(
'create')->will($this->returnValue($transactionMock));
209 $this->_configLoaderMock->expects($this->any())->method(
'getConfigByPath')->will($this->returnValue([]));
211 $this->_eventManagerMock->expects($this->at(0))
214 $this->equalTo(
'admin_system_config_changed_section_section'),
215 $this->arrayHasKey(
'website')
217 $this->_eventManagerMock->expects($this->at(0))
220 $this->equalTo(
'admin_system_config_changed_section_section'),
221 $this->arrayHasKey(
'store')
225 $group->method(
'getPath')->willReturn(
'section/1');
227 $field = $this->createMock(\
Magento\Config\Model\Config\
Structure\Element\Field::class);
228 $field->method(
'getGroupPath')->willReturn(
'section/1');
229 $field->method(
'getId')->willReturn(
'key');
231 $this->_configStructure->expects($this->at(0))
232 ->method(
'getElement')
234 ->will($this->returnValue(
$group));
235 $this->_configStructure->expects($this->at(1))
236 ->method(
'getElement')
238 ->will($this->returnValue(
$group));
239 $this->_configStructure->expects($this->at(2))
240 ->method(
'getElement')
241 ->with(
'section/1/key')
242 ->will($this->returnValue($field));
243 $this->_configStructure->expects($this->at(3))
244 ->method(
'getElement')
246 ->will($this->returnValue(
$group));
247 $this->_configStructure->expects($this->at(4))
248 ->method(
'getElement')
249 ->with(
'section/1/key')
250 ->will($this->returnValue($field));
253 $website->expects($this->any())->method(
'getCode')->will($this->returnValue(
'website_code'));
254 $this->_storeManager->expects($this->any())->method(
'getWebsite')->will($this->returnValue(
$website));
255 $this->_storeManager->expects($this->any())->method(
'getWebsites')->will($this->returnValue([
$website]));
256 $this->_storeManager->expects($this->any())->method(
'isSingleStoreMode')->will($this->returnValue(
true));
258 $this->_model->setWebsite(
'website');
259 $this->_model->setSection(
'section');
260 $this->_model->setGroups([
'1' => [
'fields' => [
'key' => [
'data']]]]);
262 $backendModel = $this->createPartialMock(
264 [
'setPath',
'addData',
'__sleep',
'__wakeup']
266 $backendModel->expects($this->once())
270 'groups' => [1 => [
'fields' => [
'key' => [
'data']]]],
272 'scope' =>
'websites',
274 'scope_code' =>
'website_code',
275 'field_config' =>
null,
276 'fieldset_data' => [
'key' =>
null],
278 $backendModel->expects($this->once())
280 ->with(
'section/1/key')
281 ->will($this->returnValue($backendModel));
283 $this->_dataFactoryMock->expects($this->any())->method(
'create')->will($this->returnValue($backendModel));
285 $this->_model->save();
291 $path =
'<section>/<group>/<field>';
294 'section' =>
'<section>',
298 '<field>' => [
'value' =>
$value],
303 $this->assertSame($expected, $this->_model->getData());
312 $this->_model->setDataByPath(
'',
'value');
323 $expectedException =
'Allowed depth of configuration is 3 (<section>/<group>/<field>). ' . $expectedException;
324 $this->expectException(
'\UnexpectedValueException');
325 $this->expectExceptionMessage($expectedException);
336 'depth 2' => [
'section/group',
"Your configuration depth is 2 for path 'section/group'"],
337 'depth 1' => [
'section',
"Your configuration depth is 1 for path 'section'"],
338 'depth 4' => [
'section/group/field/sub-field',
"Your configuration depth is 4 for path" 339 .
" 'section/group/field/sub-field'", ],
testSaveEmptiesNonSetArguments()
setDataByPathWrongDepthDataProvider()
testSaveToCheckAdminSystemConfigChangedSectionEvent()
testSaveToCheckScopeDataSet()
testSetDataByPathWrongDepth($path, $expectedException)
testDoNotSaveReadOnlyFields()
testSaveDoesNotDoAnythingIfGroupsAreNotPassed()