diff --git a/lib/behat/behat_field_manager.php b/lib/behat/behat_field_manager.php index 07b87e5b3d8..6136871759a 100644 --- a/lib/behat/behat_field_manager.php +++ b/lib/behat/behat_field_manager.php @@ -337,6 +337,12 @@ class behat_field_manager { if ($fieldtype === 'tags') { return 'autocomplete'; } + if ($fieldtype === 'date_time_selector') { + return 'date_time'; + } + if ($fieldtype === 'date_selector') { + return 'date'; + } return $fieldtype; } diff --git a/lib/behat/classes/partial_named_selector.php b/lib/behat/classes/partial_named_selector.php index 89dcc36772e..665107aa81f 100644 --- a/lib/behat/classes/partial_named_selector.php +++ b/lib/behat/classes/partial_named_selector.php @@ -325,7 +325,13 @@ XPATH XPATH , 'date_time' => << <<. + +/** + * Test for setting date fields in behat + * + * @package core_form + * @copyright Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(__DIR__ . '/../../../../../config.php'); + +defined('BEHAT_SITE_RUNNING') || die(); + +global $CFG, $PAGE, $OUTPUT; +require_once($CFG->libdir . '/formslib.php'); +$PAGE->set_url('/lib/form/tests/behat/fixtures/dates_form.php'); +$PAGE->add_body_class('limitedwidth'); +require_login(); +$PAGE->set_context(context_system::instance()); + +/** + * Test form class adding all types of date elements + * + * @package core_form + */ +class test_dates_form extends moodleform { + /** + * Define the form. + */ + public function definition() { + $mform = $this->_form; + + $mform->addElement('date_selector', 'simpledateonly', 'Simple only date'); + $mform->addElement('date_selector', 'simpleoptionaldateonly', 'Simple optional only date', ['optional' => true]); + $mform->addElement('date_time_selector', 'simpledatetime', 'Simple date and time'); + $mform->addElement('date_time_selector', 'simpleoptionaldatetime', 'Simple optional date and time', ['optional' => true]); + + $group = []; + $group[] = $mform->createElement('date_selector', 'group1dateonly', 'Group1 only date'); + $group[] = $mform->createElement('date_selector', 'group1optionaldateonly', 'Group1 optional only date', + ['optional' => true]); + $group[] = $mform->createElement('date_time_selector', 'group1datetime', 'Group1 date and time'); + $group[] = $mform->createElement('date_time_selector', 'group1optionaldatetime', 'Group1 optional date and time', + ['optional' => true]); + $mform->addGroup($group, 'dategroup1', 'Date group1', '', false); + + $group = []; + $group[] = $mform->createElement('date_selector', 'group2dateonly', 'Group2 only date'); + $group[] = $mform->createElement('date_selector', 'group2optionaldateonly', 'Group2 optional only date', + ['optional' => true]); + $group[] = $mform->createElement('date_time_selector', 'group2datetime', 'Group2 date and time'); + $group[] = $mform->createElement('date_time_selector', 'group2optionaldatetime', 'Group2 optional date and time', + ['optional' => true]); + $mform->addGroup($group, 'dategroup2', 'Date group2', '', true); + + $this->add_action_buttons(false, 'Send form'); + } +} + +echo $OUTPUT->header(); + +echo "

Quickform integration test

"; + +$form = new test_dates_form(); + +$data = $form->get_data(); +if ($data) { + echo "

Submitted data

"; + echo '
    '; + $data = (array) $data; + foreach ($data as $field => $value) { + if (is_array($value)) { + foreach ($value as $key => $v) { + echo "
  • {$field}[$key]: $v
  • "; + } + } else { + echo "
  • $field: $value
  • "; + } + } + echo '
'; +} +$form->display(); + +echo $OUTPUT->footer();