@@ -28,20 +28,10 @@ class LiveCodeTest extends TestCase
28
28
*/
29
29
private static $ changeCheckDir = '' ;
30
30
31
- /**
32
- * @var array
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
- ];
40
-
41
31
/**
42
32
* @var mixed
43
33
*/
44
- private static mixed $ frontendDataProviders ;
34
+ private static mixed $ frontendUIComponent ;
45
35
46
36
/**
47
37
* Setup basics for all tests
@@ -153,15 +143,13 @@ private static function isViewLayerClass(string $filePath, string $moduleName):
153
143
{
154
144
$ className = self ::getClassNameWithNamespace ($ filePath );
155
145
if (
156
- ! $ className ||
157
- str_contains (strtolower ($ className ), 'adminhtml ' ) ||
158
- ( str_contains ( strtolower ( $ className ), ' \ui \\' ) && ! self ::isFrontendDataProvider ($ moduleName , $ className) )
146
+ $ className &&
147
+ ! str_contains (strtolower ($ className ), 'adminhtml ' ) &&
148
+ self ::isFrontendUIComponent ($ moduleName , $ className )
159
149
) {
160
- return false ;
150
+ return true ;
161
151
}
162
-
163
- $ implementingInterfaces = array_values (class_implements ($ className ));
164
- return !empty (array_intersect ($ implementingInterfaces , self ::$ uiDataComponentInterface ));
152
+ return false ;
165
153
}
166
154
167
155
/**
@@ -186,31 +174,48 @@ private static function getClassNameWithNamespace(string $filePath): string
186
174
* @param string $className
187
175
* @return bool
188
176
*/
189
- private static function isFrontendDataProvider (string $ moduleName , string $ className ): bool
177
+ private static function isFrontendUIComponent (string $ moduleName , string $ className ): bool
190
178
{
191
- if (isset (self ::$ frontendDataProviders [$ moduleName ])) {
192
- $ frontendDataProviders = self ::$ frontendDataProviders [$ moduleName ];
179
+ if (isset (self ::$ frontendUIComponent [$ moduleName ])) {
180
+ $ frontendUIComponent = self ::$ frontendUIComponent [$ moduleName ];
193
181
} else {
194
- $ frontendDataProviders = [];
195
- $ files = glob (BP . '/app/code/Magento/ ' .$ moduleName .'/view/frontend/ui_component /*.xml ' );
182
+ $ frontendUIComponent = [];
183
+ $ files = glob (BP . '/app/code/Magento/ ' .$ moduleName .'/view/frontend/* /*.xml ' );
196
184
197
185
if (is_array ($ files )) {
186
+ $ uIComponentClasses = [];
198
187
foreach ($ files as $ filename ) {
199
188
$ xml = simplexml_load_file ($ filename );
200
-
201
- if (isset ($ xml ->dataSource ->dataProvider )) {
202
-
203
- $ frontendDataProvider = (string )$ xml ->dataSource ->dataProvider ['class ' ];
204
- $ frontendDataProviders [] = $ frontendDataProvider ;
205
- }
189
+ $ dataProviders = $ xml ->xpath ('//@class ' );
190
+ $ uIComponentClasses = array_merge ($ dataProviders , $ uIComponentClasses );
206
191
}
207
- self ::$ frontendDataProviders [$ moduleName ] = $ frontendDataProviders ;
192
+ $ frontendUIComponent = self ::filterUiComponents (array_unique ($ uIComponentClasses ), $ moduleName );
193
+ self ::$ frontendUIComponent [$ moduleName ] = $ frontendUIComponent ;
208
194
}
209
195
}
210
196
211
- if (in_array ($ className , $ frontendDataProviders )) {
197
+ if (in_array ($ className , $ frontendUIComponent )) {
212
198
return true ;
213
199
}
214
200
return false ;
215
201
}
202
+
203
+ /**
204
+ * Filter the array of classes to return only the classes in this module
205
+ *
206
+ * @param array $uIComponentClasses
207
+ * @param string $moduleName
208
+ * @return array
209
+ */
210
+ private static function filterUiComponents (array $ uIComponentClasses , string $ moduleName ): array
211
+ {
212
+ $ frontendUIComponent = [];
213
+ foreach ($ uIComponentClasses as $ dataProvider ) {
214
+ $ dataProviderClass = ltrim ((string )$ dataProvider ->class , '\\' );
215
+ if (str_starts_with ($ dataProviderClass , 'Magento \\' . $ moduleName )) {
216
+ $ frontendUIComponent [] = $ dataProviderClass ;
217
+ }
218
+ }
219
+ return $ frontendUIComponent ;
220
+ }
216
221
}
0 commit comments