Skip to content

Commit f00b2ff

Browse files
authored
MQE-914: Multiple Uniqueness References On Same Entity Generates Incorrectly
- refactored uniquenessFunctionCall in TestGenerator; fixes bug. - updated verification tests to catch test case.
1 parent 586fd5c commit f00b2ff

7 files changed

+46
-51
lines changed

dev/tests/verification/Resources/ActionGroupWithPassedArgumentAndStringSelectorParam.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ class ActionGroupWithPassedArgumentAndStringSelectorParamCest
2929
*/
3030
public function ActionGroupWithPassedArgumentAndStringSelectorParam(AcceptanceTester $I)
3131
{
32-
$I->see("John".msq("UniquePerson"), "#element .test1");
32+
$I->see("John" . msq("UniquePerson"), "#element .test1");
3333
}
3434
}

dev/tests/verification/Resources/ActionGroupWithSingleParameterSelectorFromPassedArgument.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ class ActionGroupWithSingleParameterSelectorFromPassedArgumentCest
2929
*/
3030
public function ActionGroupWithSingleParameterSelectorFromPassedArgument(AcceptanceTester $I)
3131
{
32-
$I->see("Doe", "#element .John".msq("UniquePerson"));
32+
$I->see("Doe", "#element .John" . msq("UniquePerson"));
3333
}
3434
}

dev/tests/verification/Resources/DataReplacementTest.txt

+16-14
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,22 @@ class DataReplacementTestCest
3333
$I->conditionalClick("Doe", "#John", true);
3434
$I->amOnUrl("John.html");
3535
$I->searchAndMultiSelectOption("#selector", ["John", "Doe"]);
36-
$I->fillField("#selector", "StringBefore ".msq("uniqueData")."John StringAfter");
37-
$I->fillField("#".msq("uniqueData")."John", "input");
38-
$I->dragAndDrop("#".msq("uniqueData")."John", msq("uniqueData")."John");
39-
$I->conditionalClick(msq("uniqueData")."John", "#".msq("uniqueData")."John", true);
40-
$I->amOnUrl(msq("uniqueData")."John.html");
41-
$I->searchAndMultiSelectOption("#selector", [msq("uniqueData")."John", "Doe"]);
42-
$I->fillField("#selector", "StringBefore Doe".msq("uniqueData")." StringAfter");
43-
$I->fillField("#Doe".msq("uniqueData"), "input");
44-
$I->dragAndDrop("#Doe".msq("uniqueData"), "Doe".msq("uniqueData"));
45-
$I->conditionalClick("Doe".msq("uniqueData"), "#Doe".msq("uniqueData"), true);
46-
$I->amOnUrl("Doe".msq("uniqueData").".html");
47-
$I->searchAndMultiSelectOption("#selector", ["John", "Doe".msq("uniqueData")]);
48-
$I->searchAndMultiSelectOption("#selector", [msq("uniqueData")."John", "Doe".msq("uniqueData")]);
49-
$I->selectMultipleOptions("#Doe".msq("uniqueData"), "#element", [msq("uniqueData")."John", "Doe".msq("uniqueData")]);
36+
$I->fillField("#selector", "StringBefore " . msq("uniqueData") . "John StringAfter");
37+
$I->fillField("#" . msq("uniqueData") . "John", "input");
38+
$I->dragAndDrop("#" . msq("uniqueData") . "John", msq("uniqueData") . "John");
39+
$I->conditionalClick(msq("uniqueData") . "John", "#" . msq("uniqueData") . "John", true);
40+
$I->amOnUrl(msq("uniqueData") . "John.html");
41+
$I->searchAndMultiSelectOption("#selector", [msq("uniqueData") . "John", "Doe"]);
42+
$I->click("#" . msq("uniqueData") . "John#" . msq("uniqueData") . "John");
43+
$I->click("#Doe" . msq("uniqueData") . "#Doe" . msq("uniqueData"));
44+
$I->fillField("#selector", "StringBefore Doe" . msq("uniqueData") . " StringAfter");
45+
$I->fillField("#Doe" . msq("uniqueData"), "input");
46+
$I->dragAndDrop("#Doe" . msq("uniqueData"), "Doe" . msq("uniqueData"));
47+
$I->conditionalClick("Doe" . msq("uniqueData"), "#Doe" . msq("uniqueData"), true);
48+
$I->amOnUrl("Doe" . msq("uniqueData") . ".html");
49+
$I->searchAndMultiSelectOption("#selector", ["John", "Doe" . msq("uniqueData")]);
50+
$I->searchAndMultiSelectOption("#selector", [msq("uniqueData") . "John", "Doe" . msq("uniqueData")]);
51+
$I->selectMultipleOptions("#Doe" . msq("uniqueData"), "#element", [msq("uniqueData") . "John", "Doe" . msq("uniqueData")]);
5052
$I->fillField(".selector", "0");
5153
}
5254
}

