Skip to content

Commit c2d8078

Browse files
MAGETWO-61950: UI Functional Upgrade Test from 2.1.x to 2.x.x. Components Version Support
- add functionality to select minimum compatible version for selected version with sample data - fix last page bug
1 parent 7d6b7d2 commit c2d8078

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

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

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Mtf\Client\Element\SimpleElement;
1111
use Magento\Mtf\Client\Locator;
1212
use Magento\Mtf\Fixture\FixtureInterface;
13+
use Magento\Mtf\Client\ElementInterface;
1314

1415
/**
1516
* Select version block.
@@ -71,4 +72,161 @@ public function chooseUpgradeOtherComponents()
7172
$this->waitForElementVisible($this->loader);
7273
$this->waitForElementNotVisible($this->loader);
7374
}
75+
76+
/**
77+
* Set maximum compatible sample data for each row
78+
* Iterates through each page of the grid and sets the compatible version from fixture
79+
*
80+
* @param string $sampleDataVersion
81+
* @return void
82+
*/
83+
public function chooseVersionUpgradeOtherComponents($sampleDataVersion)
84+
{
85+
do {
86+
$this->iterateAndSetComponentsRows($this->convertVersionFixtureToRegexp($sampleDataVersion));
87+
} while ($this->canClickOnNextPage());
88+
}
89+
90+
/**
91+
* Gets components rows as ElementInterface
92+
*
93+
* @return ElementInterface[]
94+
*/
95+
private function getComponentsTableRows()
96+
{
97+
return $this->_rootElement->getElements("table.data-grid tbody tr");
98+
}
99+
100+
/**
101+
* Iterate through components in table and set compatible version for selected magento version
102+
*
103+
* @param $sampleDataVersion
104+
* @return void
105+
*/
106+
private function iterateAndSetComponentsRows($sampleDataVersion)
107+
{
108+
$rows = $this->getComponentsTableRows();
109+
for ($rowIndex = 1; $rowIndex <= count($rows); $rowIndex++) {
110+
$textElement = $this->getRowComponentTitle($rowIndex);
111+
if ($this->titleContainsSampleData($textElement)) {
112+
$this->setSampleDataVersionToRowSelect($rowIndex, $sampleDataVersion);
113+
}
114+
}
115+
}
116+
117+
/**
118+
* Clicks on Next Page of the grid
119+
*
120+
* @return void
121+
*/
122+
private function clickOnNextPage()
123+
{
124+
$this->_rootElement->find(".admin__data-grid-pager .action-next", Locator::SELECTOR_CSS)->click();
125+
}
126+
127+
/**
128+
* Can click on next page
129+
*
130+
* @return bool
131+
*/
132+
private function canClickOnNextPage()
133+
{
134+
$element = $this->_rootElement->find(".admin__data-grid-pager .action-next");
135+
if ($element->isVisible()) {
136+
$result = !$element->isDisabled();
137+
$this->clickOnNextPage();
138+
return $result;
139+
}
140+
return false;
141+
}
142+
143+
/**
144+
* Gets rows component title
145+
*
146+
* @param int $rowIndex
147+
* @return ElementInterface
148+
*/
149+
private function getRowComponentTitle($rowIndex)
150+
{
151+
return $this->_rootElement->find(
152+
"//table//tbody//tr[" . $rowIndex . "]//td//*[contains(text(),'sample')]",
153+
Locator::SELECTOR_XPATH
154+
);
155+
}
156+
157+
/**
158+
* Gets the select element from row
159+
*
160+
* @param int $rowIndex
161+
* @return ElementInterface
162+
*/
163+
private function getSelectFromRow($rowIndex)
164+
{
165+
return $this->_rootElement->find(
166+
'//table//tbody//tr[' . $rowIndex . ']//td//select',
167+
Locator::SELECTOR_XPATH,
168+
'select'
169+
);
170+
}
171+
172+
/**
173+
* Convert sample data version fixture to regexp format
174+
* Example 100.1.* to 100\.1\.[0-9]+
175+
*
176+
* @param string $sampleDataVersion
177+
* @return string
178+
* @throws \Exception
179+
*/
180+
private function convertVersionFixtureToRegexp($sampleDataVersion)
181+
{
182+
if (!preg_match('/\d+(?:\.*\d*)*/', $sampleDataVersion)) {
183+
throw new \Exception('Wrong format for sample data version fixture. Example: 100.1.* needed.');
184+
}
185+
return str_replace('*', '[0-9]+', $sampleDataVersion);
186+
}
187+
188+
/**
189+
* Asserts if element's text contains sample data
190+
*
191+
* @param ElementInterface $element
192+
* @return bool
193+
*/
194+
private function titleContainsSampleData($element)
195+
{
196+
return preg_match('/magento\/.*sample-data/', $element->getText());
197+
}
198+
199+
/**
200+
* Sets sample data version matching the maximum compatible version from fixture
201+
*
202+
* @param int $rowIndex
203+
* @param string $sampleDataVersionForRegex
204+
* @return void
205+
*/
206+
private function setSampleDataVersionToRowSelect($rowIndex, $sampleDataVersionForRegex)
207+
{
208+
$selectElement = $this->getSelectFromRow($rowIndex);
209+
$optionTextArray = [];
210+
foreach ($selectElement->getElements('option') as $option) {
211+
$optionText = $option->getText();
212+
if (preg_match('/' . $sampleDataVersionForRegex . '/', $optionText)) {
213+
preg_match('/([0-9\.\-a-zA-Z]+)/', $optionText, $match);
214+
$optionTextArray[$optionText] = current($match);
215+
}
216+
}
217+
218+
if (!empty($optionTextArray)) {
219+
uasort(
220+
$optionTextArray,
221+
function ($versionOne, $versionTwo) {
222+
return version_compare($versionOne, $versionTwo) * -1;
223+
}
224+
);
225+
226+
$toSelectVersion = key($optionTextArray);
227+
if ($toSelectVersion !== $selectElement->getText()) {
228+
$selectElement->setValue($toSelectVersion);
229+
}
230+
}
231+
}
74232
}

dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function test(
7272
['data' => $createBackupConfig]
7373
);
7474
$version = $upgrade['upgradeVersion'];
75+
$sampleDataVersion = $upgrade['sampledataVersion'];
7576

7677
$suffix = "( (CE|EE))$";
7778
$normalVersion = '(0|[1-9]\d*)';
@@ -109,6 +110,7 @@ public function test(
109110
$this->setupWizard->getSelectVersion()->fill($upgradeFixture);
110111
if ($upgrade['otherComponents'] === 'Yes') {
111112
$this->setupWizard->getSelectVersion()->chooseUpgradeOtherComponents();
113+
$this->setupWizard->getSelectVersion()->chooseVersionUpgradeOtherComponents($sampleDataVersion);
112114
}
113115
$this->setupWizard->getSelectVersion()->clickNext();
114116

dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<data name="upgrade/optionsMedia" xsi:type="string">No</data>
1919
<data name="upgrade/optionsDb" xsi:type="string">No</data>
2020
<data name="upgrade/otherComponents" xsi:type="string">{otherComponents}</data>
21+
<data name="upgrade/sampledataVersion" xsi:type="string">{sampledataVersion}</data>
2122
</variation>
2223
</testCase>
2324
</config>

0 commit comments

Comments
 (0)