| 1 system.test | DateTimeFunctionalTest::testDateFormatConfiguration() | 
Test date format configuration.
File
- core/modules/ system/ tests/ system.test, line 1481 
- Tests for system.module.
Class
- DateTimeFunctionalTest
- Tests generic date and time handling capabilities of Backdrop.
Code
function testDateFormatConfiguration() {
  // Confirm 'no custom date formats available' message appears.
  $this->backdropGet('admin/config/regional/date-time/formats');
  // Add custom date format.
  $this->clickLink(t('Add date format'));
  $date_format_name = strtolower($this->randomName(8));
  $label = ucwords($date_format_name);
  $date_format = 'd.m.Y - H:i';
  $edit = array(
    'label' => $label,
    'name' => $date_format_name,
    'pattern' => $date_format,
  );
  $this->backdropPost(NULL, $edit, t('Add format'));
  $this->assertEqual($this->getUrl(), url('admin/config/regional/date-time/formats', array('absolute' => TRUE)), 'Correct page redirection.');
  $this->assertText(t('Date format updated.'), 'Date format added confirmation message appears.');
  $this->assertText($date_format_name, '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->backdropGet('admin/config/regional/date-time/formats');
  $this->clickLink(t('Configure'));
  $edit = array(
    'pattern' => 'Y m',
  );
  $this->backdropPost($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('Date format updated.'), 'Custom date format successfully updated.');
  // Delete custom date format.
  $this->backdropPost('admin/config/regional/date-time/formats/' . $date_format_name . '/delete', array(), t('Remove'));
  $this->assertEqual($this->getUrl(), url('admin/config/regional/date-time/formats', array('absolute' => TRUE)), 'Correct page redirection.');
  $this->assertRaw(t('Removed date format %format.', array('%format' => $label)), 'Custom date format removed.');
  // Make sure the date does not exist in config.
  $formats = config_get('system.date', 'formats');
  $this->assertFalse(array_key_exists($date_format, $formats), 'Date format has been removed from config.');
}
