6
6
7
7
namespace Magento \Test \Integrity ;
8
8
9
+ use Magento \Framework \App \Filesystem \DirectoryList ;
10
+
9
11
/**
10
12
* An integrity test that searches for references to static files and asserts that they are resolved via fallback
13
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
11
14
*/
12
15
class StaticFilesTest extends \PHPUnit \Framework \TestCase
13
16
{
@@ -36,6 +39,23 @@ class StaticFilesTest extends \PHPUnit\Framework\TestCase
36
39
*/
37
40
private $ baseTheme ;
38
41
42
+ /**
43
+ * @var \Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Alternative
44
+ */
45
+ private $ alternativeResolver ;
46
+
47
+ /**
48
+ * Factory for simple rule
49
+ *
50
+ * @var \Magento\Framework\View\Design\Fallback\Rule\SimpleFactory
51
+ */
52
+ private $ simpleFactory ;
53
+
54
+ /**
55
+ * @var \Magento\Framework\Filesystem
56
+ */
57
+ private $ filesystem ;
58
+
39
59
protected function setUp ()
40
60
{
41
61
$ om = \Magento \TestFramework \Helper \Bootstrap::getObjectmanager ();
@@ -46,6 +66,11 @@ protected function setUp()
46
66
$ this ->themeRepo = $ om ->get (\Magento \Framework \View \Design \Theme \FlyweightFactory::class);
47
67
$ this ->design = $ om ->get (\Magento \Framework \View \DesignInterface::class);
48
68
$ this ->baseTheme = $ om ->get (\Magento \Framework \View \Design \ThemeInterface::class);
69
+ $ this ->alternativeResolver = $ om ->get (
70
+ \Magento \Framework \View \Design \FileResolution \Fallback \Resolver \Alternative::class
71
+ );
72
+ $ this ->simpleFactory = $ om ->get (\Magento \Framework \View \Design \Fallback \Rule \SimpleFactory::class);
73
+ $ this ->filesystem = $ om ->get (\Magento \Framework \Filesystem::class);
49
74
}
50
75
51
76
/**
@@ -93,8 +118,17 @@ public function testReferencesFromStaticFiles($area, $themePath, $locale, $modul
93
118
$ relatedPath = \Magento \Framework \View \FileSystem::getRelatedPath ($ filePath , $ relatedResource );
94
119
}
95
120
// the $relatedPath will be suitable for feeding to the fallback system
121
+ $ staticFile = $ this ->getStaticFile ($ area , $ themePath , $ locale , $ relatedPath , $ fallbackModule );
122
+ if (empty ($ staticFile ) && substr ($ relatedPath , 0 , 2 ) === '.. ' ) {
123
+ //check if static file exists on lib level
124
+ $ path = substr ($ relatedPath , 2 );
125
+ $ libDir = rtrim ($ this ->filesystem ->getDirectoryRead (DirectoryList::LIB_WEB )->getAbsolutePath (), '/ ' );
126
+ $ rule = $ this ->simpleFactory ->create (['pattern ' => $ libDir ]);
127
+ $ params = ['area ' => $ area , 'theme ' => $ themePath , 'locale ' => $ locale ];
128
+ $ staticFile = $ this ->alternativeResolver ->resolveFile ($ rule , $ path , $ params );
129
+ }
96
130
$ this ->assertNotEmpty (
97
- $ this -> getStaticFile ( $ area , $ themePath , $ locale , $ relatedPath , $ fallbackModule ) ,
131
+ $ staticFile ,
98
132
"The related resource cannot be resolved through fallback: ' {$ relatedResource }' "
99
133
);
100
134
}
@@ -132,7 +166,7 @@ private function getDefaultThemePath($area)
132
166
* @param bool $isExplicit
133
167
* @return bool|string
134
168
*/
135
- private function getStaticFile ($ area , $ theme , $ locale , $ filePath , $ module , $ isExplicit = false )
169
+ private function getStaticFile ($ area , $ theme , $ locale , $ filePath , $ module = null , $ isExplicit = false )
136
170
{
137
171
if ($ area == 'base ' ) {
138
172
$ theme = $ this ->baseTheme ;
0 commit comments