@@ -29,14 +29,9 @@ class LiveCodeTest extends TestCase
29
29
private static $ changeCheckDir = '' ;
30
30
31
31
/**
32
- * @var array
32
+ * @var mixed
33
33
*/
34
- private static $ uiDataComponentInterface = [
35
- 'Magento\Framework\App\ActionInterface ' ,
36
- 'Magento\Framework\View\Element\BlockInterface ' ,
37
- 'Magento\Framework\View\Element\UiComponentInterface ' ,
38
- 'Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface ' ,
39
- ];
34
+ private static mixed $ frontendUIComponent ;
40
35
41
36
/**
42
37
* Setup basics for all tests
@@ -116,7 +111,7 @@ private static function getModulesRequiringGraphQLChange(): array
116
111
continue ;
117
112
}
118
113
119
- if (!in_array ($ moduleName , $ requireGraphQLChanges ) && self ::isViewLayerClass ($ whitelistFile )) {
114
+ if (!in_array ($ moduleName , $ requireGraphQLChanges ) && self ::isViewLayerClass ($ whitelistFile, $ moduleName )) {
120
115
$ requireGraphQLChanges [] = $ moduleName . "GraphQl " ;
121
116
}
122
117
}
@@ -138,20 +133,20 @@ private static function getModuleName(string $filePath): string
138
133
}
139
134
140
135
/**
141
- * Return true if the class implements any of the defined interfaces
136
+ * Return true if the class is a data provider for the frontend
142
137
*
143
138
* @param string $filePath
139
+ * @param string $moduleName
144
140
* @return bool
145
141
*/
146
- private static function isViewLayerClass (string $ filePath ): bool
142
+ private static function isViewLayerClass (string $ filePath, string $ moduleName ): bool
147
143
{
148
144
$ className = self ::getClassNameWithNamespace ($ filePath );
149
- if (!$ className || str_contains (strtolower ($ className ), 'adminhtml ' )) {
150
- return false ;
145
+ $ adminChange = str_contains (strtolower ($ className ), 'adminhtml ' );
146
+ if ($ className && !$ adminChange && self ::isFrontendUIComponent ($ moduleName , $ className )) {
147
+ return true ;
151
148
}
152
-
153
- $ implementingInterfaces = array_values (class_implements ($ className ));
154
- return !empty (array_intersect ($ implementingInterfaces , self ::$ uiDataComponentInterface ));
149
+ return false ;
155
150
}
156
151
157
152
/**
@@ -168,4 +163,50 @@ private static function getClassNameWithNamespace(string $filePath): string
168
163
}
169
164
return '' ;
170
165
}
166
+
167
+ /**
168
+ * Check if the class is a frontend data provider
169
+ *
170
+ * @param string $moduleName
171
+ * @param string $className
172
+ * @return bool
173
+ */
174
+ private static function isFrontendUIComponent (string $ moduleName , string $ className ): bool
175
+ {
176
+ if (!isset (self ::$ frontendUIComponent [$ moduleName ])) {
177
+ $ files = glob (BP . '/app/code/Magento/ ' .$ moduleName .'/view/frontend/*/*.xml ' );
178
+
179
+ if (is_array ($ files )) {
180
+ $ uIComponentClasses = [];
181
+
182
+ foreach ($ files as $ filename ) {
183
+ $ uIComponentClasses [] = simplexml_load_file ($ filename )->xpath ('//@class ' );
184
+ }
185
+ self ::$ frontendUIComponent [$ moduleName ] = self ::filterUiComponents (
186
+ array_unique (array_merge ([], ...$ uIComponentClasses )),
187
+ $ moduleName
188
+ );
189
+ }
190
+ }
191
+ return in_array ($ className , self ::$ frontendUIComponent [$ moduleName ]);
192
+ }
193
+
194
+ /**
195
+ * Filter the array of classes to return only the classes in this module
196
+ *
197
+ * @param array $uIComponentClasses
198
+ * @param string $moduleName
199
+ * @return array
200
+ */
201
+ private static function filterUiComponents (array $ uIComponentClasses , string $ moduleName ): array
202
+ {
203
+ $ frontendUIComponent = [];
204
+ foreach ($ uIComponentClasses as $ dataProvider ) {
205
+ $ dataProviderClass = ltrim ((string )$ dataProvider ->class , '\\' );
206
+ if (str_starts_with ($ dataProviderClass , 'Magento \\' . $ moduleName )) {
207
+ $ frontendUIComponent [] = $ dataProviderClass ;
208
+ }
209
+ }
210
+ return $ frontendUIComponent ;
211
+ }
171
212
}
0 commit comments