062d6f41240310fbc992b7a3d7608c5ed9d35963
[yaffs-website] / web / core / modules / system / tests / src / Functional / Common / FormatDateTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Common;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests the format_date() function.
9  *
10  * @group Common
11  */
12 class FormatDateTest extends BrowserTestBase {
13
14   /**
15    * Tests admin-defined formats in format_date().
16    */
17   public function testAdminDefinedFormatDate() {
18     // Create and log in an admin user.
19     $this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
20
21     // Add new date format.
22     $edit = [
23       'id' => 'example_style',
24       'label' => 'Example Style',
25       'date_format_pattern' => 'j M y',
26     ];
27     $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
28
29     // Add a second date format with a different case than the first.
30     $edit = [
31       'id' => 'example_style_uppercase',
32       'label' => 'Example Style Uppercase',
33       'date_format_pattern' => 'j M Y',
34     ];
35     $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
36     $this->assertText(t('Custom date format added.'));
37
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.');
42   }
43
44 }