1.20.x common.test CommonFormatDateTestCase::testAdminDefinedFormatDate()

Test admin-defined formats in format_date().

File

modules/simpletest/tests/common.test, line 2763
Tests for common.inc functionality.

Class

CommonFormatDateTestCase
Tests the format_date() function.

Code

function testAdminDefinedFormatDate() {
  // Create an admin user.
  $this->admin_user = $this->backdropCreateUser(array('administer site configuration'));
  $this->backdropLogin($this->admin_user);

  // Add new date format.
  $edit = array(
    'label' => 'Example Style',
    'name' => 'example_style',
    'pattern' => 'j M y',
  );
  $this->backdropPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));

  // Add a second date format with a different case than the first.
  $edit = array(
    'label' => 'Example Style Uppercase',
    'name' => 'example_style_uppercase',
    'pattern' => 'j M Y',
  );
  $this->backdropPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
  $this->assertText(t('Date format updated.'));

  // Reset the statically cached date formats so that these calls to
  // format_date() will pick up the newly created date formats from config.
  backdrop_static_reset('system_get_date_formats');

  $timestamp = strtotime('2007-03-10T00:00:00+00:00');
  $this->assertIdentical(format_date($timestamp, 'example_style', '', 'America/Los_Angeles'), '9 Mar 07', 'Test format_date() using an admin-defined date type.');
  $this->assertIdentical(format_date($timestamp, 'example_style_uppercase', '', 'America/Los_Angeles'), '9 Mar 2007', 'Test format_date() using an admin-defined date type with different case.');
  $this->assertIdentical(format_date($timestamp, 'undefined_style'), format_date($timestamp, 'medium'), 'Test format_date() defaulting to medium when $type not found.');
}