Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / src / Functional / System / DateFormatsMachineNameTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\System;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests validity of date format machine names.
9  *
10  * @group system
11  */
12 class DateFormatsMachineNameTest extends BrowserTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function setUp() {
18     parent::setUp();
19     // Create a new administrator user for the test.
20     $admin = $this->drupalCreateUser(['administer site configuration']);
21     $this->drupalLogin($admin);
22   }
23
24   /**
25    * Tests that date formats cannot be created with invalid machine names.
26    */
27   public function testDateFormatsMachineNameAllowedValues() {
28     // Try to create a date format with a not allowed character to test the date
29     // format specific machine name replace pattern.
30     $edit = [
31       'label' => 'Something Not Allowed',
32       'id' => 'something.bad',
33       'date_format_pattern' => 'Y-m-d',
34     ];
35     $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
36     $this->assertText(t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'), 'It is not possible to create a date format with the machine name that has any character other than lowercase letters, digits or underscore.');
37
38     // Try to create a date format with the reserved machine name "custom".
39     $edit = [
40       'label' => 'Custom',
41       'id' => 'custom',
42       'date_format_pattern' => 'Y-m-d',
43     ];
44     $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
45     $this->assertText(t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'), 'It is not possible to create a date format with the machine name "custom".');
46
47     // Try to create a date format with a machine name, "fallback", that
48     // already exists.
49     $edit = [
50       'label' => 'Fallback',
51       'id' => 'fallback',
52       'date_format_pattern' => 'j/m/Y',
53     ];
54     $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
55     $this->assertText(t('The machine-readable name is already in use. It must be unique.'), 'It is not possible to create a date format with the machine name "fallback". It is a built-in format that already exists.');
56
57     // Create a date format with a machine name distinct from the previous two.
58     $id = mb_strtolower($this->randomMachineName(16));
59     $edit = [
60       'label' => $this->randomMachineName(16),
61       'id' => $id,
62       'date_format_pattern' => 'd/m/Y',
63     ];
64     $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
65     $this->assertText(t('Custom date format added.'), 'It is possible to create a date format with a new machine name.');
66
67     // Try to create a date format with same machine name as the previous one.
68     $edit = [
69       'label' => $this->randomMachineName(16),
70       'id' => $id,
71       'date_format_pattern' => 'd-m-Y',
72     ];
73     $this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
74     $this->assertText(t('The machine-readable name is already in use. It must be unique.'), 'It is not possible to create a new date format with an existing machine name.');
75   }
76
77 }