diff --git a/CHANGELOG.md b/CHANGELOG.md index 61a27806b..19849c241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Magento Functional Testing Framework Changelog ================================================ +2.3.2 +----- +### Fixes +* The `executeJs` `function` no longer escapes persisted variables referenced via `$$persisted.key$$`. +* Extending a test no longer fails to generate the parent `test`'s `before`/`after` blocks if the parent was skipped. + 2.3.1 ----- ### Enhancements diff --git a/dev/tests/verification/Resources/ExecuteJsEscapingTest.txt b/dev/tests/verification/Resources/ExecuteJsEscapingTest.txt index 94dc2cbdb..371eb3d0d 100644 --- a/dev/tests/verification/Resources/ExecuteJsEscapingTest.txt +++ b/dev/tests/verification/Resources/ExecuteJsEscapingTest.txt @@ -31,5 +31,8 @@ class ExecuteJsEscapingTestCest { $javaVariableEscape = $I->executeJS("return \$javascriptVariable"); $mftfVariableNotEscaped = $I->executeJS("return {$doNotEscape}"); + $persistedDataNotEscaped = $I->executeJS("return " . $persisted->getCreatedDataByName('data')); + $hookPersistedDataNotEscaped = $I->executeJS("return " . $this->persisted->getCreatedDataByName('data')); + $addNewAttributeForRule = $I->executeJS("document.querySelector('entity option[value=" . $this->productAttribute->getCreatedDataByName('attribute_code') . "]').setAttribute('selected', 'selected')"); } } diff --git a/dev/tests/verification/Resources/ExtendingSkippedTest.txt b/dev/tests/verification/Resources/ExtendingSkippedTest.txt new file mode 100644 index 000000000..35cd3a825 --- /dev/null +++ b/dev/tests/verification/Resources/ExtendingSkippedTest.txt @@ -0,0 +1,66 @@ +amOnPage("/beforeUrl"); + } + + /** + * @param AcceptanceTester $I + * @throws \Exception + */ + public function _after(AcceptanceTester $I) + { + $I->amOnPage("/afterUrl"); + } + + /** + * @param AcceptanceTester $I + * @throws \Exception + */ + public function _failed(AcceptanceTester $I) + { + $I->saveScreenshot(); + } + + /** + * @Severity(level = SeverityLevel::CRITICAL) + * @Features({"TestModule"}) + * @Stories({"Child"}) + * @Parameter(name = "AcceptanceTester", value="$I") + * @param AcceptanceTester $I + * @return void + * @throws \Exception + */ + public function ExtendingSkippedTest(AcceptanceTester $I) + { + $I->comment("text"); + $I->comment("child"); + } +} diff --git a/dev/tests/verification/Resources/SkippedTestWithHooks.txt b/dev/tests/verification/Resources/SkippedTestWithHooks.txt new file mode 100644 index 000000000..d28c61486 --- /dev/null +++ b/dev/tests/verification/Resources/SkippedTestWithHooks.txt @@ -0,0 +1,38 @@ +skip("This test is skipped due to the following issues:\nSkippedValue"); + } +} diff --git a/dev/tests/verification/TestModule/Test/ExecuteJsTest.xml b/dev/tests/verification/TestModule/Test/ExecuteJsTest.xml index 2429fa484..b361cdd28 100644 --- a/dev/tests/verification/TestModule/Test/ExecuteJsTest.xml +++ b/dev/tests/verification/TestModule/Test/ExecuteJsTest.xml @@ -11,5 +11,8 @@ + + + diff --git a/dev/tests/verification/TestModule/Test/ExtendedFunctionalTest.xml b/dev/tests/verification/TestModule/Test/ExtendedFunctionalTest.xml index 602b9a02c..9d50f7197 100644 --- a/dev/tests/verification/TestModule/Test/ExtendedFunctionalTest.xml +++ b/dev/tests/verification/TestModule/Test/ExtendedFunctionalTest.xml @@ -116,7 +116,6 @@ - @@ -129,4 +128,34 @@ + + + + + <group value="Parent"/> + <features value="Parent"/> + <stories value="Parent"/> + <skip> + <issueId value="NONE"/> + </skip> + </annotations> + <before> + <amOnPage url="/beforeUrl" stepKey="beforeAmOnPageKey"/> + </before> + <after> + <amOnPage url="/afterUrl" stepKey="afterAmOnPageKey"/> + </after> + <comment userInput="text" stepKey="keepMe"/> + <comment userInput="text" stepKey="replaceMe"/> + </test> + <test name="ExtendingSkippedTest" extends="SkippedParent"> + <annotations> + <severity value="CRITICAL"/> + <title value="ChildExtendedTestSkippedParent"/> + <group value="Child"/> + <features value="Child"/> + <stories value="Child"/> + </annotations> + <comment userInput="child" stepKey="replaceMe"/> + </test> </tests> \ No newline at end of file diff --git a/dev/tests/verification/TestModule/Test/SkippedTest.xml b/dev/tests/verification/TestModule/Test/SkippedTest.xml index bceb619f8..7641e270e 100644 --- a/dev/tests/verification/TestModule/Test/SkippedTest.xml +++ b/dev/tests/verification/TestModule/Test/SkippedTest.xml @@ -19,6 +19,23 @@ </skip> </annotations> </test> + <test name="SkippedTestWithHooks"> + <annotations> + <stories value="skippedWithHooks"/> + <title value="skippedTestWithHooks"/> + <description value=""/> + <severity value="AVERAGE"/> + <skip> + <issueId value="SkippedValue"/> + </skip> + </annotations> + <before> + <comment userInput="skippedComment" stepKey="beforeComment"/> + </before> + <after> + <comment userInput="skippedComment" stepKey="afterComment"/> + </after> + </test> <test name="SkippedTestTwoIssues"> <annotations> <stories value="skippedMultiple"/> diff --git a/dev/tests/verification/Tests/ExtendedGenerationTest.php b/dev/tests/verification/Tests/ExtendedGenerationTest.php index d0c9926d0..46246c45b 100644 --- a/dev/tests/verification/Tests/ExtendedGenerationTest.php +++ b/dev/tests/verification/Tests/ExtendedGenerationTest.php @@ -96,4 +96,15 @@ public function testExtendedTestGenerationNoParent() { $this->generateAndCompareTest('ChildExtendedTestNoParent'); } + + /** + * Tests extending a skipped test generation. + * + * @throws \Exception + * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException + */ + public function testExtendingSkippedGeneration() + { + $this->generateAndCompareTest('ExtendingSkippedTest'); + } } diff --git a/dev/tests/verification/Tests/SkippedGenerationTest.php b/dev/tests/verification/Tests/SkippedGenerationTest.php index 6a65df8e3..2d259e02c 100644 --- a/dev/tests/verification/Tests/SkippedGenerationTest.php +++ b/dev/tests/verification/Tests/SkippedGenerationTest.php @@ -20,6 +20,17 @@ public function testSkippedGeneration() $this->generateAndCompareTest('SkippedTest'); } + /** + * Tests skipped test generation does not generate hooks. + * + * @throws \Exception + * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException + */ + public function testSkippedWithHooksGeneration() + { + $this->generateAndCompareTest('SkippedTestWithHooks'); + } + /** * Tests skipped test with multiple issues generation. * diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php index 71f5ec36b..30c3a9004 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php @@ -168,10 +168,6 @@ public function getAnnotations() */ public function getHooks() { - // if this test is skipped we do not want any before/after actions to generate as the tests will not run - if ($this->isSkipped()) { - return []; - } return $this->hooks; } diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index af39f6ad1..be9ad9996 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -207,7 +207,11 @@ private function assembleTestPhp($testObject) $className = $testObject->getCodeceptionName(); try { - $hookPhp = $this->generateHooksPhp($testObject->getHooks()); + if (!$testObject->isSkipped()) { + $hookPhp = $this->generateHooksPhp($testObject->getHooks()); + } else { + $hookPhp = null; + } $testsPhp = $this->generateTestPhp($testObject); } catch (TestReferenceException $e) { throw new TestReferenceException($e->getMessage() . "\n" . $testObject->getFilename()); @@ -620,7 +624,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " } // turn $javaVariable => \$javaVariable but not {$mftfVariable} if ($actionObject->getType() == "executeJS") { - $function = preg_replace('/(?<!{)(\$[\w\d_]+)/', '\\\\$1', $function); + $function = preg_replace('/(?<!{)(\$[A-Za-z._]+)(?![A-z.]*+\$)/', '\\\\$1', $function); } }