function FilterCrudTest::testTextFormatCrud
Same name in other branches
- 9 core/modules/filter/tests/src/Kernel/FilterCrudTest.php \Drupal\Tests\filter\Kernel\FilterCrudTest::testTextFormatCrud()
- 10 core/modules/filter/tests/src/Kernel/FilterCrudTest.php \Drupal\Tests\filter\Kernel\FilterCrudTest::testTextFormatCrud()
- 11.x core/modules/filter/tests/src/Kernel/FilterCrudTest.php \Drupal\Tests\filter\Kernel\FilterCrudTest::testTextFormatCrud()
Tests CRUD operations for text formats and filters.
File
-
core/
modules/ filter/ tests/ src/ Kernel/ FilterCrudTest.php, line 26
Class
- FilterCrudTest
- Tests creation, loading, updating, deleting of text formats and filters.
Namespace
Drupal\Tests\filter\KernelCode
public function testTextFormatCrud() {
// Add a text format with minimum data only.
$format = FilterFormat::create([
'format' => 'empty_format',
'name' => 'Empty format',
]);
$format->save();
$this->verifyTextFormat($format);
// Add another text format specifying all possible properties.
$format = FilterFormat::create([
'format' => 'custom_format',
'name' => 'Custom format',
]);
$format->setFilterConfig('filter_url', [
'status' => 1,
'settings' => [
'filter_url_length' => 30,
],
]);
$format->save();
$this->verifyTextFormat($format);
// Alter some text format properties and save again.
$format->set('name', 'Altered format');
$format->setFilterConfig('filter_url', [
'status' => 0,
]);
$format->setFilterConfig('filter_autop', [
'status' => 1,
]);
$format->save();
$this->verifyTextFormat($format);
// Add a filter_test_replace filter and save again.
$format->setFilterConfig('filter_test_replace', [
'status' => 1,
]);
$format->save();
$this->verifyTextFormat($format);
// Disable the text format.
$format->disable()
->save();
$formats = filter_formats();
$this->assertTrue(!isset($formats[$format->id()]), 'filter_formats: Disabled text format no longer exists.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.