function FilterAdminTest::testDisabledFormat
Same name in other branches
- 9 core/modules/filter/tests/src/Functional/FilterAdminTest.php \Drupal\Tests\filter\Functional\FilterAdminTest::testDisabledFormat()
- 10 core/modules/filter/tests/src/Functional/FilterAdminTest.php \Drupal\Tests\filter\Functional\FilterAdminTest::testDisabledFormat()
- 11.x core/modules/filter/tests/src/Functional/FilterAdminTest.php \Drupal\Tests\filter\Functional\FilterAdminTest::testDisabledFormat()
Tests whether a field using a disabled format is rendered.
File
-
core/
modules/ filter/ tests/ src/ Functional/ FilterAdminTest.php, line 403
Class
- FilterAdminTest
- Thoroughly test the administrative interface of the filter module.
Namespace
Drupal\Tests\filter\FunctionalCode
public function testDisabledFormat() {
// Create a node type and add a standard body field.
$node_type = NodeType::create([
'type' => mb_strtolower($this->randomMachineName()),
]);
$node_type->save();
node_add_body_field($node_type, $this->randomString());
// Create a text format with a filter that returns a static string.
$format = FilterFormat::create([
'name' => $this->randomString(),
'format' => $format_id = mb_strtolower($this->randomMachineName()),
]);
$format->setFilterConfig('filter_static_text', [
'status' => TRUE,
]);
$format->save();
// Create a new node of the new node type.
$node = Node::create([
'type' => $node_type->id(),
'title' => $this->randomString(),
]);
$body_value = $this->randomString();
$node->body->value = $body_value;
$node->body->format = $format_id;
$node->save();
// The format is used and we should see the static text instead of the body
// value.
$this->drupalGet($node->toUrl());
$this->assertText('filtered text');
// Disable the format.
$format->disable()
->save();
$this->drupalGet($node->toUrl());
// The format is not used anymore.
$this->assertNoText('filtered text');
// The text is not displayed unfiltered or escaped.
$this->assertNoRaw($body_value);
$this->assertNoEscaped($body_value);
// Visit the dblog report page.
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/reports/dblog');
// The correct message has been logged.
$this->assertRaw(sprintf('Disabled text format: %s.', $format_id));
// Programmatically change the text format to something random so we trigger
// the missing text format message.
$format_id = $this->randomMachineName();
$node->body->format = $format_id;
$node->save();
$this->drupalGet($node->toUrl());
// The text is not displayed unfiltered or escaped.
$this->assertNoRaw($body_value);
$this->assertNoEscaped($body_value);
// Visit the dblog report page.
$this->drupalGet('admin/reports/dblog');
// The missing text format message has been logged.
$this->assertRaw(sprintf('Missing text format: %s.', $format_id));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.