MDL-77733 behat: Remove extraneous no-axe option

There is no need for no-axe if we make axe a boolean value. We already
have automatic support for negated boolean flags.
This commit is contained in:
Andrew Nicols
2023-05-19 11:28:29 +08:00
committed by Jun Pataleta
parent b1fc632e5c
commit 5d14b0b0c2
4 changed files with 31 additions and 28 deletions
+5 -13
View File
@@ -49,8 +49,7 @@ list($options, $unrecognized) = cli_get_params(
'torun' => 0,
'optimize-runs' => '',
'add-core-features-to-theme' => false,
'axe' => '',
'no-axe' => false,
'axe' => null,
'disable-composer' => false,
'composer-upgrade' => true,
'composer-self-update' => true,
@@ -111,11 +110,9 @@ if (!empty($options['help'])) {
exit(0);
}
if (!empty($options['axe'])) {
if ($options['axe']) {
echo "Axe accessibility tests are enabled by default, to disable them, use the --no-axe option.\n";
}
if (!empty($options['no-axe'])) {
} else if ($options['axe'] === false) {
echo "Axe accessibility tests have been disabled.\n";
}
@@ -127,22 +124,17 @@ if ($options['parallel'] && $options['parallel'] > 1) {
$utilfile = 'util.php';
// Sanitize all input options, so they can be passed to util.
foreach ($options as $option => $value) {
if ($value) {
$commandoptions .= " --$option=\"$value\"";
}
$commandoptions .= behat_get_command_flags($option, $value);
}
} else {
// Only sanitize options for single run.
$cmdoptionsforsinglerun = [
'add-core-features-to-theme',
'axe',
'no-axe',
];
foreach ($cmdoptionsforsinglerun as $option) {
if (!empty($options[$option])) {
$commandoptions .= " --$option='$options[$option]'";
}
$commandoptions .= behat_get_command_flags($option, $options[$option]);
}
}
+2 -8
View File
@@ -54,8 +54,7 @@ list($options, $unrecognized) = cli_get_params(
'torun' => 0,
'optimize-runs' => '',
'add-core-features-to-theme' => false,
'axe' => '',
'no-axe' => false,
'axe' => true,
),
array(
'h' => 'help',
@@ -318,12 +317,7 @@ function commands_to_execute($options) {
}
foreach ($extraoptions as $option => $value) {
if ($options[$option]) {
$extra .= " --$option";
if ($value) {
$extra .= "=\"$value\"";
}
}
$extra .= behat_get_command_flags($option, $value);
}
if (empty($options['parallel'])) {
+3 -7
View File
@@ -49,8 +49,7 @@ list($options, $unrecognized) = cli_get_params(
'updatesteps' => false,
'optimize-runs' => '',
'add-core-features-to-theme' => false,
'axe' => '',
'no-axe' => false,
'axe' => true,
),
array(
'h' => 'help',
@@ -184,11 +183,8 @@ if ($options['install']) {
behat_config_manager::set_behat_run_config_value('behatsiteenabled', 1);
}
// Always run Behat with axe tests.
if (!$options['no-axe']) {
behat_config_manager::set_behat_run_config_value('axe', true);
}
// Configure axe according to option.
behat_config_manager::set_behat_run_config_value('axe', $options['axe']);
// Enable test mode.
$timestart = microtime(true);
+21
View File
@@ -548,3 +548,24 @@ function cli_execute_parallel($cmds, $cwd = null, $delay = 0) {
}
return $processes;
}
/**
* Get command flags for an option/value combination
*
* @param string $option
* @param string|bool|null $value
* @return string
*/
function behat_get_command_flags(string $option, $value): string {
$commandoptions = '';
if (is_bool($value)) {
if ($value) {
return " --{$option}";
} else {
return " --no-{$option}";
}
} else if ($value !== null) {
return " --$option=\"$value\"";
}
return '';
}