class DateFormatsMachineNameTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/System/DateFormatsMachineNameTest.php \Drupal\Tests\system\Functional\System\DateFormatsMachineNameTest
- 10 core/modules/system/tests/src/Functional/System/DateFormatsMachineNameTest.php \Drupal\Tests\system\Functional\System\DateFormatsMachineNameTest
- 8.9.x core/modules/system/tests/src/Functional/System/DateFormatsMachineNameTest.php \Drupal\Tests\system\Functional\System\DateFormatsMachineNameTest
Tests validity of date format machine names.
@group system
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\System\DateFormatsMachineNameTest implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of DateFormatsMachineNameTest
File
-
core/
modules/ system/ tests/ src/ Functional/ System/ DateFormatsMachineNameTest.php, line 12
Namespace
Drupal\Tests\system\Functional\SystemView source
class DateFormatsMachineNameTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create a new administrator user for the test.
$admin = $this->drupalCreateUser([
'administer site configuration',
]);
$this->drupalLogin($admin);
}
/**
* Tests that date formats cannot be created with invalid machine names.
*/
public function testDateFormatsMachineNameAllowedValues() {
// Try to create a date format with a not allowed character to test the date
// format specific machine name replace pattern.
$edit = [
'label' => 'Something Not Allowed',
'id' => 'something.bad',
'date_format_pattern' => 'Y-m-d',
];
$this->drupalGet('admin/config/regional/date-time/formats/add');
$this->submitForm($edit, 'Add format');
$this->assertSession()
->pageTextContains('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".');
// Try to create a date format with the reserved machine name "custom".
$edit = [
'label' => 'Custom',
'id' => 'custom',
'date_format_pattern' => 'Y-m-d',
];
$this->drupalGet('admin/config/regional/date-time/formats/add');
$this->submitForm($edit, 'Add format');
$this->assertSession()
->pageTextContains('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".');
// Try to create a date format with a machine name, "fallback", that
// already exists.
$edit = [
'label' => 'Fallback',
'id' => 'fallback',
'date_format_pattern' => 'j/m/Y',
];
$this->drupalGet('admin/config/regional/date-time/formats/add');
$this->submitForm($edit, 'Add format');
$this->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
// Create a date format with a machine name distinct from the previous two.
$id = mb_strtolower($this->randomMachineName(16));
$edit = [
'label' => $this->randomMachineName(16),
'id' => $id,
'date_format_pattern' => 'd/m/Y',
];
$this->drupalGet('admin/config/regional/date-time/formats/add');
$this->submitForm($edit, 'Add format');
$this->assertSession()
->pageTextContains('Custom date format added.');
// Try to create a date format with same machine name as the previous one.
$edit = [
'label' => $this->randomMachineName(16),
'id' => $id,
'date_format_pattern' => 'd-m-Y',
];
$this->drupalGet('admin/config/regional/date-time/formats/add');
$this->submitForm($edit, 'Add format');
$this->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.