@@ -38,6 +38,11 @@ class LiveCodeTest extends TestCase
38
38
'Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface ' ,
39
39
];
40
40
41
+ /**
42
+ * @var mixed
43
+ */
44
+ private static mixed $ frontendDataProviders ;
45
+
41
46
/**
42
47
* Setup basics for all tests
43
48
*/
@@ -116,7 +121,7 @@ private static function getModulesRequiringGraphQLChange(): array
116
121
continue ;
117
122
}
118
123
119
- if (!in_array ($ moduleName , $ requireGraphQLChanges ) && self ::isViewLayerClass ($ whitelistFile )) {
124
+ if (!in_array ($ moduleName , $ requireGraphQLChanges ) && self ::isViewLayerClass ($ whitelistFile, $ moduleName )) {
120
125
$ requireGraphQLChanges [] = $ moduleName . "GraphQl " ;
121
126
}
122
127
}
@@ -138,15 +143,20 @@ private static function getModuleName(string $filePath): string
138
143
}
139
144
140
145
/**
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
142
147
*
143
148
* @param string $filePath
149
+ * @param string $moduleName
144
150
* @return bool
145
151
*/
146
- private static function isViewLayerClass (string $ filePath ): bool
152
+ private static function isViewLayerClass (string $ filePath, string $ moduleName ): bool
147
153
{
148
154
$ 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
+ ) {
150
160
return false ;
151
161
}
152
162
@@ -168,4 +178,39 @@ private static function getClassNameWithNamespace(string $filePath): string
168
178
}
169
179
return '' ;
170
180
}
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
+ }
171
216
}
0 commit comments