/** * Testcase to check exportvalue */ public function test_exportvalue() { global $USER; $testvals = $this->testvals; foreach ($testvals as $vals) { // Set user timezone to test value. $USER->timezone = $vals['usertimezone']; // Create dateselector element with different timezones. $elparams = array('optional' => false, 'timezone' => $vals['timezone']); $el = new MoodleQuickForm_date_time_selector('dateselector', null, $elparams); $el->_createElements(); $submitvalues = array('dateselector' => $vals); $this->assertSame(array('dateselector' => $vals['timestamp']), $el->exportValue($submitvalues), "Please check if timezones are updated (Site adminstration -> location -> update timezone)"); } }
/** * Simulates submitting a form with a date selector element and tests that the chosen dates * are converted into unixtime before being saved in DB. * * @param string $element the form element we are testing * @param string $type the calendar type we want to test * @param array $date the date variables */ private function convert_dateselector_to_unixtime_test($element, $type, $date) { $this->set_calendar_type($type); if ($element == 'dateselector') { $el = new MoodleQuickForm_date_selector('dateselector', null, array('timezone' => 0.0, 'step' => 1)); } else { $el = new MoodleQuickForm_date_time_selector('dateselector', null, array('timezone' => 0.0, 'step' => 1)); } $el->_createElements(); $submitvalues = array('dateselector' => $date); $this->assertSame($el->exportValue($submitvalues), array('dateselector' => $date['timestamp'])); }