dev/tests/verification/Resources/ParameterArrayTest.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ class ParameterArrayTestCest
3232
$simpleDataKey = new DataPersistenceHandler($simpleParamData, []);
3333
$simpleDataKey->createEntity();
3434
$I->searchAndMultiSelectOption("#selector", ["name"]);
35-
$I->searchAndMultiSelectOption("#selector", [msq("simpleParamData")."prename"]);
36-
$I->searchAndMultiSelectOption("#selector", ["postname".msq("simpleParamData")]);
35+
$I->searchAndMultiSelectOption("#selector", [msq("simpleParamData") . "prename"]);
36+
$I->searchAndMultiSelectOption("#selector", ["postname" . msq("simpleParamData")]);
3737
$I->searchAndMultiSelectOption("#selector", [$simpleDataKey->getCreatedDataByName('name')]);
3838
$I->searchAndMultiSelectOption("#selector", ["name", $simpleDataKey->getCreatedDataByName('name')]);
3939
$I->searchAndMultiSelectOption("#selector", ['someKey' => $simpleDataKey->getCreatedDataByName('name')]);
4040
$I->searchAndMultiSelectOption("#selector", ['someKey' => "name"]);
41-
$I->searchAndMultiSelectOption("#selector", ['someKey' => msq("simpleParamData")."prename"]);
42-
$I->searchAndMultiSelectOption("#selector", ['someKey' => "postname".msq("simpleParamData")]);
41+
$I->searchAndMultiSelectOption("#selector", ['someKey' => msq("simpleParamData") . "prename"]);
42+
$I->searchAndMultiSelectOption("#selector", ['someKey' => "postname" . msq("simpleParamData")]);
4343
$I->unselectOption("#selector", ['foo']);
4444
$I->unselectOption("#selector", ['foo', 'bar']);
4545
$I->unselectOption("#selector", ["name"]);
46-
$I->unselectOption("#selector", [msq("simpleParamData")."prename"]);
47-
$I->unselectOption("#selector", ["postname".msq("simpleParamData")]);
46+
$I->unselectOption("#selector", [msq("simpleParamData") . "prename"]);
47+
$I->unselectOption("#selector", ["postname" . msq("simpleParamData")]);
4848
$I->unselectOption("#selector", [$simpleDataKey->getCreatedDataByName('name')]);
4949
$I->unselectOption("#selector", ["name", $simpleDataKey->getCreatedDataByName('name')]);
5050
}

dev/tests/verification/Resources/SectionReplacementTest.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ class SectionReplacementTestCest
3838
$I->click("#John .Doe");
3939
$I->click("#John-Doe .Tiberius");
4040
$I->click("#John-Doe .John [Tiberius]");
41-
$I->click("#element .".msq("uniqueData")."John");
42-
$I->click("#".msq("uniqueData")."John .stringLiteral2");
43-
$I->click("#".msq("uniqueData")."John-stringLiteral2 .stringLiteral3");
44-
$I->click("#".msq("uniqueData")."John-stringLiteral2 .");
45-
$I->click("#element .Doe".msq("uniqueData"));
46-
$I->click("#Doe".msq("uniqueData")." .stringLiteral2");
47-
$I->click("#Doe".msq("uniqueData")."-stringLiteral2 .stringLiteral3");
48-
$I->click("#Doe".msq("uniqueData")."-stringLiteral2 .Doe");
41+
$I->click("#element ." . msq("uniqueData") . "John");
42+
$I->click("#" . msq("uniqueData") . "John .stringLiteral2");
43+
$I->click("#" . msq("uniqueData") . "John-stringLiteral2 .stringLiteral3");
44+
$I->click("#" . msq("uniqueData") . "John-stringLiteral2 ." . msq("uniqueData") . "John [stringLiteral3]");
45+
$I->click("#element .Doe" . msq("uniqueData"));
46+
$I->click("#Doe" . msq("uniqueData") . " .stringLiteral2");
47+
$I->click("#Doe" . msq("uniqueData") . "-stringLiteral2 .stringLiteral3");
48+
$I->click("#Doe" . msq("uniqueData") . "-stringLiteral2 .Doe" . msq("uniqueData") . " [stringLiteral3]");
4949
$I->amGoingTo("create entity that has the stepKey: createdData");
5050
$simpleData = DataObjectHandler::getInstance()->getObject("simpleData");
5151
$createdData = new DataPersistenceHandler($simpleData, []);
@@ -60,7 +60,7 @@ class SectionReplacementTestCest
6060
$I->click("#John-Doe .John [Tiberius]");
6161
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " .John");
6262
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " .{$data}");
63-
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " .".msq("uniqueData")."John");
64-
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " .Doe".msq("uniqueData"));
63+
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " ." . msq("uniqueData") . "John");
64+
$I->click("#stringLiteral1-" . $createdData->getCreatedDataByName('firstname') . " .Doe" . msq("uniqueData"));
6565
}
6666
}

