Skip to content

Commit 99156d2

Browse files
authored
Merge pull request magento#192 from magento/develop
MFTF 2.3.2: Merging develop to master
2 parents 659cca0 + 5b8dbf8 commit 99156d2

File tree

11 files changed

+191
-7
lines changed

11 files changed

+191
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Magento Functional Testing Framework Changelog
22
================================================
33

4+
2.3.2
5+
-----
6+
### Fixes
7+
* The `executeJs` `function` no longer escapes persisted variables referenced via `$$persisted.key$$`.
8+
* Extending a test no longer fails to generate the parent `test`'s `before`/`after` blocks if the parent was skipped.
9+
410
2.3.1
511
-----
612
### Enhancements

dev/tests/verification/Resources/ExecuteJsEscapingTest.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ class ExecuteJsEscapingTestCest
3131
{
3232
$javaVariableEscape = $I->executeJS("return \$javascriptVariable");
3333
$mftfVariableNotEscaped = $I->executeJS("return {$doNotEscape}");
34+
$persistedDataNotEscaped = $I->executeJS("return " . $persisted->getCreatedDataByName('data'));
35+
$hookPersistedDataNotEscaped = $I->executeJS("return " . $this->persisted->getCreatedDataByName('data'));
36+
$addNewAttributeForRule = $I->executeJS("document.querySelector('entity option[value=" . $this->productAttribute->getCreatedDataByName('attribute_code') . "]').setAttribute('selected', 'selected')");
3437
}
3538
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_default\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
9+
use \Codeception\Util\Locator;
10+
use Yandex\Allure\Adapter\Annotation\Features;
11+
use Yandex\Allure\Adapter\Annotation\Stories;
12+
use Yandex\Allure\Adapter\Annotation\Title;
13+
use Yandex\Allure\Adapter\Annotation\Description;
14+
use Yandex\Allure\Adapter\Annotation\Parameter;
15+
use Yandex\Allure\Adapter\Annotation\Severity;
16+
use Yandex\Allure\Adapter\Model\SeverityLevel;
17+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
18+
19+
/**
20+
* @Title("ChildExtendedTestSkippedParent")
21+
* @group Child
22+
*/
23+
class ExtendingSkippedTestCest
24+
{
25+
/**
26+
* @param AcceptanceTester $I
27+
* @throws \Exception
28+
*/
29+
public function _before(AcceptanceTester $I)
30+
{
31+
$I->amOnPage("/beforeUrl");
32+
}
33+
34+
/**
35+
* @param AcceptanceTester $I
36+
* @throws \Exception
37+
*/
38+
public function _after(AcceptanceTester $I)
39+
{
40+
$I->amOnPage("/afterUrl");
41+
}
42+
43+
/**
44+
* @param AcceptanceTester $I
45+
* @throws \Exception
46+
*/
47+
public function _failed(AcceptanceTester $I)
48+
{
49+
$I->saveScreenshot();
50+
}
51+
52+
/**
53+
* @Severity(level = SeverityLevel::CRITICAL)
54+
* @Features({"TestModule"})
55+
* @Stories({"Child"})
56+
* @Parameter(name = "AcceptanceTester", value="$I")
57+
* @param AcceptanceTester $I
58+
* @return void
59+
* @throws \Exception
60+
*/
61+
public function ExtendingSkippedTest(AcceptanceTester $I)
62+
{
63+
$I->comment("text");
64+
$I->comment("child");
65+
}
66+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_default\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
9+
use \Codeception\Util\Locator;
10+
use Yandex\Allure\Adapter\Annotation\Features;
11+
use Yandex\Allure\Adapter\Annotation\Stories;
12+
use Yandex\Allure\Adapter\Annotation\Title;
13+
use Yandex\Allure\Adapter\Annotation\Description;
14+
use Yandex\Allure\Adapter\Annotation\Parameter;
15+
use Yandex\Allure\Adapter\Annotation\Severity;
16+
use Yandex\Allure\Adapter\Model\SeverityLevel;
17+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
18+
19+
/**
20+
* @Title("skippedTestWithHooks")
21+
* @Description("")
22+
*/
23+
class SkippedTestWithHooksCest
24+
{
25+
/**
26+
* @Stories({"skippedWithHooks"})
27+
* @Severity(level = SeverityLevel::MINOR)
28+
* @Features({"TestModule"})
29+
* @Parameter(name = "AcceptanceTester", value="$I")
30+
* @param AcceptanceTester $I
31+
* @return void
32+
* @throws \Exception
33+
*/
34+
public function SkippedTestWithHooks(AcceptanceTester $I, \Codeception\Scenario $scenario)
35+
{
36+
$scenario->skip("This test is skipped due to the following issues:\nSkippedValue");
37+
}
38+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
<test name="ExecuteJsEscapingTest">
1212
<executeJS function="return $javascriptVariable" stepKey="javaVariableEscape"/>
1313
<executeJS function="return {$doNotEscape}" stepKey="mftfVariableNotEscaped"/>
14+
<executeJS function="return $persisted.data$" stepKey="persistedDataNotEscaped"/>
15+
<executeJS function="return $$persisted.data$$" stepKey="hookPersistedDataNotEscaped"/>
16+
<executeJS function="document.querySelector('entity option[value=$$productAttribute.attribute_code$$]').setAttribute('selected', 'selected')" stepKey="addNewAttributeForRule"/>
1417
</test>
1518
</tests>

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
<remove keyForRemoval="beforeAmOnPageKey"/>
117117
</before>
118118
</test>
119-
120119
<test name="ChildExtendedTestNoParent" extends="ThisTestDoesNotExist">
121120
<annotations>
122121
<severity value="CRITICAL"/>
@@ -129,4 +128,34 @@
129128
<remove keyForRemoval="beforeAmOnPageKey"/>
130129
</before>
131130
</test>
131+
<test name="SkippedParent">
132+
<annotations>
133+
<severity value="CRITICAL"/>
134+
<title value="PARENTSKIPPED"/>
135+
<group value="Parent"/>
136+
<features value="Parent"/>
137+
<stories value="Parent"/>
138+
<skip>
139+
<issueId value="NONE"/>
140+
</skip>
141+
</annotations>
142+
<before>
143+
<amOnPage url="/beforeUrl" stepKey="beforeAmOnPageKey"/>
144+
</before>
145+
<after>
146+
<amOnPage url="/afterUrl" stepKey="afterAmOnPageKey"/>
147+
</after>
148+
<comment userInput="text" stepKey="keepMe"/>
149+
<comment userInput="text" stepKey="replaceMe"/>
150+
</test>
151+
<test name="ExtendingSkippedTest" extends="SkippedParent">
152+
<annotations>
153+
<severity value="CRITICAL"/>
154+
<title value="ChildExtendedTestSkippedParent"/>
155+
<group value="Child"/>
156+
<features value="Child"/>
157+
<stories value="Child"/>
158+
</annotations>
159+
<comment userInput="child" stepKey="replaceMe"/>
160+
</test>
132161
</tests>

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
</skip>
2020
</annotations>
2121
</test>
22+
<test name="SkippedTestWithHooks">
23+
<annotations>
24+
<stories value="skippedWithHooks"/>
25+
<title value="skippedTestWithHooks"/>
26+
<description value=""/>
27+
<severity value="AVERAGE"/>
28+
<skip>
29+
<issueId value="SkippedValue"/>
30+
</skip>
31+
</annotations>
32+
<before>
33+
<comment userInput="skippedComment" stepKey="beforeComment"/>
34+
</before>
35+
<after>
36+
<comment userInput="skippedComment" stepKey="afterComment"/>
37+
</after>
38+
</test>
2239
<test name="SkippedTestTwoIssues">
2340
<annotations>
2441
<stories value="skippedMultiple"/>

dev/tests/verification/Tests/ExtendedGenerationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,15 @@ public function testExtendedTestGenerationNoParent()
9696
{
9797
$this->generateAndCompareTest('ChildExtendedTestNoParent');
9898
}
99+
100+
/**
101+
* Tests extending a skipped test generation.
102+
*
103+
* @throws \Exception
104+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
105+
*/
106+
public function testExtendingSkippedGeneration()
107+
{
108+
$this->generateAndCompareTest('ExtendingSkippedTest');
109+
}
99110
}

dev/tests/verification/Tests/SkippedGenerationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ public function testSkippedGeneration()
2020
$this->generateAndCompareTest('SkippedTest');
2121
}
2222

