View source
<?php
namespace Drupal\Tests\ckeditor\Kernel\Plugin\CKEditorPlugin;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\KernelTests\KernelTestBase;
class InternalTest extends KernelTestBase {
public static $modules = [
'ckeditor',
'ckeditor_test',
'filter',
'editor',
];
protected $format;
protected $editor;
protected $ckeditorPluginManager;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('editor');
$this
->installEntitySchema('filter_format');
$this->format = FilterFormat::create([
'format' => 'test_format',
'name' => $this
->randomMachineName(),
]);
$this->format
->save();
$this->editor = Editor::create([
'editor' => 'ckeditor',
'format' => 'test_format',
'settings' => [
'toolbar' => [
'rows' => [
[
[
'name' => 'Enabled Buttons',
'items' => [
'Format',
],
],
],
],
],
],
]);
$this->editor
->save();
$this->ckeditorPluginManager = $this->container
->get('plugin.manager.ckeditor.plugin');
}
public function testFormatTagsSettings($filter_plugins, $expected_format_tags) {
foreach ($filter_plugins as $filter_plugin_id => $filter_plugin_settings) {
$this->format
->setFilterConfig($filter_plugin_id, $filter_plugin_settings);
}
$this->format
->save();
$internal_plugin = $this->ckeditorPluginManager
->createInstance('internal', []);
$plugin_config = $internal_plugin
->getConfig($this->editor);
$this
->assertEquals($expected_format_tags, explode(';', $plugin_config['format_tags']));
}
public function formatTagsSettingsTestCases() {
$all_tags = [
'p',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'pre',
];
return [
'No filter plugins enabled (all tags allowed)' => [
[],
$all_tags,
],
'HTML filter plugin enabled (some tags filtered out)' => [
[
'filter_html' => [
'status' => 1,
'settings' => [
'allowed_html' => '<h1> <h2>',
'filter_html_help' => 1,
'filter_html_nofollow' => 0,
],
],
],
[
'p',
'h1',
'h2',
],
],
'Test attribute filter enabled (all tags allowed)' => [
[
'test_attribute_filter' => [
'status' => 1,
'settings' => [
'tags' => [
'h1',
'h2',
],
],
],
],
$all_tags,
],
];
}
}