diff --git a/lib/form/tests/behat/fixtures/repeat_defaults_form.php b/lib/form/tests/behat/fixtures/repeat_defaults_form.php index 1e88cc4dc7f..13748ed3ede 100644 --- a/lib/form/tests/behat/fixtures/repeat_defaults_form.php +++ b/lib/form/tests/behat/fixtures/repeat_defaults_form.php @@ -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 */ @@ -27,10 +28,18 @@ defined('BEHAT_SITE_RUNNING') || die(); 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']; diff --git a/lib/form/tests/behat/repeat_defaults.feature b/lib/form/tests/behat/repeat_defaults.feature index bb881796f7c..25e0385f41a 100644 --- a/lib/form/tests/behat/repeat_defaults.feature +++ b/lib/form/tests/behat/repeat_defaults.feature @@ -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 | diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index 944c7e13a72..d81686e081b 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -731,13 +731,4 @@ class behat_forms extends behat_base { $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))); - } } diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index 002ab615d96..a452734f888 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -962,4 +962,21 @@ class behat_navigation extends behat_base { 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(?:[^"]|\\")*)"$/ + * @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)); + } }