Skip to content

Commit

Permalink
MDL-43156 core_form: fix handling of fixture form
Browse files Browse the repository at this point in the history
Also moving it from behat_forms to behat_navigation
  • Loading branch information
davosmith authored and stronk7 committed Apr 30, 2020
1 parent 5079271 commit 9da975f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
11 changes: 10 additions & 1 deletion lib/form/tests/behat/fixtures/repeat_defaults_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Test form repeat elements + defaults
*
* @copyright 2020 Davo Smith, Synergy Learning
* @package core_form
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -27,10 +28,18 @@

global $CFG, $PAGE, $OUTPUT;
require_once($CFG->libdir.'/formslib.php');
$PAGE->set_url('/lib/form/tests/behat/fixtures/formtest.php');
$PAGE->set_url('/lib/form/tests/behat/fixtures/repeat_defaults_form.php');
require_login();
$PAGE->set_context(context_system::instance());

/**
* Class repeat_defaults_form
* @package core_form
*/
class repeat_defaults_form extends moodleform {
/**
* Form definition
*/
public function definition() {
$mform = $this->_form;
$repeatcount = $this->_customdata['repeatcount'];
Expand Down
5 changes: 3 additions & 2 deletions lib/form/tests/behat/repeat_defaults.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@core_form @javascript
@core_form
Feature: Newly created repeat elements have the correct default values

Scenario: Clicking button to add repeat elements creates repeat elements with the correct default values
Given I am on the repeat defaults form page
Given I log in as "admin"
And I am on fixture page "/lib/form/tests/behat/fixtures/repeat_defaults_form.php"
When I press "Add repeats"
Then the following fields match these values:
| testcheckbox[1] | 1 |
Expand Down
9 changes: 0 additions & 9 deletions lib/tests/behat/behat_forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,4 @@ public function i_should_see_in_the_list_of_option_for_the_autocomplete($option,
$node = $this->get_node_in_container('xpath_element', $xpathtarget, 'form_row', $field);
$this->ensure_node_is_visible($node);
}

/**
* Visit the fixture page for testing repeat defaults.
* @Given /^I am on the repeat defaults form page$/
*/
public function i_am_on_the_repeat_defaults_form_page() {
$url = new moodle_url('/lib/form/tests/behat/fixtures/repeat_defaults_form.php');
$this->getSession()->visit($this->locate_path($url->out_as_local_url(false)));
}
}
17 changes: 17 additions & 0 deletions lib/tests/behat/behat_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,4 +962,21 @@ protected function select_from_administration_menu($nodelist) {
throw new ElementNotFoundException($this->getSession(),
'Link "' . join(' > ', $nodelist) . '" in the current page edit menu"');
}

/**
* Visit a fixture page for testing stuff that is not available in core.
*
* Please always, to prevent unwanted requests, protect behat fixture files with:
* defined('BEHAT_SITE_RUNNING') || die();
*
* @Given /^I am on fixture page "(?P<url_string>(?:[^"]|\\")*)"$/
* @param string $url local path to fixture page
*/
public function i_am_on_fixture_page($url) {
$fixtureregex = '|^/[a-z0-9_\-/]*/tests/behat/fixtures/[a-z0-9_\-]*\.php$|';
if (!preg_match($fixtureregex, $url)) {
throw new coding_exception("URL {$url} is not a fixture URL");
}
$this->getSession()->visit($this->locate_path($url));
}
}

0 comments on commit 9da975f

Please sign in to comment.