1 date_validation.test public DateValidationTestCase::testValidation()

Test validation on each type of date widget.

File

core/modules/date/tests/date_validation.test, line 14
Date validation tests.

Class

DateValidationTestCase

Code

public function testValidation() {
  // Attempts to create text date field stored as a date with default settings
  // (from input which is not valid).
  foreach (array('date', 'datestamp', 'datetime') as $field_type) {
    foreach (array('date_select', 'date_popup', 'date_text', 'date_html5') as $widget_type) {
      $field_name = 'field_test';
      $label = 'Test';
      $options = array(
        'label' => $label,
        'field_name' => $field_name,
        'field_type' => $field_type,
        'widget_type' => $widget_type,
        'input_format' => 'm/d/Y - H:i',
      );
      $this->createDateField($options);

      // Malformed date test won't work on date_select, which won't allow
      // invalid input. Similar with date_html5, which falls back to "now".
      if ($widget_type != 'date_select' && $widget_type != 'date_html5') {
        $this->malFormedDate($field_name, $field_type, $widget_type);
      }

      $this->checkGranularity($field_name, $field_type, $widget_type);
      $this->deleteDateField($label);

      $options['required'] = TRUE;
      $this->createDateField($options);
      $this->dateRangeTests($field_name, $field_type, $widget_type);
      $this->deleteDateField($label);
    }
  }
}