Skip to content

Commit

Permalink
Merge pull request #668 from magento-fearless-kiwis/FearlessKiwis-MAG…
Browse files Browse the repository at this point in the history
…ETWO-61950-2.1

Fixed issue:
 - MAGETWO-61950: UI Functional Upgrade Test from 2.1.x to 2.x.x. Components Version Support
  • Loading branch information
Oleksii Korshenko authored Dec 15, 2016
2 parents 7d6b7d2 + adeed94 commit a21c443
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -71,4 +72,161 @@ public function chooseUpgradeOtherComponents()
$this->waitForElementVisible($this->loader);
$this->waitForElementNotVisible($this->loader);
}

/**
* 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));
} 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()) {
$result = !$element->isDisabled();
$this->clickOnNextPage();
return $result;
}
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function test(
['data' => $createBackupConfig]
);
$version = $upgrade['upgradeVersion'];
$sampleDataVersion = $upgrade['sampledataVersion'];

$suffix = "( (CE|EE))$";
$normalVersion = '(0|[1-9]\d*)';
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<data name="upgrade/optionsMedia" xsi:type="string">No</data>
<data name="upgrade/optionsDb" xsi:type="string">No</data>
<data name="upgrade/otherComponents" xsi:type="string">{otherComponents}</data>
<data name="upgrade/sampledataVersion" xsi:type="string">{sampledataVersion}</data>
</variation>
</testCase>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected function setUp()
*/
public function testValidateHasRecursiveReference()
{
$this->markTestSkipped("MAGETWO-59802:BuildFailureforL2onbranch2.1-develop");
$fieldConfig = [
'path' => 'design/email/header_template',
'fieldset' => 'other_settings/email',
Expand Down

0 comments on commit a21c443

Please sign in to comment.