MDL-47410 behat: Support selection from the datetime selector element

Adds behat support for selecting date and time from a datetime selector
element. The passed values should represent a textual date and time
description wrapped in '##' (e.g. '##first day of January 2020 08:00##',
'##1 Jan 2020 10:30##'). Also, the value 'disabled' is valid and can be
used to disable the datetime selector element.
This commit is contained in:
Mihail Geshoski 2021-02-11 12:04:46 +08:00
parent 76fe097b55
commit 3ac452047f
3 changed files with 19 additions and 3 deletions

View File

@ -25,7 +25,7 @@
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/behat_form_date_selector.php');
require_once(__DIR__ . '/behat_form_date.php');
/**
* Date time form field.
@ -38,5 +38,18 @@ require_once(__DIR__ . '/behat_form_date_selector.php');
* @copyright 2013 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_form_date_time_selector extends behat_form_date_selector {
class behat_form_date_time extends behat_form_date {
/**
* Returns the date field identifiers and the values that should be assigned to them.
*
* @param int $timestamp The UNIX timestamp
* @return array
*/
protected function get_mapped_fields(int $timestamp): array {
return array_merge(parent::get_mapped_fields($timestamp), [
'hour' => date('G', $timestamp),
'minute' => (int) date('i', $timestamp)
]);
}
}

View File

@ -1,6 +1,6 @@
{{< core_form/element-group }}
{{$element}}
<fieldset class="m-0 p-0 border-0" id="{{element.id}}">
<fieldset data-fieldtype="date_time" class="m-0 p-0 border-0" id="{{element.id}}">
<legend class="sr-only">{{label}}</legend>
<div class="fdate_time_selector d-flex flex-wrap align-items-center">
{{#element.elements}}

View File

@ -27,6 +27,9 @@ information provided here is intended especially for developers.
* Behat now supports date selection from the date form element. Examples:
- I set the field "<field_string>" to "##15 March 2021##"
- I set the field "<field_string>" to "##first day of January last year##"
* Behat now supports date and time selection from the datetime form element. Examples:
- I set the field "<field_string>" to "##15 March 2021 08:15##"
- I set the field "<field_string>" to "##first day of January last year noon##"
=== 3.10 ===
* PHPUnit has been upgraded to 8.5. That comes with a few changes: