function FilterAPITest::testFilterFormatPreSave

Same name and namespace in other branches
  1. 9 core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testFilterFormatPreSave()
  2. 10 core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testFilterFormatPreSave()
  3. 11.x 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\Kernel

Code

public function testFilterFormatPreSave() {
    
    /** @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->assertEqual([
        'filter_html_escape',
        'filter_html',
    ], 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->assertEqual([
        'filter_html_escape',
        'filter_html',
    ], 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->assertEqual([
        'filter_html',
    ], array_keys($filters));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.