19
19
use Magento \Framework \Filesystem \Driver \File ;
20
20
use Magento \Framework \Module \ModuleList ;
21
21
use Magento \Framework \ObjectManagerInterface ;
22
+ use Magento \Framework \Validator \Locale ;
22
23
use Magento \Framework \View \Asset \LocalInterface ;
23
24
use Magento \Framework \View \Asset \Repository ;
25
+ use Magento \Framework \View \Design \Theme \ThemePackageList ;
24
26
use PHPUnit \Framework \MockObject \MockObject ;
25
27
use PHPUnit \Framework \TestCase ;
26
28
use Psr \Log \LoggerInterface ;
@@ -85,6 +87,16 @@ class StaticResourceTest extends TestCase
85
87
*/
86
88
private $ driverMock ;
87
89
90
+ /**
91
+ * @var ThemePackageList|MockObject
92
+ */
93
+ private $ themePackageListMock ;
94
+
95
+ /**
96
+ * @var Locale|MockObject
97
+ */
98
+ private $ localeValidatorMock ;
99
+
88
100
/**
89
101
* @var StaticResource
90
102
*/
@@ -106,6 +118,8 @@ protected function setUp(): void
106
118
$ this ->configLoaderMock = $ this ->createMock (ConfigLoader::class);
107
119
$ this ->deploymentConfigMock = $ this ->createMock (DeploymentConfig::class);
108
120
$ this ->driverMock = $ this ->createMock (File::class);
121
+ $ this ->themePackageListMock = $ this ->createMock (ThemePackageList::class);
122
+ $ this ->localeValidatorMock = $ this ->createMock (Locale::class);
109
123
$ this ->object = new StaticResource (
110
124
$ this ->stateMock ,
111
125
$ this ->responseMock ,
@@ -116,7 +130,9 @@ protected function setUp(): void
116
130
$ this ->objectManagerMock ,
117
131
$ this ->configLoaderMock ,
118
132
$ this ->deploymentConfigMock ,
119
- $ this ->driverMock
133
+ $ this ->driverMock ,
134
+ $ this ->themePackageListMock ,
135
+ $ this ->localeValidatorMock
120
136
);
121
137
}
122
138
@@ -210,6 +226,16 @@ public function testLaunch(
210
226
$ this ->driverMock ->expects ($ this ->once ())
211
227
->method ('getRealPathSafety ' )
212
228
->willReturnArgument (0 );
229
+ $ this ->themePackageListMock ->expects ($ this ->atLeastOnce ())->method ('getThemes ' )->willReturn (
230
+ [
231
+ 'area/Magento/theme ' => [
232
+ 'area ' => 'area ' ,
233
+ 'vendor ' => 'Magento ' ,
234
+ 'name ' => 'theme ' ,
235
+ ],
236
+ ],
237
+ );
238
+ $ this ->localeValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (true );
213
239
$ this ->object ->launch ();
214
240
}
215
241
@@ -353,4 +379,86 @@ public function testLaunchPathAbove()
353
379
354
380
$ this ->object ->launch ();
355
381
}
382
+
383
+ /**
384
+ * @param array $themes
385
+ * @dataProvider themesDataProvider
386
+ */
387
+ public function testLaunchWithInvalidTheme (array $ themes ): void
388
+ {
389
+ $ this ->expectException ('InvalidArgumentException ' );
390
+ $ path = 'frontend/Test/luma/en_US/calendar.css ' ;
391
+
392
+ $ this ->stateMock ->expects ($ this ->once ())
393
+ ->method ('getMode ' )
394
+ ->willReturn (State::MODE_DEVELOPER );
395
+ $ this ->requestMock ->expects ($ this ->once ())
396
+ ->method ('get ' )
397
+ ->with ('resource ' )
398
+ ->willReturn ($ path );
399
+ $ this ->driverMock ->expects ($ this ->once ())
400
+ ->method ('getRealPathSafety ' )
401
+ ->with ($ path )
402
+ ->willReturn ($ path );
403
+ $ this ->themePackageListMock ->expects ($ this ->once ())->method ('getThemes ' )->willReturn ($ themes );
404
+ $ this ->localeValidatorMock ->expects ($ this ->never ())->method ('isValid ' );
405
+ $ this ->expectExceptionMessage ('Requested path ' . $ path . ' is wrong. ' );
406
+
407
+ $ this ->object ->launch ();
408
+ }
409
+
410
+ /**
411
+ * @param array $themes
412
+ * @dataProvider themesDataProvider
413
+ */
414
+ public function testLaunchWithInvalidLocale (array $ themes ): void
415
+ {
416
+ $ this ->expectException ('InvalidArgumentException ' );
417
+ $ path = 'frontend/Magento/luma/test/calendar.css ' ;
418
+
419
+ $ this ->stateMock ->expects ($ this ->once ())
420
+ ->method ('getMode ' )
421
+ ->willReturn (State::MODE_DEVELOPER );
422
+ $ this ->requestMock ->expects ($ this ->once ())
423
+ ->method ('get ' )
424
+ ->with ('resource ' )
425
+ ->willReturn ($ path );
426
+ $ this ->driverMock ->expects ($ this ->once ())
427
+ ->method ('getRealPathSafety ' )
428
+ ->with ($ path )
429
+ ->willReturn ($ path );
430
+ $ this ->themePackageListMock ->expects ($ this ->once ())->method ('getThemes ' )->willReturn ($ themes );
431
+ $ this ->localeValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (false );
432
+ $ this ->expectExceptionMessage ('Requested path ' . $ path . ' is wrong. ' );
433
+
434
+ $ this ->object ->launch ();
435
+ }
436
+
437
+ /**
438
+ * @return array
439
+ */
440
+ public function themesDataProvider (): array
441
+ {
442
+ return [
443
+ [
444
+ [
445
+ 'adminhtml/Magento/backend ' => [
446
+ 'area ' => 'adminhtml ' ,
447
+ 'vendor ' => 'Magento ' ,
448
+ 'name ' => 'backend ' ,
449
+ ],
450
+ 'frontend/Magento/blank ' => [
451
+ 'area ' => 'frontend ' ,
452
+ 'vendor ' => 'Magento ' ,
453
+ 'name ' => 'blank ' ,
454
+ ],
455
+ 'frontend/Magento/luma ' => [
456
+ 'area ' => 'frontend ' ,
457
+ 'vendor ' => 'Magento ' ,
458
+ 'name ' => 'luma ' ,
459
+ ],
460
+ ],
461
+ ],
462
+ ];
463
+ }
356
464
}
0 commit comments