Skip to content

Commit 07d73cc

Browse files
author
Mihail Geshoski
committed
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.
1 parent c68967a commit 07d73cc

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/behat/form_field/behat_form_date_time_selector.php renamed to lib/behat/form_field/behat_form_date_time.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
2727

28-
require_once(__DIR__ . '/behat_form_date_selector.php');
28+
require_once(__DIR__ . '/behat_form_date.php');
2929

3030
/**
3131
* Date time form field.
@@ -38,5 +38,18 @@
3838
* @copyright 2013 David Monllaó
3939
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4040
*/
41-
class behat_form_date_time_selector extends behat_form_date_selector {
41+
class behat_form_date_time extends behat_form_date {
42+
43+
/**
44+
* Returns the date field identifiers and the values that should be assigned to them.
45+
*
46+
* @param int $timestamp The UNIX timestamp
47+
* @return array
48+
*/
49+
protected function get_mapped_fields(int $timestamp): array {
50+
return array_merge(parent::get_mapped_fields($timestamp), [
51+
'hour' => date('G', $timestamp),
52+
'minute' => (int) date('i', $timestamp)
53+
]);
54+
}
4255
}

lib/form/templates/element-date_time_selector.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{< core_form/element-group }}
22
{{$element}}
3-
<fieldset class="m-0 p-0 border-0" id="{{element.id}}">
3+
<fieldset data-fieldtype="date_time" class="m-0 p-0 border-0" id="{{element.id}}">
44
<legend class="sr-only">{{label}}</legend>
55
<div class="fdate_time_selector d-flex flex-wrap align-items-center">
66
{{#element.elements}}

lib/upgrade.txt

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ information provided here is intended especially for developers.
77
* Behat now supports date selection from the date form element. Examples:
88
- I set the field "<field_string>" to "##15 March 2021##"
99
- I set the field "<field_string>" to "##first day of January last year##"
10+
* Behat now supports date and time selection from the datetime form element. Examples:
11+
- I set the field "<field_string>" to "##15 March 2021 08:15##"
12+
- I set the field "<field_string>" to "##first day of January last year noon##"
1013

1114
=== 3.10 ===
1215
* PHPUnit has been upgraded to 8.5. That comes with a few changes:

0 commit comments

Comments
 (0)