dev/tests/verification/TestModule/Test/DataReplacementTest.xml

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<conditionalClick stepKey="dependentSelectorReplaceMSQPrefix" dependentSelector="#{{uniqueData.firstname}}" selector="{{uniqueData.firstname}}" visible="true"/>
2323
<amOnUrl stepKey="urlReplaceMSQPrefix" url="{{uniqueData.firstname}}.html"/>
2424
<searchAndMultiSelectOption stepKey="parameterArrayReplacementMSQPrefix" selector="#selector" parameterArray="[{{uniqueData.firstname}}, {{simpleData.lastname}}]"/>
25+
<click stepKey="selectorReplaceDupedMSQPrefix" selector="#{{uniqueData.firstname}}#{{uniqueData.firstname}}"/>
26+
<click stepKey="selectorReplaceDupedMSQSuffix" selector="#{{uniqueData.lastname}}#{{uniqueData.lastname}}"/>
2527

2628
<fillField stepKey="inputReplaceMSQSuffix" selector="#selector" userInput="StringBefore {{uniqueData.lastname}} StringAfter"/>
2729
<fillField stepKey="selectorReplaceMSQSuffix" selector="#{{uniqueData.lastname}}" userInput="input"/>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+10-19
Original file line numberDiff line numberDiff line change
@@ -1576,26 +1576,17 @@ private function addUniquenessToParamArray($input)
15761576
*/
15771577
private function addUniquenessFunctionCall($input)
15781578
{
1579-
$output = '';
1580-
1581-
preg_match('/' . EntityDataObject::CEST_UNIQUE_FUNCTION . '\("[\w]+"\)/', $input, $matches);
1582-
if (!empty($matches)) {
1583-
$parts = preg_split('/' . EntityDataObject::CEST_UNIQUE_FUNCTION . '\("[\w]+"\)/', $input, -1);
1584-
for ($i = 0; $i < count($parts); $i++) {
1585-
$parts[$i] = $this->stripWrappedQuotes($parts[$i]);
1586-
}
1587-
if (!empty($parts[0])) {
1588-
$output = $this->wrapWithDoubleQuotes($parts[0]);
1589-
}
1590-
$output .= $output === '' ? $matches[0] : '.' . $matches[0];
1591-
if (!empty($parts[1])) {
1592-
$output .= '.' . $this->wrapWithDoubleQuotes($parts[1]);
1593-
}
1594-
} else {
1595-
$output = $this->wrapWithDoubleQuotes($input);
1579+
$output = $this->wrapWithDoubleQuotes($input);
1580+
1581+
//Match on msq(\"entityName\")
1582+
preg_match_all('/' . EntityDataObject::CEST_UNIQUE_FUNCTION . '\(\\\\"[\w]+\\\\"\)/', $output, $matches);
1583+
foreach (array_unique($matches[0]) as $match) {
1584+
preg_match('/\\\\"([\w]+)\\\\"/', $match, $entityMatch);
1585+
$entity = $entityMatch[1];
1586+
$output = str_replace($match, '" . msq("' . $entity . '") . "', $output);
15961587
}
1597-
1598-
return $output;
1588+
// trim unnecessary "" . and . ""
1589+
return preg_replace('/(?(?<![\\\\])"" \. )| \. ""/', "", $output);
15991590
}
16001591

16011592
/**

0 commit comments

Comments
 (0)