Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions dev/tests/verification/Resources/ExecuteJsEscapingTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Magento\AcceptanceTest\_default\Backend;

use Magento\FunctionalTestingFramework\AcceptanceTester;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
use \Codeception\Util\Locator;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Title;
use Yandex\Allure\Adapter\Annotation\Description;
use Yandex\Allure\Adapter\Annotation\Parameter;
use Yandex\Allure\Adapter\Annotation\Severity;
use Yandex\Allure\Adapter\Model\SeverityLevel;
use Yandex\Allure\Adapter\Annotation\TestCaseId;

/**
*/
class ExecuteJsEscapingTestCest
{
/**
* @Features({"TestModule"})
* @Parameter(name = "AcceptanceTester", value="$I")
* @param AcceptanceTester $I
* @return void
* @throws \Exception
*/
public function ExecuteJsEscapingTest(AcceptanceTester $I)
{
$javaVariableEscape = $I->executeJS("return \$javascriptVariable");
$mftfVariableNotEscaped = $I->executeJS("return {$doNotEscape}");
}
}
15 changes: 15 additions & 0 deletions dev/tests/verification/TestModule/Test/ExecuteJsTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
<test name="ExecuteJsEscapingTest">
<executeJS function="return $javascriptVariable" stepKey="javaVariableEscape"/>
<executeJS function="return {$doNotEscape}" stepKey="mftfVariableNotEscaped"/>
</test>
</tests>
22 changes: 22 additions & 0 deletions dev/tests/verification/Tests/ExecuteJsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace tests\verification\Tests;

use tests\util\MftfTestCase;

class ExecuteJsTest extends MftfTestCase
{
/**
* Tests escaping of $javascriptVariable => \$javascriptVariable in the executeJs function
*
* @throws \Exception
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
*/
public function testExecuteJsTest()
{
$this->generateAndCompareTest('ExecuteJsEscapingTest');
}
}
4 changes: 4 additions & 0 deletions src/Magento/FunctionalTestingFramework/Util/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
// Argument must be a closure function, not a string.
$function = trim($function, '"');
}
// turn $javaVariable => \$javaVariable but not {$mftfVariable}
if ($actionObject->getType() == "executeJS") {
$function = preg_replace('/(?<!{)(\$[\w\d_]+)/', '\\\\$1', $function);
}
}

if (isset($customActionAttributes['html'])) {
Expand Down