@@ -28,20 +28,10 @@ class LiveCodeTest extends TestCase
2828 */
2929 private static $ changeCheckDir = '' ;
3030
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-
4131 /**
4232 * @var mixed
4333 */
44- private static mixed $ frontendDataProviders ;
34+ private static mixed $ frontendUIComponent ;
4535
4636 /**
4737 * Setup basics for all tests
@@ -153,15 +143,13 @@ private static function isViewLayerClass(string $filePath, string $moduleName):
153143 {
154144 $ className = self ::getClassNameWithNamespace ($ filePath );
155145 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 )
159149 ) {
160- return false ;
150+ return true ;
161151 }
162-
163- $ implementingInterfaces = array_values (class_implements ($ className ));
164- return !empty (array_intersect ($ implementingInterfaces , self ::$ uiDataComponentInterface ));
152+ return false ;
165153 }
166154
167155 /**
@@ -186,31 +174,48 @@ private static function getClassNameWithNamespace(string $filePath): string
186174 * @param string $className
187175 * @return bool
188176 */
189- private static function isFrontendDataProvider (string $ moduleName , string $ className ): bool
177+ private static function isFrontendUIComponent (string $ moduleName , string $ className ): bool
190178 {
191- if (isset (self ::$ frontendDataProviders [$ moduleName ])) {
192- $ frontendDataProviders = self ::$ frontendDataProviders [$ moduleName ];
179+ if (isset (self ::$ frontendUIComponent [$ moduleName ])) {
180+ $ frontendUIComponent = self ::$ frontendUIComponent [$ moduleName ];
193181 } 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 ' );
196184
197185 if (is_array ($ files )) {
186+ $ uIComponentClasses = [];
198187 foreach ($ files as $ filename ) {
199188 $ 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 );
206191 }
207- self ::$ frontendDataProviders [$ moduleName ] = $ frontendDataProviders ;
192+ $ frontendUIComponent = self ::filterUiComponents (array_unique ($ uIComponentClasses ), $ moduleName );
193+ self ::$ frontendUIComponent [$ moduleName ] = $ frontendUIComponent ;
208194 }
209195 }
210196
211- if (in_array ($ className , $ frontendDataProviders )) {
197+ if (in_array ($ className , $ frontendUIComponent )) {
212198 return true ;
213199 }
214200 return false ;
215201 }
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+ }
216221}
0 commit comments