From a3e810bf7ea31a84aa910c1099e9f4afeb55906f Mon Sep 17 00:00:00 2001 From: ferranrecio Date: Tue, 9 Jul 2024 15:25:54 +0200 Subject: [PATCH 1/2] MDL-82424 behat: steps to handle plugins This commit adds one new step to disable plugins, and also replaces the regexp from the enable plugins method to make ti compatible with the tool_generator create testing scenario. --- lib/tests/behat/behat_general.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 5c48d897103..bd7d7d0a271 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -2371,6 +2371,18 @@ EOF; $class::enable_plugin($plugin, true); } + /** + * Disable an specific plugin. + * + * @When /^I disable "(?P(?:[^"]|\\")*)" "(?P[^"]*)" plugin$/ + * @param string $plugin Plugin we look for + * @param string $plugintype The type of the plugin + */ + public function i_disable_plugin($plugin, $plugintype) { + $class = core_plugin_manager::resolve_plugininfo_class($plugintype); + $class::enable_plugin($plugin, false); + } + /** * Set the default text editor to the named text editor. * From 5cd11ee33a1b2943c637b400ac0d11317ade871c Mon Sep 17 00:00:00 2001 From: ferranrecio Date: Tue, 9 Jul 2024 15:26:33 +0200 Subject: [PATCH 2/2] MDL-82424 tool_generator: plugin handling on test scenarios --- .../classes/local/testscenario/runner.php | 25 +++++++++++++------ .../classes/local/testscenario/steprunner.php | 4 +++ .../tests/behat/testscenario_steps.feature | 18 +++++++++++++ .../testscenario/scenario_plugins.feature | 12 +++++++++ 4 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 admin/tool/generator/tests/behat/testscenario_steps.feature create mode 100644 admin/tool/generator/tests/fixtures/testscenario/scenario_plugins.feature diff --git a/admin/tool/generator/classes/local/testscenario/runner.php b/admin/tool/generator/classes/local/testscenario/runner.php index 3f8d2dc4783..d35e0b9674d 100644 --- a/admin/tool/generator/classes/local/testscenario/runner.php +++ b/admin/tool/generator/classes/local/testscenario/runner.php @@ -20,6 +20,7 @@ use behat_admin; use behat_data_generators; use behat_base; use behat_course; +use behat_general; use behat_user; use Behat\Gherkin\Parser; use Behat\Gherkin\Lexer; @@ -82,6 +83,7 @@ class runner { require_once("{$CFG->dirroot}/admin/tests/behat/behat_admin.php"); require_once("{$CFG->dirroot}/course/lib.php"); require_once("{$CFG->dirroot}/course/tests/behat/behat_course.php"); + require_once("{$CFG->dirroot}/lib/tests/behat/behat_general.php"); require_once("{$CFG->dirroot}/user/tests/behat/behat_user.php"); return true; } @@ -93,13 +95,22 @@ class runner { $this->generator = new behat_data_generators(); $this->validsteps = $this->scan_generator($this->generator); - // Set config values is not inside the general behat generators. - $extra = $this->scan_method( - new ReflectionMethod(behat_admin::class, 'the_following_config_values_are_set_as_admin'), - new behat_admin(), - ); - if ($extra) { - $this->validsteps[$extra->given] = $extra; + // Add some extra steps from other classes. + $extrasteps = [ + [behat_admin::class, 'the_following_config_values_are_set_as_admin'], + [behat_general::class, 'i_enable_plugin'], + [behat_general::class, 'i_disable_plugin'], + ]; + foreach ($extrasteps as $callable) { + $classname = $callable[0]; + $method = $callable[1]; + $extra = $this->scan_method( + new ReflectionMethod($classname, $method), + new $classname(), + ); + if ($extra) { + $this->validsteps[$extra->given] = $extra; + } } } diff --git a/admin/tool/generator/classes/local/testscenario/steprunner.php b/admin/tool/generator/classes/local/testscenario/steprunner.php index 17b7834c276..d0ab058a424 100644 --- a/admin/tool/generator/classes/local/testscenario/steprunner.php +++ b/admin/tool/generator/classes/local/testscenario/steprunner.php @@ -103,6 +103,10 @@ class steprunner { if (isset($matches[$paramname])) { $params[] = $matches[$paramname]; unset($matches[$paramname]); + } else if (isset($matches["{$paramname}_string"])) { + // If the param uses a regular expression with a name. + $params[] = $matches["{$paramname}_string"]; + unset($matches["{$paramname}_string"]); } else if (count($matches) > 0) { // If the param is not present means the regular expressions does not use // proper names. So we will try to find the param by position. diff --git a/admin/tool/generator/tests/behat/testscenario_steps.feature b/admin/tool/generator/tests/behat/testscenario_steps.feature new file mode 100644 index 00000000000..d14e63ffb25 --- /dev/null +++ b/admin/tool/generator/tests/behat/testscenario_steps.feature @@ -0,0 +1,18 @@ +@tool @tool_generator @_file_upload +Feature: Make test scenario can execute specific steps + In order to create all sort of testing scenarios + As a developer + I need to execute some generic steps in the current instance + + @javascript + Scenario: Make test scenario can enable and disable plugins + Given I disable "page" "mod" plugin + And I log in as "admin" + And I navigate to "Development > Create testing scenarios" in site administration + And I upload "admin/tool/generator/tests/fixtures/testscenario/scenario_plugins.feature" file to "Feature file" filemanager + And I press "Import" + And I should see "Scenario: Course with some disabled plugins" + When I am on "C1" course homepage with editing mode on + And I click on "Add an activity or resource" "button" in the "Section 1" "section" + Then I should see "Page" in the "Add an activity or resource" "dialogue" + And I should not see "Book" in the "Add an activity or resource" "dialogue" diff --git a/admin/tool/generator/tests/fixtures/testscenario/scenario_plugins.feature b/admin/tool/generator/tests/fixtures/testscenario/scenario_plugins.feature new file mode 100644 index 00000000000..d7ac99f98ec --- /dev/null +++ b/admin/tool/generator/tests/fixtures/testscenario/scenario_plugins.feature @@ -0,0 +1,12 @@ +Feature: Enable and disable plugins + Scenario: Course with some disabled plugins + Given the following config values are set as admin: + | sendcoursewelcomemessage | 0 | enrol_manual | + And I enable "page" "mod" plugin + And I disable "book" "mod" plugin + And the following "course" exists: + | fullname | Course test | + | shortname | C1 | + | category | 0 | + | numsections | 3 | + | initsections | 1 |