function EditorAdminTest::testDisableFormatWithEditor
Same name in other branches
- 9 core/modules/editor/tests/src/Functional/EditorAdminTest.php \Drupal\Tests\editor\Functional\EditorAdminTest::testDisableFormatWithEditor()
- 8.9.x core/modules/editor/tests/src/Functional/EditorAdminTest.php \Drupal\Tests\editor\Functional\EditorAdminTest::testDisableFormatWithEditor()
- 10 core/modules/editor/tests/src/Functional/EditorAdminTest.php \Drupal\Tests\editor\Functional\EditorAdminTest::testDisableFormatWithEditor()
Tests format disabling.
File
-
core/
modules/ editor/ tests/ src/ Functional/ EditorAdminTest.php, line 112
Class
- EditorAdminTest
- Tests administration of text editors.
Namespace
Drupal\Tests\editor\FunctionalCode
public function testDisableFormatWithEditor() : void {
$formats = [
'monoceros' => 'Monoceros',
'tattoo' => 'Tattoo',
];
// Install the node module.
$this->container
->get('module_installer')
->install([
'node',
]);
$this->resetAll();
// Create a new node type and attach the 'body' field to it.
$node_type = NodeType::create([
'type' => $this->randomMachineName(),
'name' => $this->randomString(),
]);
$node_type->save();
node_add_body_field($node_type, $this->randomString());
$permissions = [
'administer filters',
"edit any {$node_type->id()} content",
];
foreach ($formats as $format => $name) {
// Create a format and add an editor to this format.
$this->addEditorToNewFormat($format, $name);
// Add permission for this format.
$permissions[] = "use text format {$format}";
}
// Create a node having the body format value 'monoceros'.
$node = Node::create([
'type' => $node_type->id(),
'title' => $this->randomString(),
]);
$node->body->value = $this->randomString(100);
$node->body->format = 'monoceros';
$node->save();
// Log in as a user able to use both formats and edit nodes of created type.
$account = $this->drupalCreateUser($permissions);
$this->drupalLogin($account);
// The node edit page header.
$text = (string) new FormattableMarkup('<em>Edit @type</em> @title', [
'@type' => $node_type->label(),
'@title' => $node->label(),
]);
// Go to node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertSession()
->responseContains($text);
// Disable the format assigned to the 'body' field of the node.
FilterFormat::load('monoceros')->disable()
->save();
// Edit again the node.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertSession()
->responseContains($text);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.