diff --git a/dev/tests/functional/etc/events.xml b/dev/tests/functional/etc/events.xml
index a2648835265dd..3f24c78b6095c 100644
--- a/dev/tests/functional/etc/events.xml
+++ b/dev/tests/functional/etc/events.xml
@@ -43,4 +43,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dev/tests/functional/tests/app/Magento/Upgrade/Test/Block/SelectVersion.php b/dev/tests/functional/tests/app/Magento/Upgrade/Test/Block/SelectVersion.php
index d1979716e1f2c..cb606a13d813d 100644
--- a/dev/tests/functional/tests/app/Magento/Upgrade/Test/Block/SelectVersion.php
+++ b/dev/tests/functional/tests/app/Magento/Upgrade/Test/Block/SelectVersion.php
@@ -10,6 +10,7 @@
use Magento\Mtf\Client\Element\SimpleElement;
use Magento\Mtf\Client\Locator;
use Magento\Mtf\Fixture\FixtureInterface;
+use Magento\Mtf\Client\ElementInterface;
/**
* Select version block.
@@ -63,4 +64,162 @@ public function chooseUpgradeOtherComponents()
$this->_rootElement->find("[for=yesUpdateComponents]", Locator::SELECTOR_CSS)->click();
$this->waitForElementVisible("[ng-show='componentsProcessed']");
}
+
+ /**
+ * Set maximum compatible sample data for each row
+ * Iterates through each page of the grid and sets the compatible version from fixture
+ *
+ * @param string $sampleDataVersion
+ * @return void
+ */
+ public function chooseVersionUpgradeOtherComponents($sampleDataVersion)
+ {
+ do {
+ $this->iterateAndSetComponentsRows($this->convertVersionFixtureToRegexp($sampleDataVersion));
+ if ($this->canClickOnNextPage()) {
+ $this->clickOnNextPage();
+ }
+ } while ($this->canClickOnNextPage());
+ }
+
+ /**
+ * Gets components rows as ElementInterface
+ *
+ * @return ElementInterface[]
+ */
+ private function getComponentsTableRows()
+ {
+ return $this->_rootElement->getElements("table.data-grid tbody tr");
+ }
+
+ /**
+ * Iterate through components in table and set compatible version for selected magento version
+ *
+ * @param $sampleDataVersion
+ * @return void
+ */
+ private function iterateAndSetComponentsRows($sampleDataVersion)
+ {
+ $rows = $this->getComponentsTableRows();
+ for ($rowIndex = 1; $rowIndex <= count($rows); $rowIndex++) {
+ $textElement = $this->getRowComponentTitle($rowIndex);
+ if ($this->titleContainsSampleData($textElement)) {
+ $this->setSampleDataVersionToRowSelect($rowIndex, $sampleDataVersion);
+ }
+ }
+ }
+
+ /**
+ * Clicks on Next Page of the grid
+ *
+ * @return void
+ */
+ private function clickOnNextPage()
+ {
+ $this->_rootElement->find(".admin__data-grid-pager .action-next", Locator::SELECTOR_CSS)->click();
+ }
+
+ /**
+ * Can click on next page
+ *
+ * @return bool
+ */
+ private function canClickOnNextPage()
+ {
+ $element = $this->_rootElement->find(".admin__data-grid-pager .action-next");
+ if ($element->isVisible()) {
+ return !$element->isDisabled();
+ }
+ return false;
+ }
+
+ /**
+ * Gets rows component title
+ *
+ * @param int $rowIndex
+ * @return ElementInterface
+ */
+ private function getRowComponentTitle($rowIndex)
+ {
+ return $this->_rootElement->find(
+ "//table//tbody//tr[" . $rowIndex . "]//td//*[contains(text(),'sample')]",
+ Locator::SELECTOR_XPATH
+ );
+ }
+
+ /**
+ * Gets the select element from row
+ *
+ * @param int $rowIndex
+ * @return ElementInterface
+ */
+ private function getSelectFromRow($rowIndex)
+ {
+ return $this->_rootElement->find(
+ '//table//tbody//tr[' . $rowIndex . ']//td//select',
+ Locator::SELECTOR_XPATH,
+ 'select'
+ );
+ }
+
+ /**
+ * Convert sample data version fixture to regexp format
+ * Example 100.1.* to 100\.1\.[0-9]+
+ *
+ * @param string $sampleDataVersion
+ * @return string
+ * @throws \Exception
+ */
+ private function convertVersionFixtureToRegexp($sampleDataVersion)
+ {
+ if (!preg_match('/\d+(?:\.*\d*)*/', $sampleDataVersion)) {
+ throw new \Exception('Wrong format for sample data version fixture. Example: 100.1.* needed.');
+ }
+ return str_replace('*', '[0-9]+', $sampleDataVersion);
+ }
+
+ /**
+ * Asserts if element's text contains sample data
+ *
+ * @param ElementInterface $element
+ * @return bool
+ */
+ private function titleContainsSampleData($element)
+ {
+ return preg_match('/magento\/.*sample-data/', $element->getText());
+ }
+
+ /**
+ * Sets sample data version matching the maximum compatible version from fixture
+ *
+ * @param int $rowIndex
+ * @param string $sampleDataVersionForRegex
+ * @return void
+ */
+ private function setSampleDataVersionToRowSelect($rowIndex, $sampleDataVersionForRegex)
+ {
+ $selectElement = $this->getSelectFromRow($rowIndex);
+ $optionTextArray = [];
+ foreach ($selectElement->getElements('option') as $option) {
+ $optionText = $option->getText();
+ if (preg_match('/' . $sampleDataVersionForRegex . '/', $optionText)) {
+ preg_match('/([0-9\.\-a-zA-Z]+)/', $optionText, $match);
+ $optionTextArray[$optionText] = current($match);
+ }
+ }
+
+ if (!empty($optionTextArray)) {
+ uasort(
+ $optionTextArray,
+ function ($versionOne, $versionTwo) {
+ return version_compare($versionOne, $versionTwo) * -1;
+ }
+ );
+
+ $toSelectVersion = key($optionTextArray);
+ if ($toSelectVersion !== $selectElement->getText()) {
+ $selectElement->setValue($toSelectVersion);
+ }
+ }
+ }
}
diff --git a/dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.php b/dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.php
index f5933fa91e51d..67d5b11c2b22d 100644
--- a/dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.php
+++ b/dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.php
@@ -72,6 +72,7 @@ public function test(
['data' => $createBackupConfig]
);
$version = $upgrade['upgradeVersion'];
+ $sampleDataVersion = $upgrade['sampledataVersion'];
$suffix = "( (CE|EE))$";
$normalVersion = '(0|[1-9]\d*)';
@@ -109,6 +110,7 @@ public function test(
$this->setupWizard->getSelectVersion()->fill($upgradeFixture);
if ($upgrade['otherComponents'] === 'Yes') {
$this->setupWizard->getSelectVersion()->chooseUpgradeOtherComponents();
+ $this->setupWizard->getSelectVersion()->chooseVersionUpgradeOtherComponents($sampleDataVersion);
}
$this->setupWizard->getSelectVersion()->clickNext();
diff --git a/dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.xml b/dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.xml
index 3b88f360ec156..d4b594747a93f 100644
--- a/dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.xml
+++ b/dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.xml
@@ -18,6 +18,7 @@
No
No
{otherComponents}
+ {sampledataVersion}