1 form.test FormH5datetimeTestCase::testFormH5datetime()

Tests for #type 'html_date', 'html_time' and 'html_datetime' validation.

File

core/modules/simpletest/tests/form.test, line 2358
Unit tests for the Backdrop Form API.

Class

FormH5datetimeTestCase
Tests html5 date and time elements.

Code

function testFormH5datetime() {
  $edit = array();
  // Valid input.
  $edit['h5date'] = '2002-02-01';
  $edit['h5time'] = '10:33:00';
  $edit['h5datetime[date]'] = '1990-03-22';
  $edit['h5datetime[time]'] = '10:30:20';
  $values = backdrop_json_decode($this->backdropPost('form-test/h5datetime', $edit, 'Submit'));
  $this->assertEqual($values['h5date'], '2002-02-01', 'Correct h5date input validates');
  $this->assertEqual($values['h5time'], '10:33:00', 'Correct h5time input validates');
  $message = 'Correct h5 date and time combined input validates';
  $this->assertEqual($values['h5datetime'], array('date' => '1990-03-22', 'time' => '10:30:20'), $message);

  // Invalid input.
  $edit = array();
  $edit['h5date'] = '2002-02-40';
  $edit['h5time'] = '10:66:00';
  $this->backdropPost('form-test/h5datetime', $edit, 'Submit');
  $this->assertRaw(t('%date is not a valid date.', array('%date' => '2002-02-40')), 'Invalid date doesn\'t validate');
  $this->assertRaw(t('%time is not a valid time.', array('%time' => '10:66:00')), 'Invalid time doesn\'t validate');
}