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()
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()
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
@@ -320,4 +347,86 @@ public function testLaunchPathAbove()
320
347
321
348
$ this ->object ->launch ();
322
349
}
350
+
351
+ /**
352
+ * @param array $themes
353
+ * @dataProvider themesDataProvider
354
+ */
355
+ public function testLaunchWithInvalidTheme (array $ themes ): void
356
+ {
357
+ $ this ->expectException ('InvalidArgumentException ' );
358
+ $ path = 'frontend/Test/luma/en_US/calendar.css ' ;
359
+
360
+ $ this ->stateMock ->expects ($ this ->once ())
361
+ ->method ('getMode ' )
362
+ ->willReturn (State::MODE_DEVELOPER );
363
+ $ this ->requestMock ->expects ($ this ->once ())
364
+ ->method ('get ' )
365
+ ->with ('resource ' )
366
+ ->willReturn ($ path );
367
+ $ this ->driverMock ->expects ($ this ->once ())
368
+ ->method ('getRealPathSafety ' )
369
+ ->with ($ path )
370
+ ->willReturn ($ path );
371
+ $ this ->themePackageListMock ->expects ($ this ->once ())->method ('getThemes ' )->willReturn ($ themes );
372
+ $ this ->localeValidatorMock ->expects ($ this ->never ())->method ('isValid ' );
373
+ $ this ->expectExceptionMessage ('Requested path ' . $ path . ' is wrong. ' );
374
+
375
+ $ this ->object ->launch ();
376
+ }
377
+
378
+ /**
379
+ * @param array $themes
380
+ * @dataProvider themesDataProvider
381
+ */
382
+ public function testLaunchWithInvalidLocale (array $ themes ): void
383
+ {
384
+ $ this ->expectException ('InvalidArgumentException ' );
385
+ $ path = 'frontend/Magento/luma/test/calendar.css ' ;
386
+
387
+ $ this ->stateMock ->expects ($ this ->once ())
388
+ ->method ('getMode ' )
389
+ ->willReturn (State::MODE_DEVELOPER );
390
+ $ this ->requestMock ->expects ($ this ->once ())
391
+ ->method ('get ' )
392
+ ->with ('resource ' )
393
+ ->willReturn ($ path );
394
+ $ this ->driverMock ->expects ($ this ->once ())
395
+ ->method ('getRealPathSafety ' )
396
+ ->with ($ path )
397
+ ->willReturn ($ path );
398
+ $ this ->themePackageListMock ->expects ($ this ->once ())->method ('getThemes ' )->willReturn ($ themes );
399
+ $ this ->localeValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->willReturn (false );
400
+ $ this ->expectExceptionMessage ('Requested path ' . $ path . ' is wrong. ' );
401
+
402
+ $ this ->object ->launch ();
403
+ }
404
+
405
+ /**
406
+ * @return array
407
+ */
408
+ public function themesDataProvider (): array
409
+ {
410
+ return [
411
+ [
412
+ [
413
+ 'adminhtml/Magento/backend ' => [
414
+ 'area ' => 'adminhtml ' ,
415
+ 'vendor ' => 'Magento ' ,
416
+ 'name ' => 'backend ' ,
417
+ ],
418
+ 'frontend/Magento/blank ' => [
419
+ 'area ' => 'frontend ' ,
420
+ 'vendor ' => 'Magento ' ,
421
+ 'name ' => 'blank ' ,
422
+ ],
423
+ 'frontend/Magento/luma ' => [
424
+ 'area ' => 'frontend ' ,
425
+ 'vendor ' => 'Magento ' ,
426
+ 'name ' => 'luma ' ,
427
+ ],
428
+ ],
429
+ ],
430
+ ];
431
+ }
323
432
}
0 commit comments