MDL-86501 form: Fix unit tests

The change in the calendar button from an `<a>` tag to a native
`<button>` tag means the `\HTML_QuickForm_group::getValue()` will have
a different result and the `test_onquickformevent()` tests must be
adjusted accordingly.
This commit is contained in:
Jun Pataleta
2025-09-10 16:14:31 +01:00
committed by Paul Holden
parent 4aa92a69e0
commit 03bcd85bee
2 changed files with 16 additions and 14 deletions
+7 -6
View File
@@ -147,7 +147,7 @@ final class dateselector_test extends \advanced_testcase {
* Testcase to check onQuickformEvent
*/
public function test_onquickformevent(): void {
global $USER;
global $OUTPUT, $USER;
$testvals = $this->testvals;
// Get dummy form for data.
$mform = $this->mform;
@@ -160,11 +160,12 @@ final class dateselector_test extends \advanced_testcase {
$elparams = array('optional'=>false, 'timezone' => $vals['timezone']);
$el = $this->mform->addElement('date_selector', 'dateselector', null, $elparams);
$this->assertTrue($el instanceof MoodleQuickForm_date_selector);
$expectedvalues = array(
'day' => array($vals['day']),
'month' => array($vals['month']),
'year' => array($vals['year'])
);
$expectedvalues = [
'day' => [$vals['day']],
'month' => [$vals['month']],
'year' => [$vals['year']],
'calendar' => $OUTPUT->pix_icon('i/calendar', ''),
];
$mform->_submitValues = array('dateselector' => $vals['timestamp']);
$el->onQuickFormEvent('updateValue', null, $mform);
$this->assertSame($expectedvalues, $el->getValue());
@@ -159,7 +159,7 @@ final class datetimeselector_test extends \advanced_testcase {
* Testcase to check onQuickformEvent
*/
public function test_onquickformevent(): void {
global $USER;
global $OUTPUT, $USER;
$testvals = $this->testvals;
// Get dummy form for data.
$mform = $this->mform;
@@ -172,13 +172,14 @@ final class datetimeselector_test extends \advanced_testcase {
$elparams = array('optional'=>false, 'timezone' => $vals['timezone']);
$el = $this->mform->addElement('date_time_selector', 'dateselector', null, $elparams);
$this->assertTrue($el instanceof MoodleQuickForm_date_time_selector);
$expectedvalues = array(
'day' => array($vals['day']),
'month' => array($vals['month']),
'year' => array($vals['year']),
'hour' => array($vals['hour']),
'minute' => array($vals['minute'])
);
$expectedvalues = [
'day' => [$vals['day']],
'month' => [$vals['month']],
'year' => [$vals['year']],
'hour' => [$vals['hour']],
'minute' => [$vals['minute']],
'calendar' => $OUTPUT->pix_icon('i/calendar', ''),
];
$mform->_submitValues = array('dateselector' => $vals['timestamp']);
$el->onQuickFormEvent('updateValue', null, $mform);
$this->assertSame($expectedvalues, $el->getValue());