function DateTimeTest::testDateFormatConfiguration

Test date format configuration.

File

drupal/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php, line 77
Definition of Drupal\system\Tests\System\DateTimeTest.

Class

DateTimeTest
Tests generic date and time handling capabilities of Drupal.

Namespace

Drupal\system\Tests\System

Code

function testDateFormatConfiguration() {

  // Confirm 'no custom date formats available' message appears.
  $this
    ->drupalGet('admin/config/regional/date-time/formats');

  // Add custom date format.
  $this
    ->clickLink(t('Add format'));
  $date_format_id = strtolower($this
    ->randomName(8));
  $name = ucwords($date_format_id);
  $date_format = 'd.m.Y - H:i';
  $edit = array(
    'date_format_id' => $date_format_id,
    'date_format_name' => $name,
    'date_format_pattern' => $date_format,
  );
  $this
    ->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
  $this
    ->assertEqual($this
    ->getUrl(), url('admin/config/regional/date-time/formats', array(
    'absolute' => TRUE,
  )), 'Correct page redirection.');
  $this
    ->assertText(t('Custom date format updated.'), 'Date format added confirmation message appears.');
  $this
    ->assertText($date_format_id, 'Custom date format appears in the date format list.');
  $this
    ->assertText(t('delete'), 'Delete link for custom date format appears.');

  // Edit custom date format.
  $this
    ->drupalGet('admin/config/regional/date-time/formats');
  $this
    ->clickLink(t('edit'));
  $edit = array(
    'date_format_pattern' => 'Y m',
  );
  $this
    ->drupalPost($this
    ->getUrl(), $edit, t('Save format'));
  $this
    ->assertEqual($this
    ->getUrl(), url('admin/config/regional/date-time/formats', array(
    'absolute' => TRUE,
  )), 'Correct page redirection.');
  $this
    ->assertText(t('Custom date format updated.'), 'Custom date format successfully updated.');

  // Delete custom date format.
  $this
    ->clickLink(t('delete'));
  $this
    ->drupalPost('admin/config/regional/date-time/formats/' . $date_format_id . '/delete', array(), t('Remove'));
  $this
    ->assertEqual($this
    ->getUrl(), url('admin/config/regional/date-time/formats', array(
    'absolute' => TRUE,
  )), 'Correct page redirection.');
  $this
    ->assertText(t('Removed date format ' . $name), 'Custom date format removed.');

  // Make sure the date does not exist in config.
  $date_format = config('system.date')
    ->get('formats.' . $date_format_id);
  $this
    ->assertIdentical($date_format, NULL);
}