1919use Magento \Framework \Filesystem \Driver \File ;
2020use Magento \Framework \Module \ModuleList ;
2121use Magento \Framework \ObjectManagerInterface ;
22+ use Magento \Framework \Validator \Locale ;
2223use Magento \Framework \View \Asset \LocalInterface ;
2324use Magento \Framework \View \Asset \Repository ;
25+ use Magento \Framework \View \Design \Theme \ThemePackageList ;
2426use PHPUnit \Framework \MockObject \MockObject ;
2527use PHPUnit \Framework \TestCase ;
2628use Psr \Log \LoggerInterface ;
@@ -85,6 +87,16 @@ class StaticResourceTest extends TestCase
8587 */
8688 private $ driverMock ;
8789
90+ /**
91+ * @var ThemePackageList|MockObject
92+ */
93+ private $ themePackageListMock ;
94+
95+ /**
96+ * @var Locale|MockObject
97+ */
98+ private $ localeValidatorMock ;
99+
88100 /**
89101 * @var StaticResource
90102 */
@@ -106,6 +118,8 @@ protected function setUp(): void
106118 $ this ->configLoaderMock = $ this ->createMock (ConfigLoader::class);
107119 $ this ->deploymentConfigMock = $ this ->createMock (DeploymentConfig::class);
108120 $ this ->driverMock = $ this ->createMock (File::class);
121+ $ this ->themePackageListMock = $ this ->createMock (ThemePackageList::class);
122+ $ this ->localeValidatorMock = $ this ->createMock (Locale::class);
109123 $ this ->object = new StaticResource (
110124 $ this ->stateMock ,
111125 $ this ->responseMock ,
@@ -116,7 +130,9 @@ protected function setUp(): void
116130 $ this ->objectManagerMock ,
117131 $ this ->configLoaderMock ,
118132 $ this ->deploymentConfigMock ,
119- $ this ->driverMock
133+ $ this ->driverMock ,
134+ $ this ->themePackageListMock ,
135+ $ this ->localeValidatorMock
120136 );
121137 }
122138
@@ -210,6 +226,16 @@ public function testLaunch(
210226 $ this ->driverMock ->expects ($ this ->once ())
211227 ->method ('getRealPathSafety ' )
212228 ->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 );
213239 $ this ->object ->launch ();
214240 }
215241
@@ -353,4 +379,86 @@ public function testLaunchPathAbove()
353379
354380 $ this ->object ->launch ();
355381 }
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+ }
356464}
0 commit comments