You are here

public function SchedulerDateModuleTest::testDatePopupFormats in Scheduler 7

Tests configuration of different date formats with the Date Popup field.

File

tests/scheduler.test, line 1163
Scheduler module test case file.

Class

SchedulerDateModuleTest
Tests the components of the scheduler interface which use the date module.

Code

public function testDatePopupFormats() {
  $this
    ->drupalLogin($this->adminUser);

  // Define some date formats to test.
  $test_cases = array(
    // By default we are not using the 'date only' option, so passing only a
    // date should fail.
    'Y-m-d' => FALSE,
    'd-m-Y' => FALSE,
    'm-d-Y' => FALSE,
    'n/j/y' => FALSE,
    'd F Y' => FALSE,
    // Test a number of supported date formats.
    'Y-m-d H:i' => TRUE,
    'd-m-Y h:ia' => TRUE,
    'd m Y h:i a' => TRUE,
    'm-d-Y h:iA' => TRUE,
    'm/d/Y h:i A' => TRUE,
    'n-j-y H:i:s' => TRUE,
    'Y/M/d h:i:sA' => TRUE,
    'Y/M/d h:i:s A' => TRUE,
    'j F y h:i:sa' => TRUE,
    'j F y h:i:s a' => TRUE,
    // Test a number of date formats with invalid time specifications.
    'y-m-d G:i' => FALSE,
    'y-j-n G:i:sa' => FALSE,
    'Y-m-d g:i:sa' => FALSE,
    'y-m-d g:i:s' => FALSE,
    'n-j-y h:i' => FALSE,
    'd-m-y h:i:s' => FALSE,
    'd/M/y H:i:sA' => FALSE,
    'Y F d H:ia' => FALSE,
  );
  foreach ($test_cases as $date_format => $expected_result) {
    $edit = array(
      'scheduler_date_format' => $date_format,
      'scheduler_field_type' => 'date_popup',
    );
    $this
      ->drupalPost('admin/config/content/scheduler', $edit, t('Save configuration'));
    $message = format_string('When using date popups the date format %format is @expected', array(
      '%format' => $date_format,
      '@expected' => $expected_result ? 'allowed' : 'not allowed.',
    ));
    $assert = $expected_result ? 'assertNoText' : 'assertText';
    $this
      ->{$assert}('Error message', $message);
  }
}