Skip to content

Commit ff2e0f2

Browse files
authored
Merge branch 'develop' into MQE-1677
2 parents a9ba447 + 4d600ed commit ff2e0f2

File tree

10 files changed

+108
-8
lines changed

10 files changed

+108
-8
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,66 @@ public function testEntityException(): void
8888
$this->assertArrayHasKey('sampleTest', $testErrors);
8989
}
9090

91+
/**
92+
* Basic test to check unique id is appended to input as prefix
93+
*
94+
* @return void
95+
* @throws Exception
96+
*/
97+
public function testUniqueIdAppendedToInputStringAsPrefix()
98+
{
99+
$actionObject = new ActionObject('fakeAction', 'comment', [
100+
'userInput' => '{{someEntity.entity}}'
101+
]);
102+
103+
$testObject = new TestObject('sampleTest', ['merge123' => $actionObject], [], [], 'filename');
104+
$testGeneratorObject = TestGenerator::getInstance('', ['sampleTest' => $testObject]);
105+
106+
$result = $testGeneratorObject->getUniqueIdForInput('prefix', "foo");
107+
108+
$this->assertMatchesRegularExpression('/[A-Za-z0-9]+foo/', $result);
109+
}
110+
111+
/**
112+
* Basic test to check unique id is appended to input as suffix
113+
*
114+
* @return void
115+
* @throws Exception
116+
*/
117+
public function testUniqueIdAppendedToInputStringAsSuffix()
118+
{
119+
$actionObject = new ActionObject('fakeAction', 'comment', [
120+
'userInput' => '{{someEntity.entity}}'
121+
]);
122+
123+
$testObject = new TestObject('sampleTest', ['merge123' => $actionObject], [], [], 'filename');
124+
$testGeneratorObject = TestGenerator::getInstance('', ['sampleTest' => $testObject]);
125+
126+
$result = $testGeneratorObject->getUniqueIdForInput('suffix', "foo");
127+
128+
$this->assertMatchesRegularExpression('/foo[A-Za-z0-9]+/', $result);
129+
}
130+
131+
/**
132+
* Basic test for wrong output for input
133+
*
134+
* @return void
135+
* @throws Exception
136+
*/
137+
public function testFailedRegexForUniqueAttribute()
138+
{
139+
$actionObject = new ActionObject('fakeAction', 'comment', [
140+
'userInput' => '{{someEntity.entity}}'
141+
]);
142+
143+
$testObject = new TestObject('sampleTest', ['merge123' => $actionObject], [], [], 'filename');
144+
$testGeneratorObject = TestGenerator::getInstance('', ['sampleTest' => $testObject]);
145+
146+
$result = $testGeneratorObject->getUniqueIdForInput('suffix', "foo");
147+
148+
$this->assertDoesNotMatchRegularExpression('/bar[A-Za-z0-9]+/', $result);
149+
}
150+
91151
/**
92152
* Tests that skipped tests do not have a fully generated body.
93153
*

dev/tests/verification/Resources/DataActionsTest.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class DataActionsTestCest
3232
$I->createEntity("createdInBefore", "hook", "entity", [], []); // stepKey: createdInBefore
3333
$I->updateEntity("createdInBefore", "hook", "entity",[]); // stepKey: updateInBefore
3434
$I->deleteEntity("createdInBefore", "hook"); // stepKey: deleteInBefore
35+
$customerFields['lastname'] = "foo";
36+
$I->createEntity("customer", "hook", "Simple_Customer_Without_Address", [], $customerFields); // stepKey: customer
3537
$I->comment('[END BEFORE HOOK]');
3638
}
3739

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<createData entity="entity" stepKey="createdInBefore"/>
1414
<updateData entity="entity" createDataKey="createdInBefore" stepKey="updateInBefore"/>
1515
<deleteData createDataKey="createdInBefore" stepKey="deleteInBefore"/>
16+
<createData stepKey="customer" entity="Simple_Customer_Without_Address">
17+
<field key="lastname">foo</field>
18+
</createData>
1619

1720
</before>
1821
<waitForElementClickable selector=".functionalTestSelector" time="30" stepKey="waitForElementClickable" />
@@ -23,4 +26,4 @@
2326
<updateData entity="entity" createDataKey="createdInBefore" stepKey="updatedDataOutOfScope"/>
2427
<deleteData createDataKey="createdInBefore" stepKey="deleteDataOutOfScope"/>
2528
</test>
26-
</tests>
29+
</tests>

docs/img/issue.png

-13.6 KB
Binary file not shown.

docs/img/pull-request.png

-7.47 KB
Binary file not shown.

docs/img/switching-the-base.png

-6.9 KB
Binary file not shown.

docs/img/trouble-chrome232.png

-24.8 KB
Binary file not shown.

src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class TestObject
3939
'deleteData' => 200,
4040
'updateData' => 200,
4141
'getOTP' => 1000,
42+
'startMessageQueue' => 700,
4243
];
4344

4445
const WEBAPI_AUTH_TEST_ACTIONS = [

src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,32 @@
125125
</xs:simpleContent>
126126
</xs:complexType>
127127

128+
128129
<xs:complexType name="additionalFieldType">
129-
<xs:annotation>
130-
<xs:documentation>field used to override defined fields from metadata or existing data definitions, during operation.</xs:documentation>
131-
</xs:annotation>
132130
<xs:simpleContent>
133131
<xs:extension base="xs:string">
134-
<xs:attribute name="key" use="required"/>
132+
<xs:attribute type="xs:string" name="key" use="required">
133+
<xs:annotation>
134+
<xs:documentation>xp
135+
Key attribute of data/value pair.
136+
</xs:documentation>
137+
</xs:annotation>
138+
</xs:attribute>
139+
<xs:attribute type="uniquenessEnumType" name="unique" use="optional">
140+
<xs:annotation>
141+
<xs:documentation>
142+
Add suite or test wide unique sequence as "prefix" or "suffix" to the data value if specified.
143+
</xs:documentation>
144+
</xs:annotation>
145+
</xs:attribute>
135146
</xs:extension>
136147
</xs:simpleContent>
137148
</xs:complexType>
138-
</xs:schema>
149+
150+
<xs:simpleType name="uniquenessEnumType">
151+
<xs:restriction base="xs:string">
152+
<xs:enumeration value="prefix" />
153+
<xs:enumeration value="suffix" />
154+
</xs:restriction>
155+
</xs:simpleType>
156+
</xs:schema>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,11 +1462,12 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
14621462
$actionObject->getActionOrigin()
14631463
)[0];
14641464
$argRef = "\t\t\$";
1465-
14661465
$input = $this->resolveAllRuntimeReferences([$input])[0];
1466+
$input = (isset($actionObject->getCustomActionAttributes()['unique'])) ?
1467+
$this->getUniqueIdForInput($actionObject->getCustomActionAttributes()['unique'], $input)
1468+
: $input;
14671469
$argRef .= str_replace(ucfirst($fieldKey), "", $stepKey) .
14681470
"Fields['{$fieldKey}'] = ${input};";
1469-
14701471
$testSteps .= $argRef;
14711472
break;
14721473
case "generateDate":
@@ -1513,6 +1514,21 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
15131514
return $testSteps;
15141515
}
15151516

1517+
/**
1518+
* Get unique value appended to input string
1519+
*
1520+
* @param string $uniqueValue
1521+
* @param string $input
1522+
* @return string
1523+
*/
1524+
public function getUniqueIdForInput($uniqueValue, $input)
1525+
{
1526+
$input = ($uniqueValue == 'prefix')
1527+
? '"'.uniqid().str_replace('"', '', $input).'"'
1528+
: '"'.str_replace('"', '', $input).uniqid().'"';
1529+
return $input;
1530+
}
1531+
15161532
/**
15171533
* Resolves Locator:: in given $attribute if it is found.
15181534
*

0 commit comments

Comments
 (0)