@@ -60,6 +60,11 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
60
60
*/
61
61
protected $ _configStructure ;
62
62
63
+ /**
64
+ * @var \PHPUnit_Framework_MockObject_MockObject
65
+ */
66
+ private $ _settingsChecker ;
67
+
63
68
protected function setUp ()
64
69
{
65
70
$ this ->_eventManagerMock = $ this ->createMock (\Magento \Framework \Event \ManagerInterface::class);
@@ -79,7 +84,7 @@ protected function setUp()
79
84
80
85
$ this ->_transFactoryMock = $ this ->createPartialMock (
81
86
\Magento \Framework \DB \TransactionFactory::class,
82
- ['create ' ]
87
+ ['create ' , ' addObject ' ]
83
88
);
84
89
$ this ->_appConfigMock = $ this ->createMock (\Magento \Framework \App \Config \ReinitableConfigInterface::class);
85
90
$ this ->_configLoaderMock = $ this ->createPartialMock (
@@ -90,14 +95,18 @@ protected function setUp()
90
95
91
96
$ this ->_storeManager = $ this ->getMockForAbstractClass (\Magento \Store \Model \StoreManagerInterface::class);
92
97
98
+ $ this ->_settingsChecker = $ this
99
+ ->createMock (\Magento \Config \Model \Config \Reader \Source \Deployed \SettingChecker::class);
100
+
93
101
$ this ->_model = new \Magento \Config \Model \Config (
94
102
$ this ->_appConfigMock ,
95
103
$ this ->_eventManagerMock ,
96
104
$ this ->_configStructure ,
97
105
$ this ->_transFactoryMock ,
98
106
$ this ->_configLoaderMock ,
99
107
$ this ->_dataFactoryMock ,
100
- $ this ->_storeManager
108
+ $ this ->_storeManager ,
109
+ $ this ->_settingsChecker
101
110
);
102
111
}
103
112
@@ -149,6 +158,49 @@ public function testSaveToCheckAdminSystemConfigChangedSectionEvent()
149
158
$ this ->_model ->save ();
150
159
}
151
160
161
+ public function testDoNotSaveReadOnlyFields ()
162
+ {
163
+ $ transactionMock = $ this ->createMock (\Magento \Framework \DB \Transaction::class);
164
+ $ this ->_transFactoryMock ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ transactionMock ));
165
+
166
+ $ this ->_settingsChecker ->expects ($ this ->any ())->method ('isReadOnly ' )->will ($ this ->returnValue (true ));
167
+ $ this ->_configLoaderMock ->expects ($ this ->any ())->method ('getConfigByPath ' )->will ($ this ->returnValue ([]));
168
+
169
+ $ this ->_model ->setGroups (['1 ' => ['fields ' => ['key ' => ['data ' ]]]]);
170
+ $ this ->_model ->setSection ('section ' );
171
+
172
+ $ group = $ this ->createMock (\Magento \Config \Model \Config \Structure \Element \Group::class);
173
+ $ group ->method ('getPath ' )->willReturn ('section/1 ' );
174
+
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 ' );
178
+
179
+ $ this ->_configStructure ->expects ($ this ->at (0 ))
180
+ ->method ('getElement ' )
181
+ ->with ('section/1 ' )
182
+ ->will ($ this ->returnValue ($ group ));
183
+ $ this ->_configStructure ->expects ($ this ->at (1 ))
184
+ ->method ('getElement ' )
185
+ ->with ('section/1 ' )
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 ));
191
+
192
+ $ backendModel = $ this ->createPartialMock (
193
+ \Magento \Framework \App \Config \Value::class,
194
+ ['addData ' ]
195
+ );
196
+ $ this ->_dataFactoryMock ->expects ($ this ->any ())->method ('create ' )->will ($ this ->returnValue ($ backendModel ));
197
+
198
+ $ this ->_transFactoryMock ->expects ($ this ->never ())->method ('addObject ' );
199
+ $ backendModel ->expects ($ this ->never ())->method ('addData ' );
200
+
201
+ $ this ->_model ->save ();
202
+ }
203
+
152
204
public function testSaveToCheckScopeDataSet ()
153
205
{
154
206
$ transactionMock = $ this ->createMock (\Magento \Framework \DB \Transaction::class);
0 commit comments