Skip to content

Commit

Permalink
MDL-82424 tool_generator: plugin handling on test scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranrecio authored and sarjona committed Jul 30, 2024
1 parent a3e810b commit 5cd11ee
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
25 changes: 18 additions & 7 deletions admin/tool/generator/classes/local/testscenario/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions admin/tool/generator/tests/behat/testscenario_steps.feature
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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 |

0 comments on commit 5cd11ee

Please sign in to comment.