From 41eaa09bbe9d5c3f45957e28be101fae7bbf8be1 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 16 Jul 2020 12:09:27 +0800 Subject: [PATCH] MDL-67687 behat: Make axe tests optional --- admin/tool/behat/cli/init.php | 7 ++++++- admin/tool/behat/cli/util.php | 4 +++- admin/tool/behat/cli/util_single_run.php | 5 +++++ lib/behat/classes/util.php | 19 +++++++++++++++++++ lib/tests/behat/behat_accessibility.php | 4 ++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/admin/tool/behat/cli/init.php b/admin/tool/behat/cli/init.php index a5b66169f4b..91a5d8626c3 100644 --- a/admin/tool/behat/cli/init.php +++ b/admin/tool/behat/cli/init.php @@ -49,6 +49,7 @@ list($options, $unrecognized) = cli_get_params( 'torun' => 0, 'optimize-runs' => '', 'add-core-features-to-theme' => false, + 'axe' => false, ), array( 'j' => 'parallel', @@ -71,6 +72,7 @@ Options: -m, --maxruns Max parallel processes to be executed at one time. --fromrun Execute run starting from (Used for parallel runs on different vms) --torun Execute run till (Used for parallel runs on different vms) +--axe Include axe accessibility tests -o, --optimize-runs Split features with specified tags in all parallel runs. -a, --add-core-features-to-theme Add all core features to specified theme's @@ -102,7 +104,10 @@ if ($options['parallel'] && $options['parallel'] > 1) { } } else { // Only sanitize options for single run. - $cmdoptionsforsinglerun = array('add-core-features-to-theme'); + $cmdoptionsforsinglerun = [ + 'add-core-features-to-theme', + 'axe', + ]; foreach ($cmdoptionsforsinglerun as $option) { if (!empty($options[$option])) { diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php index 83a19af1b63..e5f5adeafd3 100644 --- a/admin/tool/behat/cli/util.php +++ b/admin/tool/behat/cli/util.php @@ -54,6 +54,7 @@ list($options, $unrecognized) = cli_get_params( 'torun' => 0, 'optimize-runs' => '', 'add-core-features-to-theme' => false, + 'axe' => false, ), array( 'h' => 'help', @@ -69,7 +70,7 @@ $help = " Behat utilities to manage the test environment Usage: - php util.php [--install|--drop|--enable|--disable|--diag|--updatesteps|--help] [--parallel=value [--maxruns=value]] + php util.php [--install|--drop|--enable|--disable|--diag|--updatesteps|--axe|--help] [--parallel=value [--maxruns=value]] Options: --install Installs the test environment for acceptance tests @@ -78,6 +79,7 @@ Options: --disable Disables test environment --diag Get behat test environment status code --updatesteps Update feature step file. +--axe Include axe accessibility tests -j, --parallel Number of parallel behat run operation -m, --maxruns Max parallel processes to be executed at one time. diff --git a/admin/tool/behat/cli/util_single_run.php b/admin/tool/behat/cli/util_single_run.php index f0a3650f540..42b335cc8cb 100644 --- a/admin/tool/behat/cli/util_single_run.php +++ b/admin/tool/behat/cli/util_single_run.php @@ -49,6 +49,7 @@ list($options, $unrecognized) = cli_get_params( 'updatesteps' => false, 'optimize-runs' => '', 'add-core-features-to-theme' => false, + 'axe' => false, ), array( 'h' => 'help', @@ -75,6 +76,7 @@ Options: --disable Disables test environment --diag Get behat test environment status code --updatesteps Update feature step file. +--axe Include axe accessibility tests -o, --optimize-runs Split features with specified tags in all parallel runs. -a, --add-core-features-to-theme Add all core features to specified theme's @@ -181,6 +183,9 @@ if ($options['install']) { behat_config_manager::set_behat_run_config_value('behatsiteenabled', 1); } + // Define whether to run Behat with axe tests. + behat_config_manager::set_behat_run_config_value('axe', $options['axe']); + // Enable test mode. behat_util::start_test_mode($options['add-core-features-to-theme'], $options['optimize-runs'], $parallel, $run); diff --git a/lib/behat/classes/util.php b/lib/behat/classes/util.php index b24ea485065..aff5dcf6322 100644 --- a/lib/behat/classes/util.php +++ b/lib/behat/classes/util.php @@ -491,4 +491,23 @@ class behat_util extends testing_util { $linecount = count(explode("\n", $formattedmessage)); fwrite(STDOUT, str_repeat(cli_ansi_format(""), $linecount - 1)); } + + /** + * Gets a text-based site version description. + * + * @return string The site info + */ + public static function get_site_info() { + $siteinfo = parent::get_site_info(); + + $accessibility = empty(behat_config_manager::get_behat_run_config_value('axe')) ? 'No' : 'Yes'; + + $siteinfo .= <<has_tag('accessibility')) { throw new DriverException( 'Accessibility tests using Axe must have the @accessibility tag on either the scenario or feature.'