diff --git a/admin/tool/generator/classes/local/testscenario/runner.php b/admin/tool/generator/classes/local/testscenario/runner.php index 3f8d2dc47833a..d35e0b9674de2 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_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 @@ public function include_behat_libraries() { 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 @@ private function load_generator() { $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 17b7834c276a6..d0ab058a42454 100644 --- a/admin/tool/generator/classes/local/testscenario/steprunner.php +++ b/admin/tool/generator/classes/local/testscenario/steprunner.php @@ -103,6 +103,10 @@ private function build_method_params(string $methodname, array $matches, behat_b 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 0000000000000..d14e63ffb255e --- /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 0000000000000..d7ac99f98ec68 --- /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 |