mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-83610 behat: allow to set date fields in groups
This commit is contained in:
parent
63205f03bb
commit
98975c118e
@ -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;
|
||||
}
|
||||
|
@ -325,7 +325,13 @@ XPATH
|
||||
XPATH
|
||||
,
|
||||
'date_time' => <<<XPATH
|
||||
.//fieldset[(%idMatch% or ./legend[%exactTagTextMatch%]) and (@data-fieldtype='date' or @data-fieldtype='date_time')]
|
||||
.//*[
|
||||
(%idMatch% or ./legend[%exactTagTextMatch%]
|
||||
or parent::div[@data-groupname=%locator% or ./label[contains(normalize-space(string(.)), %locator%)]]
|
||||
) and
|
||||
(@data-fieldtype='date' or @data-fieldtype='date_time'
|
||||
or @data-fieldtype='date_selector' or @data-fieldtype='date_time_selector')
|
||||
]
|
||||
XPATH
|
||||
,
|
||||
'select_menu' => <<<XPATH
|
||||
|
76
lib/form/tests/behat/dates.feature
Normal file
76
lib/form/tests/behat/dates.feature
Normal file
@ -0,0 +1,76 @@
|
||||
@core @core_form
|
||||
Feature: Setting and validating date fields
|
||||
Behat steps to set and check the date fields
|
||||
|
||||
Background:
|
||||
Given I log in as "admin"
|
||||
|
||||
Scenario: Setting moodleform date fields by field label
|
||||
Given I am on fixture page "/lib/form/tests/behat/fixtures/dates_form.php"
|
||||
And I set the following fields to these values:
|
||||
| Simple only date | ## 2023-07-31 ## |
|
||||
| simpleoptionaldateonly[enabled] | 1 |
|
||||
| Simple optional only date | ## 2023-08-31 ## |
|
||||
| Simple date and time | ## 2023-07-31 11:15 ## |
|
||||
| simpleoptionaldatetime[enabled] | 1 |
|
||||
| Simple optional date and time | ## 2023-08-31 14:45 ## |
|
||||
| Group1 only date | ## 2023-07-31 ## |
|
||||
| group1optionaldateonly[enabled] | 1 |
|
||||
| Group1 optional only date | ## 2023-08-31 ## |
|
||||
| Group1 date and time | ## 2023-07-31 11:15 ## |
|
||||
| group1optionaldatetime[enabled] | 1 |
|
||||
| Group1 optional date and time | ## 2023-08-31 14:45 ## |
|
||||
| Group2 only date | ## 2023-07-31 ## |
|
||||
| dategroup2[group2optionaldateonly][enabled] | 1 |
|
||||
| Group2 optional only date | ## 2023-08-31 ## |
|
||||
| Group2 date and time | ## 2023-07-31 11:15 ## |
|
||||
| dategroup2[group2optionaldatetime][enabled] | 1 |
|
||||
| Group2 optional date and time | ## 2023-08-31 14:45 ## |
|
||||
When I press "Send form"
|
||||
Then I should see "simpledateonly: 1690732800"
|
||||
And I should see "simpleoptionaldateonly: 1693411200"
|
||||
And I should see "simpledatetime: 1690773300"
|
||||
And I should see "simpleoptionaldatetime: 1693464300"
|
||||
And I should see "group1dateonly: 1690732800"
|
||||
And I should see "group1optionaldateonly: 1693411200"
|
||||
And I should see "group1datetime: 1690773300"
|
||||
And I should see "group1optionaldatetime: 1693464300"
|
||||
And I should see "dategroup2[group2dateonly]: 1690732800"
|
||||
And I should see "dategroup2[group2optionaldateonly]: 1693411200"
|
||||
And I should see "dategroup2[group2datetime]: 1690773300"
|
||||
And I should see "dategroup2[group2optionaldatetime]: 1693464300"
|
||||
|
||||
Scenario: Setting moodleform date fields by field name
|
||||
Given I am on fixture page "/lib/form/tests/behat/fixtures/dates_form.php"
|
||||
And I set the following fields to these values:
|
||||
| simpledateonly | ## 2023-07-31 ## |
|
||||
| simpleoptionaldateonly[enabled] | 1 |
|
||||
| simpleoptionaldateonly | ## 2023-08-31 ## |
|
||||
| simpledatetime | ## 2023-07-31 11:15 ## |
|
||||
| simpleoptionaldatetime[enabled] | 1 |
|
||||
| simpleoptionaldatetime | ## 2023-08-31 14:45 ## |
|
||||
| group1dateonly | ## 2023-07-31 ## |
|
||||
| group1optionaldateonly[enabled] | 1 |
|
||||
| group1optionaldateonly | ## 2023-08-31 ## |
|
||||
| group1datetime | ## 2023-07-31 11:15 ## |
|
||||
| group1optionaldatetime[enabled] | 1 |
|
||||
| group1optionaldatetime | ## 2023-08-31 14:45 ## |
|
||||
| dategroup2[group2dateonly] | ## 2023-07-31 ## |
|
||||
| dategroup2[group2optionaldateonly][enabled] | 1 |
|
||||
| dategroup2[group2optionaldateonly] | ## 2023-08-31 ## |
|
||||
| dategroup2[group2datetime] | ## 2023-07-31 11:15 ## |
|
||||
| dategroup2[group2optionaldatetime][enabled] | 1 |
|
||||
| dategroup2[group2optionaldatetime] | ## 2023-08-31 14:45 ## |
|
||||
When I press "Send form"
|
||||
Then I should see "simpledateonly: 1690732800"
|
||||
And I should see "simpleoptionaldateonly: 1693411200"
|
||||
And I should see "simpledatetime: 1690773300"
|
||||
And I should see "simpleoptionaldatetime: 1693464300"
|
||||
And I should see "group1dateonly: 1690732800"
|
||||
And I should see "group1optionaldateonly: 1693411200"
|
||||
And I should see "group1datetime: 1690773300"
|
||||
And I should see "group1optionaldatetime: 1693464300"
|
||||
And I should see "dategroup2[group2dateonly]: 1690732800"
|
||||
And I should see "dategroup2[group2optionaldateonly]: 1693411200"
|
||||
And I should see "dategroup2[group2datetime]: 1690773300"
|
||||
And I should see "dategroup2[group2optionaldatetime]: 1693464300"
|
99
lib/form/tests/behat/fixtures/dates_form.php
Normal file
99
lib/form/tests/behat/fixtures/dates_form.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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 "<h2>Quickform integration test</h2>";
|
||||
|
||||
$form = new test_dates_form();
|
||||
|
||||
$data = $form->get_data();
|
||||
if ($data) {
|
||||
echo "<h3>Submitted data</h3>";
|
||||
echo '<div id="submitted_data"><ul>';
|
||||
$data = (array) $data;
|
||||
foreach ($data as $field => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $key => $v) {
|
||||
echo "<li id=\"sumbmitted_{$field}_$key\">{$field}[$key]: $v</li>";
|
||||
}
|
||||
} else {
|
||||
echo "<li id=\"sumbmitted_{$field}\">$field: $value</li>";
|
||||
}
|
||||
}
|
||||
echo '</ul></div>';
|
||||
}
|
||||
$form->display();
|
||||
|
||||
echo $OUTPUT->footer();
|
Loading…
x
Reference in New Issue
Block a user