@@ -38,6 +38,11 @@ class LiveCodeTest extends TestCase
3838 'Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface ' ,
3939 ];
4040
41+ /**
42+ * @var mixed
43+ */
44+ private static mixed $ frontendDataProviders ;
45+
4146 /**
4247 * Setup basics for all tests
4348 */
@@ -116,7 +121,7 @@ private static function getModulesRequiringGraphQLChange(): array
116121 continue ;
117122 }
118123
119- if (!in_array ($ moduleName , $ requireGraphQLChanges ) && self ::isViewLayerClass ($ whitelistFile )) {
124+ if (!in_array ($ moduleName , $ requireGraphQLChanges ) && self ::isViewLayerClass ($ whitelistFile, $ moduleName )) {
120125 $ requireGraphQLChanges [] = $ moduleName . "GraphQl " ;
121126 }
122127 }
@@ -138,15 +143,20 @@ private static function getModuleName(string $filePath): string
138143 }
139144
140145 /**
141- * Return true if the class implements any of the defined interfaces
146+ * Return true if the class is a data provider for the frontend
142147 *
143148 * @param string $filePath
149+ * @param string $moduleName
144150 * @return bool
145151 */
146- private static function isViewLayerClass (string $ filePath ): bool
152+ private static function isViewLayerClass (string $ filePath, string $ moduleName ): bool
147153 {
148154 $ className = self ::getClassNameWithNamespace ($ filePath );
149- if (!$ className || str_contains (strtolower ($ className ), 'adminhtml ' )) {
155+ if (
156+ !$ className ||
157+ str_contains (strtolower ($ className ), 'adminhtml ' ) ||
158+ (str_contains (strtolower ($ className ), '\ui \\' ) && !self ::isFrontendDataProvider ($ moduleName , $ className ))
159+ ) {
150160 return false ;
151161 }
152162
@@ -168,4 +178,39 @@ private static function getClassNameWithNamespace(string $filePath): string
168178 }
169179 return '' ;
170180 }
181+
182+ /**
183+ * Check if the class is a frontend data provider
184+ *
185+ * @param string $moduleName
186+ * @param string $className
187+ * @return bool
188+ */
189+ private static function isFrontendDataProvider (string $ moduleName , string $ className ): bool
190+ {
191+ if (isset (self ::$ frontendDataProviders [$ moduleName ])) {
192+ $ frontendDataProviders = self ::$ frontendDataProviders [$ moduleName ];
193+ } else {
194+ $ frontendDataProviders = [];
195+ $ files = glob (BP . '/app/code/Magento/ ' .$ moduleName .'/view/frontend/ui_component/*.xml ' );
196+
197+ if (is_array ($ files )) {
198+ foreach ($ files as $ filename ) {
199+ $ xml = simplexml_load_file ($ filename );
200+
201+ if (isset ($ xml ->dataSource ->dataProvider )) {
202+
203+ $ frontendDataProvider = (string )$ xml ->dataSource ->dataProvider ['class ' ];
204+ $ frontendDataProviders [] = $ frontendDataProvider ;
205+ }
206+ }
207+ self ::$ frontendDataProviders [$ moduleName ] = $ frontendDataProviders ;
208+ }
209+ }
210+
211+ if (in_array ($ className , $ frontendDataProviders )) {
212+ return true ;
213+ }
214+ return false ;
215+ }
171216}
0 commit comments