public function FilterAdminTest::testFormatAdmin in Drupal 9
Same name and namespace in other branches
- 8 core/modules/filter/tests/src/Functional/FilterAdminTest.php \Drupal\Tests\filter\Functional\FilterAdminTest::testFormatAdmin()
- 10 core/modules/filter/tests/src/Functional/FilterAdminTest.php \Drupal\Tests\filter\Functional\FilterAdminTest::testFormatAdmin()
Tests the format administration functionality.
File
- core/
modules/ filter/ tests/ src/ Functional/ FilterAdminTest.php, line 128
Class
- FilterAdminTest
- Thoroughly test the administrative interface of the filter module.
Namespace
Drupal\Tests\filter\FunctionalCode
public function testFormatAdmin() {
// Add text format.
$this
->drupalGet('admin/config/content/formats');
$this
->clickLink('Add text format');
$format_id = mb_strtolower($this
->randomMachineName());
$name = $this
->randomMachineName();
$edit = [
'format' => $format_id,
'name' => $name,
];
$this
->submitForm($edit, 'Save configuration');
// Verify default weight of the text format.
$this
->drupalGet('admin/config/content/formats');
$this
->assertSession()
->fieldValueEquals("formats[{$format_id}][weight]", 0);
// Change the weight of the text format.
$edit = [
"formats[{$format_id}][weight]" => 5,
];
$this
->drupalGet('admin/config/content/formats');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->fieldValueEquals("formats[{$format_id}][weight]", 5);
// Edit text format.
$this
->drupalGet('admin/config/content/formats');
$destination = Url::fromRoute('filter.admin_overview')
->toString();
$edit_href = Url::fromRoute('entity.filter_format.edit_form', [
'filter_format' => $format_id,
], [
'query' => [
'destination' => $destination,
],
])
->toString();
$this
->assertSession()
->linkByHrefExists($edit_href);
$this
->drupalGet('admin/config/content/formats/manage/' . $format_id);
$this
->submitForm([], 'Save configuration');
// Verify that the custom weight of the text format has been retained.
$this
->drupalGet('admin/config/content/formats');
$this
->assertSession()
->fieldValueEquals("formats[{$format_id}][weight]", 5);
// Disable text format.
$this
->assertSession()
->linkByHrefExists('admin/config/content/formats/manage/' . $format_id . '/disable');
$this
->drupalGet('admin/config/content/formats/manage/' . $format_id . '/disable');
$this
->submitForm([], 'Disable');
// Verify that disabled text format no longer exists.
$this
->drupalGet('admin/config/content/formats/manage/' . $format_id);
$this
->assertSession()
->statusCodeEquals(404);
// Attempt to create a format of the same machine name as the disabled
// format but with a different human readable name.
$edit = [
'format' => $format_id,
'name' => 'New format',
];
$this
->drupalGet('admin/config/content/formats/add');
$this
->submitForm($edit, 'Save configuration');
$this
->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
// Attempt to create a format of the same human readable name as the
// disabled format but with a different machine name.
$edit = [
'format' => 'new_format',
'name' => $name,
];
$this
->drupalGet('admin/config/content/formats/add');
$this
->submitForm($edit, 'Save configuration');
$this
->assertSession()
->pageTextContains("Text format names must be unique. A format named {$name} already exists.");
}