7
7
8
8
namespace Magento \Theme \Test \Unit \Model \Data \Design ;
9
9
10
+ use Magento \Config \Model \Config \Reader \Source \Deployed \SettingChecker ;
10
11
use Magento \Framework \App \ScopeValidatorInterface ;
11
12
use Magento \Store \Api \Data \WebsiteInterface ;
12
13
use Magento \Store \Model \StoreManagerInterface ;
@@ -52,6 +53,11 @@ class ConfigFactoryTest extends TestCase
52
53
/** @var WebsiteInterface|MockObject */
53
54
protected $ website ;
54
55
56
+ /**
57
+ * @var SettingChecker|MockObject
58
+ */
59
+ private $ settingChecker ;
60
+
55
61
protected function setUp (): void
56
62
{
57
63
$ this ->designConfigFactory = $ this ->createPartialMock (
@@ -99,14 +105,18 @@ protected function setUp(): void
99
105
->getMockForAbstractClass ();
100
106
$ this ->website = $ this ->getMockBuilder (WebsiteInterface::class)
101
107
->getMockForAbstractClass ();
108
+ $ this ->settingChecker = $ this ->getMockBuilder (SettingChecker::class)
109
+ ->disableOriginalConstructor ()
110
+ ->getMock ();
102
111
103
112
$ this ->factory = new ConfigFactory (
104
113
$ this ->designConfigFactory ,
105
114
$ this ->metadataProvider ,
106
115
$ this ->designConfigDataFactory ,
107
116
$ this ->configExtensionFactory ,
108
117
$ this ->scopeValidator ,
109
- $ this ->storeManager
118
+ $ this ->storeManager ,
119
+ $ this ->settingChecker
110
120
);
111
121
}
112
122
@@ -158,14 +168,18 @@ public function testCreate()
158
168
return null ;
159
169
}
160
170
});
161
- $ this ->designConfigData ->expects ($ this ->exactly (2 ))
162
- ->method ('setFieldConfig ' )
163
- ->willReturnCallback (function ($ config ) {
164
- if ($ config ['path ' ] == 'design/header/default_title ' ||
165
- $ config ['path ' ]== 'design/head/default_description ' ) {
166
- return null ;
167
- }
168
- });
171
+ $ this ->designConfigData ->expects ($ this ->exactly (2 ))
172
+ ->method ('setFieldConfig ' )
173
+ ->willReturnCallback (function ($ config ) {
174
+ if ($ config ['path ' ] == 'design/header/default_title ' ||
175
+ $ config ['path ' ] == 'design/head/default_description ' ) {
176
+ return null ;
177
+ }
178
+ });
179
+ $ this ->settingChecker ->expects ($ this ->once ())
180
+ ->method ('isReadOnly ' )
181
+ ->with ('design/header/default_title ' , 'default ' , 0 )
182
+ ->willReturn (false );
169
183
$ this ->designConfigData ->expects ($ this ->once ())
170
184
->method ('setValue ' )
171
185
->with ('value ' );
@@ -242,6 +256,10 @@ public function testCreateInSingleStoreMode()
242
256
return null ;
243
257
}
244
258
});
259
+ $ this ->settingChecker ->expects ($ this ->once ())
260
+ ->method ('isReadOnly ' )
261
+ ->with ('design/header/default_title ' , 'default ' , 0 )
262
+ ->willReturn (false );
245
263
$ this ->designConfigData ->expects ($ this ->once ())
246
264
->method ('setValue ' )
247
265
->with ('value ' );
@@ -256,4 +274,80 @@ public function testCreateInSingleStoreMode()
256
274
->with ($ this ->designConfigExtension );
257
275
$ this ->assertSame ($ this ->designConfig , $ this ->factory ->create ($ scope , $ scopeId , $ data ));
258
276
}
277
+
278
+ public function testBypassSettingLockedConfig () {
279
+ $ scope = 'default ' ;
280
+ $ scopeId = 0 ;
281
+ $ data = [
282
+ 'header_default_title ' => 'value '
283
+ ];
284
+ $ metadata = [
285
+ 'header_default_title ' => [
286
+ 'path ' => 'design/header/default_title ' ,
287
+ 'fieldset ' => 'head '
288
+ ],
289
+ 'head_default_description ' => [
290
+ 'path ' => 'design/head/default_description ' ,
291
+ 'fieldset ' => 'head '
292
+ ],
293
+ ];
294
+
295
+ $ this ->scopeValidator ->expects ($ this ->once ())
296
+ ->method ('isValidScope ' )
297
+ ->with ($ scope , $ scopeId )
298
+ ->willReturn (true );
299
+ $ this ->storeManager ->expects ($ this ->once ())
300
+ ->method ('isSingleStoreMode ' )
301
+ ->willReturn (true );
302
+ $ this ->storeManager ->expects ($ this ->once ())
303
+ ->method ('getWebsites ' )
304
+ ->willReturn ([$ this ->website ]);
305
+ $ this ->website ->expects ($ this ->once ())
306
+ ->method ('getId ' )
307
+ ->willReturn (1 );
308
+
309
+ $ this ->designConfigFactory ->expects ($ this ->once ())
310
+ ->method ('create ' )
311
+ ->willReturn ($ this ->designConfig );
312
+ $ this ->designConfig ->expects ($ this ->once ())
313
+ ->method ('setScope ' )
314
+ ->willReturn ('websites ' );
315
+ $ this ->designConfig ->expects ($ this ->once ())
316
+ ->method ('setScopeId ' )
317
+ ->willReturn (1 );
318
+ $ this ->metadataProvider ->expects ($ this ->once ())
319
+ ->method ('get ' )
320
+ ->willReturn ($ metadata );
321
+ $ this ->designConfigDataFactory ->expects ($ this ->exactly (2 ))
322
+ ->method ('create ' )
323
+ ->willReturn ($ this ->designConfigData );
324
+ $ this ->designConfigData ->expects ($ this ->exactly (2 ))
325
+ ->method ('setPath ' )
326
+ ->willReturnCallback (function ($ arg1 ) {
327
+ if ($ arg1 == 'design/header/default_title ' && $ arg1 == 'design/head/default_description ' ) {
328
+ return null ;
329
+ }
330
+ });
331
+ $ this ->designConfigData ->expects ($ this ->exactly (2 ))
332
+ ->method ('setFieldConfig ' )
333
+ ->willReturnCallback (function ($ arg1 ) {
334
+ if ($ arg1 == 'design/header/default_title ' && $ arg1 == 'design/head/default_description ' ) {
335
+ return null ;
336
+ }
337
+ });
338
+ $ this ->settingChecker ->expects ($ this ->once ())
339
+ ->method ('isReadOnly ' )
340
+ ->with ('design/header/default_title ' , 'default ' , 0 )
341
+ ->willReturn (true );
342
+ $ this ->configExtensionFactory ->expects ($ this ->once ())
343
+ ->method ('create ' )
344
+ ->willReturn ($ this ->designConfigExtension );
345
+ $ this ->designConfigExtension ->expects ($ this ->once ())
346
+ ->method ('setDesignConfigData ' )
347
+ ->with ([$ this ->designConfigData , $ this ->designConfigData ]);
348
+ $ this ->designConfig ->expects ($ this ->once ())
349
+ ->method ('setExtensionAttributes ' )
350
+ ->with ($ this ->designConfigExtension );
351
+ $ this ->assertSame ($ this ->designConfig , $ this ->factory ->create ($ scope , $ scopeId , $ data ));
352
+ }
259
353
}
0 commit comments