function FilterAPITest::testFilterFormatPreSave
Same name in other branches
- 9 core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testFilterFormatPreSave()
- 8.9.x core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testFilterFormatPreSave()
- 10 core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testFilterFormatPreSave()
Tests that FilterFormat::preSave() only saves customized plugins.
File
-
core/
modules/ filter/ tests/ src/ Kernel/ FilterAPITest.php, line 402
Class
- FilterAPITest
- Tests the behavior of the API of the Filter module.
Namespace
Drupal\Tests\filter\KernelCode
public function testFilterFormatPreSave() : void {
/** @var \Drupal\filter\FilterFormatInterface $crazy_format */
$crazy_format = FilterFormat::create([
'format' => 'crazy',
'name' => 'Crazy',
'weight' => 1,
'filters' => [
'filter_html_escape' => [
'weight' => 10,
'status' => 1,
],
'filter_html' => [
'weight' => -10,
'status' => 1,
'settings' => [
'allowed_html' => '<p>',
],
],
],
]);
$crazy_format->save();
// Use config to directly load the configuration and check that only enabled
// or customized plugins are saved to configuration.
$filters = $this->config('filter.format.crazy')
->get('filters');
$this->assertEquals([
'filter_html',
'filter_html_escape',
], array_keys($filters));
// Disable a plugin to ensure that disabled plugins with custom settings are
// stored in configuration.
$crazy_format->setFilterConfig('filter_html_escape', [
'status' => FALSE,
]);
$crazy_format->save();
$filters = $this->config('filter.format.crazy')
->get('filters');
$this->assertEquals([
'filter_html',
'filter_html_escape',
], array_keys($filters));
// Set the settings as per default to ensure that disable plugins in this
// state are not stored in configuration.
$crazy_format->setFilterConfig('filter_html_escape', [
'weight' => -10,
]);
$crazy_format->save();
$filters = $this->config('filter.format.crazy')
->get('filters');
$this->assertEquals([
'filter_html',
], array_keys($filters));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.