From 3ac452047fb3a4591f292b56125b40836dfda40a Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Thu, 11 Feb 2021 12:04:46 +0800 Subject: [PATCH] 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. --- ...me_selector.php => behat_form_date_time.php} | 17 +++++++++++++++-- .../element-date_time_selector.mustache | 2 +- lib/upgrade.txt | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) rename lib/behat/form_field/{behat_form_date_time_selector.php => behat_form_date_time.php} (70%) diff --git a/lib/behat/form_field/behat_form_date_time_selector.php b/lib/behat/form_field/behat_form_date_time.php similarity index 70% rename from lib/behat/form_field/behat_form_date_time_selector.php rename to lib/behat/form_field/behat_form_date_time.php index 19181cf6b40..f1344603adf 100644 --- a/lib/behat/form_field/behat_form_date_time_selector.php +++ b/lib/behat/form_field/behat_form_date_time.php @@ -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) + ]); + } } diff --git a/lib/form/templates/element-date_time_selector.mustache b/lib/form/templates/element-date_time_selector.mustache index a78ad2e6800..b1a267f0950 100644 --- a/lib/form/templates/element-date_time_selector.mustache +++ b/lib/form/templates/element-date_time_selector.mustache @@ -1,6 +1,6 @@ {{< core_form/element-group }} {{$element}} -
+
{{label}}
{{#element.elements}} diff --git a/lib/upgrade.txt b/lib/upgrade.txt index a63dd29b98c..14386f9cc58 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -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 "" to "##15 March 2021##" - I set the field "" to "##first day of January last year##" +* Behat now supports date and time selection from the datetime form element. Examples: + - I set the field "" to "##15 March 2021 08:15##" + - I set the field "" to "##first day of January last year noon##" === 3.10 === * PHPUnit has been upgraded to 8.5. That comes with a few changes: