You are here

public function DateValidationTest::testValidation in Date 8

Same name in this branch
  1. 8 lib/Drupal/date/Tests/DateValidationTest.php \Drupal\date\Tests\DateValidationTest::testValidation()
  2. 8 date_field/lib/Drupal/date_field/Tests/DateValidationTest.php \Drupal\date\Tests\DateValidationTest::testValidation()

@todo.

File

date_field/lib/Drupal/date_field/Tests/DateValidationTest.php, line 27
Date validation tests.

Class

DateValidationTest

Namespace

Drupal\date\Tests

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',
  ) as $field_type) {
    foreach (array(
      'date_select',
      'date_popup',
    ) 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.
      if ($widget_type != 'date_select') {
        $this
          ->malFormedDate($field_name, $field_type, $widget_type);
      }
      $this
        ->wrongGranularity($field_name, $field_type, $widget_type);
      $this
        ->deleteDateField($label);
    }
  }
}