3 namespace Drupal\Tests\system\Functional\Common;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests the format_date() function.
12 class FormatDateTest extends BrowserTestBase {
15 * Tests admin-defined formats in format_date().
17 public function testAdminDefinedFormatDate() {
18 // Create and log in an admin user.
19 $this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
21 // Add new date format.
23 'id' => 'example_style',
24 'label' => 'Example Style',
25 'date_format_pattern' => 'j M y',
27 $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
29 // Add a second date format with a different case than the first.
31 'id' => 'example_style_uppercase',
32 'label' => 'Example Style Uppercase',
33 'date_format_pattern' => 'j M Y',
35 $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
36 $this->assertText(t('Custom date format added.'));
38 $timestamp = strtotime('2007-03-10T00:00:00+00:00');
39 $this->assertIdentical(format_date($timestamp, 'example_style', '', 'America/Los_Angeles'), '9 Mar 07');
40 $this->assertIdentical(format_date($timestamp, 'example_style_uppercase', '', 'America/Los_Angeles'), '9 Mar 2007');
41 $this->assertIdentical(format_date($timestamp, 'undefined_style'), format_date($timestamp, 'fallback'), 'Test format_date() defaulting to `fallback` when $type not found.');