コード例 #1
0
 /**
  * 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']));
 }
コード例 #2
0
 /**
  * Testcase to check onQuickformEvent
  */
 public function test_onquickformevent()
 {
     global $USER;
     $testvals = $this->testvals;
     // Get dummy form for data.
     $mform = $this->mform;
     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();
         $expectedvalues = array('day' => array($vals['day']), 'month' => array($vals['month']), 'year' => array($vals['year']), 'hour' => array($vals['hour']), 'minute' => array($vals['minute']));
         $mform->_submitValues = array('dateselector' => $vals['timestamp']);
         $el->onQuickFormEvent('updateValue', null, $mform);
         $this->assertSame($expectedvalues, $el->getValue());
     }
 }