This commit is contained in:
Andrew Nicols
2025-11-27 11:10:20 +08:00
4 changed files with 76 additions and 24 deletions
+33 -12
View File
@@ -14,15 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Date form field class.
*
* @package core_form
* @category test
* @copyright 2013 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/behat_form_group.php');
@@ -41,17 +32,14 @@ use Behat\Mink\Exception\ExpectationException;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_form_date extends behat_form_group {
/**
* Sets the value to a date field.
*
* @param string $value The value to be assigned to the date selector field. The string value must be either
* parsable into a UNIX timestamp or equal to 'disabled' (if disabling the date selector).
* @return void
* @throws ExpectationException If the value is invalid.
*/
public function set_value($value) {
if ($value === 'disabled') {
// Disable the given date selector field.
$this->set_child_field_value('enabled', false);
@@ -77,6 +65,29 @@ class behat_form_date extends behat_form_group {
}
}
/**
* Returns the current value of the field
*
* @return int
*/
public function get_value() {
return make_timestamp(
$this->get_child_field_value('year'),
$this->get_child_field_value('month'),
$this->get_child_field_value('day'),
);
}
/**
* Matches the provided value against the current field value
*
* @param mixed $expectedvalue
* @return bool
*/
public function matches($expectedvalue) {
return (int) $expectedvalue === $this->get_value();
}
/**
* Returns the date field identifiers and the values that should be assigned to them.
*
@@ -115,4 +126,14 @@ class behat_form_date extends behat_form_group {
$childinstance->set_value($childvalue);
}
}
/**
* Gets a value of a child element in the date form field
*
* @param string $childname
* @return string
*/
protected function get_child_field_value(string $childname): string {
return $this->field->find('css', "*[name$='[{$childname}]']")->getValue();
}
}
@@ -14,15 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Date time form field class.
*
* @package core_form
* @category test
* @copyright 2013 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/behat_form_date.php');
@@ -39,6 +30,20 @@ require_once(__DIR__ . '/behat_form_date.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_form_date_time extends behat_form_date {
/**
* Returns the current value of the field
*
* @return string
*/
public function get_value() {
return make_timestamp(
$this->get_child_field_value('year'),
$this->get_child_field_value('month'),
$this->get_child_field_value('day'),
$this->get_child_field_value('hour'),
$this->get_child_field_value('minute'),
);
}
/**
* Returns the date field identifiers and the values that should be assigned to them.
+28 -2
View File
@@ -27,7 +27,20 @@ Feature: Setting and validating date fields
| 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"
Then the following fields match these values:
| Simple only date | ## 2023-07-31 ## |
| Simple optional only date | ## 2023-08-31 ## |
| Simple date and time | ## 2023-07-31 11:15 ## |
| Simple optional date and time | ## 2023-08-31 14:45 ## |
| Group1 only date | ## 2023-07-31 ## |
| Group1 optional only date | ## 2023-08-31 ## |
| Group1 date and time | ## 2023-07-31 11:15 ## |
| Group1 optional date and time | ## 2023-08-31 14:45 ## |
| Group2 only date | ## 2023-07-31 ## |
| Group2 optional only date | ## 2023-08-31 ## |
| Group2 date and time | ## 2023-07-31 11:15 ## |
| Group2 optional date and time | ## 2023-08-31 14:45 ## |
And I should see "simpledateonly: 1690732800"
And I should see "simpleoptionaldateonly: 1693411200"
And I should see "simpledatetime: 1690773300"
And I should see "simpleoptionaldatetime: 1693464300"
@@ -62,7 +75,20 @@ Feature: Setting and validating date fields
| dategroup2[group2optionaldatetime][enabled] | 1 |
| dategroup2[group2optionaldatetime] | ## 2023-08-31 14:45 ## |
When I press "Send form"
Then I should see "simpledateonly: 1690732800"
Then the following fields match these values:
| simpledateonly | ## 2023-07-31 ## |
| simpleoptionaldateonly | ## 2023-08-31 ## |
| simpledatetime | ## 2023-07-31 11:15 ## |
| simpleoptionaldatetime | ## 2023-08-31 14:45 ## |
| group1dateonly | ## 2023-07-31 ## |
| group1optionaldateonly | ## 2023-08-31 ## |
| group1datetime | ## 2023-07-31 11:15 ## |
| group1optionaldatetime | ## 2023-08-31 14:45 ## |
| dategroup2[group2dateonly] | ## 2023-07-31 ## |
| dategroup2[group2optionaldateonly] | ## 2023-08-31 ## |
| dategroup2[group2datetime] | ## 2023-07-31 11:15 ## |
| dategroup2[group2optionaldatetime] | ## 2023-08-31 14:45 ## |
And I should see "simpledateonly: 1690732800"
And I should see "simpleoptionaldateonly: 1693411200"
And I should see "simpledatetime: 1690773300"
And I should see "simpleoptionaldatetime: 1693464300"
@@ -162,7 +162,7 @@ Feature: Manage custom report schedules
And I press "Edit schedule details" action in the "My updated schedule" report row
And the following fields in the "Edit schedule details" "dialogue" match these values:
| Name | My updated schedule |
# | Starting from | ##tomorrow 11:00## | Nope, can't: MDL-86255.
| Starting from | ##tomorrow 11:00## |
| All users: All site users | 1 |
| Subject | Tell me how to win your heart |
| Body | For I haven't got a clue |