summaryrefslogtreecommitdiffstats
path: root/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php')
-rw-r--r--core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php94
1 files changed, 89 insertions, 5 deletions
diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
index 81c3b80..971d12e 100644
--- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
+++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
@@ -21,7 +21,7 @@ class CKEditorTest extends DrupalUnitTestBase {
*
* @var array
*/
- public static $modules = array('system', 'editor', 'ckeditor');
+ public static $modules = array('system', 'editor', 'ckeditor', 'filter_test');
/**
* An instance of the "CKEditor" text editor plugin.
@@ -53,6 +53,9 @@ class CKEditorTest extends DrupalUnitTestBase {
'filters' => array(
'filter_html' => array(
'status' => 1,
+ 'settings' => array(
+ 'allowed_html' => '<h4> <h5> <h6> <p> <br> <strong> <a>',
+ )
),
),
));
@@ -76,6 +79,7 @@ class CKEditorTest extends DrupalUnitTestBase {
// Default toolbar.
$expected_config = $this->getDefaultInternalConfig() + array(
+ 'allowedContent' => $this->getDefaultAllowedContentConfig(),
'toolbar' => $this->getDefaultToolbarConfig(),
'contentsCss' => $this->getDefaultContentsCssConfig(),
'extraPlugins' => '',
@@ -83,6 +87,7 @@ class CKEditorTest extends DrupalUnitTestBase {
'stylesSet' => FALSE,
'drupalExternalPlugins' => array(),
);
+ ksort($expected_config);
$this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for default configuration.');
// Customize the configuration: add button, have two contextually enabled
@@ -102,15 +107,81 @@ class CKEditorTest extends DrupalUnitTestBase {
$expected_config['drupalExternalPlugins']['llama_contextual_and_button'] = file_create_url('core/modules/ckeditor/tests/modules/js/llama_contextual_and_button.js');
$expected_config['contentsCss'][] = file_create_url('core/modules/ckeditor/tests/modules/ckeditor_test.css');
$expected_config['keystrokes'] = array(array(1114187, 'link'), array(1114188, NULL));
- $this->assertEqual($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
+ ksort($expected_config);
+ $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
- // Change the allowed HTML tags; the "format_tags" setting for CKEditor
- // should automatically be updated as well.
+ // Change the allowed HTML tags; the "allowedContent" and "format_tags"
+ // settings for CKEditor should automatically be updated as well.
$format = entity_load('filter_format', 'filtered_html');
$format->filters('filter_html')->settings['allowed_html'] .= '<pre> <h3>';
$format->save();
+ $expected_config['allowedContent']['pre'] = array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE);
+ $expected_config['allowedContent']['h3'] = array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE);
$expected_config['format_tags'] = 'p;h3;h4;h5;h6;pre';
- $this->assertEqual($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
+ $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
+
+ // Disable the filter_html filter: allow *all *tags.
+ $format->setFilterConfig('filter_html', array('status' => 0));
+ $format->save();
+ $expected_config['allowedContent'] = TRUE;
+ $expected_config['format_tags'] = 'p;h1;h2;h3;h4;h5;h6;pre';
+ $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
+
+ // Enable the filter_test_restrict_tags_and_attributes filter.
+ $format->setFilterConfig('filter_test_restrict_tags_and_attributes', array(
+ 'status' => 1,
+ 'settings' => array(
+ 'restrictions' => array(
+ 'allowed' => array(
+ 'p' => TRUE,
+ 'a' => array(
+ 'href' => TRUE,
+ 'rel' => array('nofollow' => TRUE),
+ 'class' => array('external' => TRUE),
+ 'target' => array('_blank' => FALSE),
+ ),
+ 'span' => array(
+ 'class' => array('dodo' => FALSE),
+ 'property' => array('dc:*' => TRUE),
+ 'rel' => array('foaf:*' => FALSE),
+ ),
+ '*' => array(
+ 'style' => FALSE,
+ 'class' => array('is-a-hipster-llama' => TRUE, 'and-more' => TRUE),
+ 'data-*' => TRUE,
+ ),
+ 'del' => FALSE,
+ )
+ ),
+ ),
+ ));
+ $format->save();
+ $expected_config['allowedContent'] = array(
+ 'p' => array(
+ 'attributes' => TRUE,
+ 'styles' => FALSE,
+ 'classes' => 'is-a-hipster-llama,and-more',
+ ),
+ 'a' => array(
+ 'attributes' => 'href,rel,class,target',
+ 'classes' => 'external',
+ ),
+ 'span' => array(
+ 'attributes' => 'class,property,rel',
+ ),
+ '*' => array(
+ 'attributes' => 'class,data-*',
+ 'classes' => 'is-a-hipster-llama,and-more',
+ ),
+ 'del' => array(
+ 'attributes' => FALSE,
+ 'styles' => FALSE,
+ 'classes' => FALSE,
+ ),
+ );
+ $expected_config['format_tags'] = 'p';
+ ksort($expected_config);
+ $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
}
/**
@@ -166,6 +237,7 @@ class CKEditorTest extends DrupalUnitTestBase {
// Default toolbar.
$expected = $this->getDefaultInternalConfig();
+ $expected['allowedContent'] = $this->getDefaultAllowedContentConfig();
$this->assertIdentical($expected, $internal_plugin->getConfig($editor), '"Internal" plugin configuration built correctly for default toolbar.');
// Format dropdown/button enabled: new setting should be present.
@@ -236,6 +308,18 @@ class CKEditorTest extends DrupalUnitTestBase {
);
}
+ protected function getDefaultAllowedContentConfig() {
+ return array(
+ 'h4' => array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE),
+ 'h5' => array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE),
+ 'h6' => array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE),
+ 'p' => array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE),
+ 'br' => array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE),
+ 'strong' => array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE),
+ 'a' => array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE),
+ );
+ }
+
protected function getDefaultToolbarConfig() {
return array(
0 => array('items' => array('Bold', 'Italic')),