Skip to content

Commit bc111f5

Browse files
authored
Merge pull request #2020 from magento-pangolin/MFTF2.0.2-2.3-develop
[Pangolin] Added possibility to run Magento CLI from MFTF tests * [MQE-585](https://jira.corp.magento.com/browse/MQE-585): Implement CLI command action * [MQE-710](https://jira.corp.magento.com/browse/MQE-710): [2.0.2 - Release] Execute Magento Functional tests on Jenkins * [MQE-734](https://jira.corp.magento.com/browse/MQE-734): Update dependency for MFTF in magento 2.3-develop branch
2 parents 3881f04 + ce31c78 commit bc111f5

File tree

6 files changed

+93
-5
lines changed

6 files changed

+93
-5
lines changed

dev/tests/acceptance/.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# MAGENTO_ADMIN_USERNAME=admin
1010
# MAGENTO_ADMIN_PASSWORD=123123q
1111
#
12+
# MAGENTO_CLI_COMMAND_PATH=dev/tests/functional/utils/command.php
13+
# MAGENTO_CLI_COMMAND_PARAMETER=command
14+
#
1215
# SELENIUM_HOST=127.0.0.1
1316
# SELENIUM_PORT=4444
1417
# SELENIUM_PROTOCOL=http
@@ -35,6 +38,10 @@ MAGENTO_BACKEND_NAME=
3538
MAGENTO_ADMIN_USERNAME=
3639
MAGENTO_ADMIN_PASSWORD=
3740

41+
#*** Path to CLI entry point and command parameter name. Uncomment and change if folder structure differs from standard Magento installation
42+
#MAGENTO_CLI_COMMAND_PATH=dev/tests/acceptance/utils/command.php
43+
#MAGENTO_CLI_COMMAND_PARAMETER=command
44+
3845
#*** Selenium Server Protocol, Host, Port, and Path, with local defaults. Uncomment and change if not running Selenium locally.
3946
#SELENIUM_HOST=127.0.0.1
4047
#SELENIUM_PORT=4444

dev/tests/acceptance/.htaccess.sample

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
##############################################
2+
## Allow access to command.php
3+
<FilesMatch "command.php">
4+
<IfVersion < 2.4>
5+
order allow,deny
6+
allow from all
7+
</IfVersion>
8+
<IfVersion >= 2.4>
9+
Require all granted
10+
</IfVersion>
11+
</FilesMatch>

dev/tests/acceptance/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"consolidation/robo": "^1.0.0",
2323
"symfony/process": ">=2.7 <3.4",
2424
"henrikbjorn/lurker": "^1.2",
25-
"magento/magento2-functional-testing-framework": "~2.0.0",
25+
"magento/magento2-functional-testing-framework": "~2.0.2",
2626
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0",
2727
"vlucas/phpdotenv": "~2.4"
2828
},

dev/tests/acceptance/composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/SampleTests/Test/SampleTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappear1"/>
199199
<scrollToTopOfPage stepKey="scrollToTopOfPage"/>
200200
<parseFloat userInput="300,000.2325" stepKey="parseFloat1"/>
201+
<magentoCLI stepKey="enableMaintenance1" command="maintenance:enable"/>
201202
</test>
202203
<test name="AllVariableMethodsTest">
203204
<annotations>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
if (isset($_POST['command'])) {
8+
$command = urldecode($_POST['command']);
9+
$php = PHP_BINARY ?: (PHP_BINDIR ? PHP_BINDIR . '/php' : 'php');
10+
$valid = validateCommand($command);
11+
if ($valid) {
12+
exec(escapeCommand($php . ' -f ../../../../bin/magento ' . $command) . " 2>&1", $output, $exitCode);
13+
if ($exitCode == 0) {
14+
http_response_code(202);
15+
} else {
16+
http_response_code(500);
17+
}
18+
echo implode("\n", $output);
19+
} else {
20+
http_response_code(500);
21+
echo "Given command not found valid in Magento CLI Command list.";
22+
}
23+
} else {
24+
http_response_code(500);
25+
echo("Command parameter is not set.");
26+
}
27+
28+
/**
29+
* Returns escaped command.
30+
*
31+
* @param string $command
32+
* @return string
33+
*/
34+
function escapeCommand($command)
35+
{
36+
$escapeExceptions = [
37+
'> /dev/null &' => '--dev-null-amp--'
38+
];
39+
40+
$command = escapeshellcmd(
41+
str_replace(array_keys($escapeExceptions), array_values($escapeExceptions), $command)
42+
);
43+
44+
return str_replace(array_values($escapeExceptions), array_keys($escapeExceptions), $command);
45+
}
46+
47+
/**
48+
* Checks magento list of CLI commands for given $command. Does not check command parameters, just base command.
49+
* @param string $command
50+
* @return bool
51+
*/
52+
function validateCommand($command)
53+
{
54+
$php = PHP_BINARY ?: (PHP_BINDIR ? PHP_BINDIR . '/php' : 'php');
55+
exec($php . ' -f ../../../../bin/magento list', $commandList);
56+
// Trim list of commands after first whitespace
57+
$commandList = array_map("trimAfterWhitespace", $commandList);
58+
return in_array(trimAfterWhitespace($command), $commandList);
59+
}
60+
61+
/**
62+
* Returns given string trimmed of everything after the first found whitespace.
63+
* @param string $string
64+
* @return string
65+
*/
66+
function trimAfterWhitespace($string)
67+
{
68+
return strtok($string, ' ');
69+
}

0 commit comments

Comments
 (0)