Skip to content

Commit

Permalink
MDL-47410 behat: Support selection from the datetime selector element
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mihail Geshoski committed Feb 11, 2021
1 parent c68967a commit 07d73cc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -38,5 +38,18 @@
* @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)
]);
}
}
2 changes: 1 addition & 1 deletion lib/form/templates/element-date_time_selector.mustache
Original file line number Diff line number Diff line change
@@ -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}}
Expand Down
3 changes: 3 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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:
Expand Down

0 comments on commit 07d73cc

Please sign in to comment.