* 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
*/
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'];
-@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 |
$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)));
- }
}
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));
+ }
}