Skip to content

Commit 4ecc9bb

Browse files
committed
MAGETWO-61877: UI Upgrade from 2.0.x to 2.0.11 Test Failure with Sample Data
- refactoring code to better readability
1 parent 07d9000 commit 4ecc9bb

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

dev/tests/functional/tests/app/Magento/Upgrade/Test/Block/SelectVersion.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,9 @@ private function convertVersionFixtureToRegexp($sampleDataVersion)
184184
*/
185185
private function titleContainsSampleData($element)
186186
{
187-
return preg_match('/magento.+sample.+data/', $element->getText());
187+
return preg_match('/magento\/*+sample-data/', $element->getText());
188188
}
189189

190-
191190
/**
192191
* Sets sample data version matching the maximum compatible version from fixture
193192
*
@@ -198,18 +197,25 @@ private function titleContainsSampleData($element)
198197
private function setSampleDataVersionToRowSelect($rowIndex, $sampleDataVersionForRegex)
199198
{
200199
$selectElement = $this->getSelectFromRow($rowIndex);
201-
$toSelectVersion = '0';
200+
$optionTextArray = [];
202201
foreach ($selectElement->getElements('option') as $option) {
203202
$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;
212213
}
214+
);
215+
216+
$toSelectVersion = key($optionTextArray);
217+
if ($toSelectVersion !== $selectElement->getText()) {
218+
$selectElement->setValue($optionTextArray[]);
213219
}
214220
}
215221
}

0 commit comments

Comments
 (0)