You are here

function FormatDateTest::testAdminDefinedFormatDate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Common/FormatDateTest.php \Drupal\system\Tests\Common\FormatDateTest::testAdminDefinedFormatDate()

Tests admin-defined formats in format_date().

File

core/modules/system/src/Tests/Common/FormatDateTest.php, line 58
Contains \Drupal\system\Tests\Common\FormatDateTest.

Class

FormatDateTest
Tests the format_date() function.

Namespace

Drupal\system\Tests\Common

Code

function testAdminDefinedFormatDate() {

  // Create and log in an admin user.
  $this
    ->drupalLogin($this
    ->drupalCreateUser(array(
    'administer site configuration',
  )));

  // Add new date format.
  $edit = array(
    'id' => 'example_style',
    'label' => 'Example Style',
    'date_format_pattern' => 'j M y',
  );
  $this
    ->drupalPostForm('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(
    'id' => 'example_style_uppercase',
    'label' => 'Example Style Uppercase',
    'date_format_pattern' => 'j M Y',
  );
  $this
    ->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
  $this
    ->assertText(t('Custom date format added.'));
  $timestamp = strtotime('2007-03-10T00:00:00+00:00');
  $this
    ->assertIdentical(format_date($timestamp, 'example_style', '', 'America/Los_Angeles'), '9 Mar 07');
  $this
    ->assertIdentical(format_date($timestamp, 'example_style_uppercase', '', 'America/Los_Angeles'), '9 Mar 2007');
  $this
    ->assertIdentical(format_date($timestamp, 'undefined_style'), format_date($timestamp, 'fallback'), 'Test format_date() defaulting to `fallback` when $type not found.');
}