Skip to content

Commit 2e1b1a2

Browse files
Manjusha.SManjusha.S
Manjusha.S
authored and
Manjusha.S
committed
MQE-2021 : Added unit test
1 parent 2702cae commit 2e1b1a2

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

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

+60
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
*

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+18-5
Original file line numberDiff line numberDiff line change
@@ -1463,11 +1463,9 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
14631463
)[0];
14641464
$argRef = "\t\t\$";
14651465
$input = $this->resolveAllRuntimeReferences([$input])[0];
1466-
if (isset($actionObject->getCustomActionAttributes()['unique'])) {
1467-
$input = ($actionObject->getCustomActionAttributes()['unique'] == 'prefix')
1468-
? '"'.uniqid().str_replace('"', '', $input).'"'
1469-
: '"'.str_replace('"', '', $input).uniqid().'"';
1470-
}
1466+
$input = (isset($actionObject->getCustomActionAttributes()['unique'])) ?
1467+
$this->getUniqueIdForInput( $actionObject->getCustomActionAttributes()['unique'], $input)
1468+
: $input;
14711469
$argRef .= str_replace(ucfirst($fieldKey), "", $stepKey) .
14721470
"Fields['{$fieldKey}'] = ${input};";
14731471
$testSteps .= $argRef;
@@ -1516,6 +1514,21 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
15161514
return $testSteps;
15171515
}
15181516

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+
15191532
/**
15201533
* Resolves Locator:: in given $attribute if it is found.
15211534
*

0 commit comments

Comments
 (0)