21
21
use Psr \Log \LoggerInterface ;
22
22
use PHPUnit \Framework \MockObject \MockObject as MockObject ;
23
23
use Magento \Framework \Filesystem \Driver \File ;
24
+ use Magento \Framework \View \Design \Theme \ThemePackageList ;
25
+ use Magento \Framework \Validator \Locale ;
24
26
25
27
/**
26
28
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -77,6 +79,16 @@ class StaticResourceTest extends \PHPUnit\Framework\TestCase
77
79
*/
78
80
private $ deploymentConfigMock ;
79
81
82
+ /**
83
+ * @var ThemePackageList|MockObject
84
+ */
85
+ private $ themePackageListMock ;
86
+
87
+ /**
88
+ * @var Locale|MockObject
89
+ */
90
+ private $ localeValidatorMock ;
91
+
80
92
/**
81
93
* @var StaticResource
82
94
*/
@@ -100,6 +112,8 @@ protected function setUp(): void
100
112
$ this ->configLoaderMock = $ this ->createMock (ConfigLoader::class);
101
113
$ this ->deploymentConfigMock = $ this ->createMock (DeploymentConfig::class);
102
114
$ this ->driverMock = $ this ->createMock (File::class);
115
+ $ this ->themePackageListMock = $ this ->createMock (ThemePackageList::class);
116
+ $ this ->localeValidatorMock = $ this ->createMock (Locale::class);
103
117
$ this ->object = new StaticResource (
104
118
$ this ->stateMock ,
105
119
$ this ->responseMock ,
@@ -110,7 +124,9 @@ protected function setUp(): void
110
124
$ this ->objectManagerMock ,
111
125
$ this ->configLoaderMock ,
112
126
$ this ->deploymentConfigMock ,
113
- $ this ->driverMock
127
+ $ this ->driverMock ,
128
+ $ this ->themePackageListMock ,
129
+ $ this ->localeValidatorMock
114
130
);
115
131
}
116
132
@@ -201,6 +217,17 @@ public function testLaunch(
201
217
$ this ->driverMock ->expects ($ this ->once ())
202
218
->method ('getRealPathSafety ' )
203
219
->willReturnArgument (0 );
220
+ $ this ->themePackageListMock ->expects ($ this ->atLeastOnce ())->method ('getThemes ' )->willReturn (
221
+ [
222
+ 'area/Magento/theme ' => [
223
+ 'area ' => 'area ' ,
224
+ 'vendor ' => 'Magento ' ,
225
+ 'name ' => 'theme ' ,
226
+ ],
227
+ ]
228
+ );
229
+ $ this ->localeValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (true );
230
+
204
231
$ this ->object ->launch ();
205
232
}
206
233
@@ -322,4 +349,86 @@ public function testLaunchPathAbove()
322
349
323
350
$ this ->object ->launch ();
324
351
}
352
+
353
+ /**
354
+ * @param array $themes
355
+ * @dataProvider themesDataProvider
356
+ */
357
+ public function testLaunchWithInvalidTheme (array $ themes ): void
358
+ {
359
+ $ this ->expectException ('InvalidArgumentException ' );
360
+ $ path = 'frontend/Test/luma/en_US/calendar.css ' ;
361
+
362
+ $ this ->stateMock ->expects ($ this ->once ())
363
+ ->method ('getMode ' )
364
+ ->willReturn (State::MODE_DEVELOPER );
365
+ $ this ->requestMock ->expects ($ this ->once ())
366
+ ->method ('get ' )
367
+ ->with ('resource ' )
368
+ ->willReturn ($ path );
369
+ $ this ->driverMock ->expects ($ this ->once ())
370
+ ->method ('getRealPathSafety ' )
371
+ ->with ($ path )
372
+ ->willReturn ($ path );
373
+ $ this ->themePackageListMock ->expects ($ this ->once ())->method ('getThemes ' )->willReturn ($ themes );
374
+ $ this ->localeValidatorMock ->expects ($ this ->never ())->method ('isValid ' );
375
+ $ this ->expectExceptionMessage ('Requested path ' . $ path . ' is wrong. ' );
376
+
377
+ $ this ->object ->launch ();
378
+ }
379
+
380
+ /**
381
+ * @param array $themes
382
+ * @dataProvider themesDataProvider
383
+ */
384
+ public function testLaunchWithInvalidLocale (array $ themes ): void
385
+ {
386
+ $ this ->expectException ('InvalidArgumentException ' );
387
+ $ path = 'frontend/Magento/luma/test/calendar.css ' ;
388
+
389
+ $ this ->stateMock ->expects ($ this ->once ())
390
+ ->method ('getMode ' )
391
+ ->willReturn (State::MODE_DEVELOPER );
392
+ $ this ->requestMock ->expects ($ this ->once ())
393
+ ->method ('get ' )
394
+ ->with ('resource ' )
395
+ ->willReturn ($ path );
396
+ $ this ->driverMock ->expects ($ this ->once ())
397
+ ->method ('getRealPathSafety ' )
398
+ ->with ($ path )
399
+ ->willReturn ($ path );
400
+ $ this ->themePackageListMock ->expects ($ this ->once ())->method ('getThemes ' )->willReturn ($ themes );
401
+ $ this ->localeValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (false );
402
+ $ this ->expectExceptionMessage ('Requested path ' . $ path . ' is wrong. ' );
403
+
404
+ $ this ->object ->launch ();
405
+ }
406
+
407
+ /**
408
+ * @return array
409
+ */
410
+ public function themesDataProvider (): array
411
+ {
412
+ return [
413
+ [
414
+ [
415
+ 'adminhtml/Magento/backend ' => [
416
+ 'area ' => 'adminhtml ' ,
417
+ 'vendor ' => 'Magento ' ,
418
+ 'name ' => 'backend ' ,
419
+ ],
420
+ 'frontend/Magento/blank ' => [
421
+ 'area ' => 'frontend ' ,
422
+ 'vendor ' => 'Magento ' ,
423
+ 'name ' => 'blank ' ,
424
+ ],
425
+ 'frontend/Magento/luma ' => [
426
+ 'area ' => 'frontend ' ,
427
+ 'vendor ' => 'Magento ' ,
428
+ 'name ' => 'luma ' ,
429
+ ],
430
+ ],
431
+ ],
432
+ ];
433
+ }
325
434
}
0 commit comments