function FilterAPITest::testDependencyRemoval
Same name in other branches
- 8.9.x core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testDependencyRemoval()
- 10 core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testDependencyRemoval()
- 11.x core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testDependencyRemoval()
Tests that filter format dependency removal works.
Ensure that modules providing filter plugins are required when the plugin is in use, and that only disabled plugins are removed from format configuration entities rather than the configuration entities being deleted.
See also
\Drupal\filter\Entity\FilterFormat::onDependencyRemoval()
filter_system_info_alter()
File
-
core/
modules/ filter/ tests/ src/ Kernel/ FilterAPITest.php, line 465
Class
- FilterAPITest
- Tests the behavior of the API of the Filter module.
Namespace
Drupal\Tests\filter\KernelCode
public function testDependencyRemoval() {
$this->installSchema('user', [
'users_data',
]);
$filter_format = FilterFormat::load('filtered_html');
// Disable the filter_test_restrict_tags_and_attributes filter plugin but
// have custom configuration so that the filter plugin is still configured
// in filtered_html the filter format.
$filter_config = [
'weight' => 20,
'status' => 0,
];
$filter_format->setFilterConfig('filter_test_restrict_tags_and_attributes', $filter_config)
->save();
// Use the get method to match the assert after the module has been
// uninstalled.
$filters = $filter_format->get('filters');
$this->assertTrue(isset($filters['filter_test_restrict_tags_and_attributes']), 'The filter plugin filter_test_restrict_tags_and_attributes is configured by the filtered_html filter format.');
drupal_static_reset('filter_formats');
\Drupal::entityTypeManager()->getStorage('filter_format')
->resetCache();
$module_data = \Drupal::service('extension.list.module')->getList();
$this->assertFalse(isset($module_data['filter_test']->info['required']), 'The filter_test module is required.');
// Verify that a dependency exists on the module that provides the filter
// plugin since it has configuration for the disabled plugin.
$this->assertEquals([
'module' => [
'filter_test',
],
], $filter_format->getDependencies());
// Uninstall the module.
\Drupal::service('module_installer')->uninstall([
'filter_test',
]);
// Verify the filter format still exists but the dependency and filter is
// gone.
\Drupal::entityTypeManager()->getStorage('filter_format')
->resetCache();
$filter_format = FilterFormat::load('filtered_html');
$this->assertEquals([], $filter_format->getDependencies());
// Use the get method since the FilterFormat::filters() method only returns
// existing plugins.
$filters = $filter_format->get('filters');
$this->assertFalse(isset($filters['filter_test_restrict_tags_and_attributes']), 'The filter plugin filter_test_restrict_tags_and_attributes is not configured by the filtered_html filter format.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.