23+
/**
24+
* Tests skipped test generation does not generate hooks.
25+
*
26+
* @throws \Exception
27+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
28+
*/
29+
public function testSkippedWithHooksGeneration()
30+
{
31+
$this->generateAndCompareTest('SkippedTestWithHooks');
32+
}
33+
2334
/**
2435
* Tests skipped test with multiple issues generation.
2536
*

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ public function getAnnotations()
168168
*/
169169
public function getHooks()
170170
{
171-
// if this test is skipped we do not want any before/after actions to generate as the tests will not run
172-
if ($this->isSkipped()) {
173-
return [];
174-
}
175171
return $this->hooks;
176172
}
177173

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ private function assembleTestPhp($testObject)
207207

208208
$className = $testObject->getCodeceptionName();
209209
try {
210-
$hookPhp = $this->generateHooksPhp($testObject->getHooks());
210+
if (!$testObject->isSkipped()) {
211+
$hookPhp = $this->generateHooksPhp($testObject->getHooks());
212+
} else {
213+
$hookPhp = null;
214+
}
211215
$testsPhp = $this->generateTestPhp($testObject);
212216
} catch (TestReferenceException $e) {
213217
throw new TestReferenceException($e->getMessage() . "\n" . $testObject->getFilename());
@@ -620,7 +624,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
620624
}
621625
// turn $javaVariable => \$javaVariable but not {$mftfVariable}
622626
if ($actionObject->getType() == "executeJS") {
623-
$function = preg_replace('/(?<!{)(\$[\w\d_]+)/', '\\\\$1', $function);
627+
$function = preg_replace('/(?<!{)(\$[A-Za-z._]+)(?![A-z.]*+\$)/', '\\\\$1', $function);
624628
}
625629
}
626630

0 commit comments

Comments
 (0)