@@ -184,10 +184,9 @@ private function convertVersionFixtureToRegexp($sampleDataVersion)
184
184
*/
185
185
private function titleContainsSampleData ($ element )
186
186
{
187
- return preg_match ('/magento. +sample.+ data/ ' , $ element ->getText ());
187
+ return preg_match ('/magento\/* +sample- data/ ' , $ element ->getText ());
188
188
}
189
189
190
-
191
190
/**
192
191
* Sets sample data version matching the maximum compatible version from fixture
193
192
*
@@ -198,18 +197,25 @@ private function titleContainsSampleData($element)
198
197
private function setSampleDataVersionToRowSelect ($ rowIndex , $ sampleDataVersionForRegex )
199
198
{
200
199
$ selectElement = $ this ->getSelectFromRow ($ rowIndex );
201
- $ toSelectVersion = ' 0 ' ;
200
+ $ optionTextArray = [] ;
202
201
foreach ($ selectElement ->getElements ('option ' ) as $ option ) {
203
202
$ optionText = $ option ->getText ();
204
- if (preg_match ('/ ' . $ sampleDataVersionForRegex . '/ ' , $ optionText )
205
- && preg_match ('/([0-9\.\-a-zA-Z]+)/ ' , $ optionText , $ match )
206
- ) {
207
- $ extractedVersion = reset ($ match );
208
- if (version_compare ($ extractedVersion , $ toSelectVersion , '> ' )) {
209
- $ toSelectVersion = $ extractedVersion ;
210
- $ selectElement ->setValue ($ optionText );
211
- }
203
+ if (preg_match ('/ ' . $ sampleDataVersionForRegex . '/ ' , $ optionText )) {
204
+ preg_match ('/([0-9\.\-a-zA-Z]+)/ ' , $ optionText , $ match );
205
+ $ optionTextArray [$ optionText ] = current ($ match );
206
+ }
207
+ }
208
+
209
+ uasort (
210
+ $ optionTextArray ,
211
+ function ($ versionOne , $ versionTwo ) {
212
+ return version_compare ($ versionOne , $ versionTwo ) * -1 ;
212
213
}
214
+ );
215
+
216
+ $ toSelectVersion = key ($ optionTextArray );
217
+ if ($ toSelectVersion !== $ selectElement ->getText ()) {
218
+ $ selectElement ->setValue ($ optionTextArray []);
213
219
}
214
220
}
215
221
}
0 commit comments