From 429edf3787e82fc9aadd0024aa6cefda9097724f Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Sat, 9 Feb 2013 03:47:51 -0800
Subject: [PATCH] Issue #1898844 by Wim Leers: Fixed No test coverage for
 hook_editor_js_settings_alter().

---
 .../lib/Drupal/editor/Plugin/EditorManager.php     |  2 +-
 .../lib/Drupal/editor/Tests/EditorManagerTest.php  |  8 ++++++--
 .../editor/tests/modules/editor_test.module        | 14 ++++++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php
index d142dad490c1..74a5eab068df 100644
--- a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php
+++ b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php
@@ -78,7 +78,7 @@ public function getAttachments(array $format_ids) {
     }
 
     // We have all JavaScript settings, allow other modules to alter them.
-    drupal_alter('editor_js_settings', $settings, $formats);
+    drupal_alter('editor_js_settings', $settings);
 
     if (empty($attachments['library']) && empty($settings)) {
       return array();
diff --git a/core/modules/editor/lib/Drupal/editor/Tests/EditorManagerTest.php b/core/modules/editor/lib/Drupal/editor/Tests/EditorManagerTest.php
index f85f176837b1..3a83b8ab9a05 100644
--- a/core/modules/editor/lib/Drupal/editor/Tests/EditorManagerTest.php
+++ b/core/modules/editor/lib/Drupal/editor/Tests/EditorManagerTest.php
@@ -87,9 +87,7 @@ function testManager() {
     // Case 3: a text editor available & associated (but associated only with
     // the 'Full HTML' text format).
     $unicorn_plugin = $this->editorManager->createInstance('unicorn');
-    $default_editor_settings = $unicorn_plugin->getDefaultSettings();
     $editor = entity_create('editor', array(
-      'name' => 'Full HTML',
       'format' => 'full_html',
       'editor' => 'unicorn',
     ));
@@ -112,6 +110,12 @@ function testManager() {
       ),
     );
     $this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'Correct attachments when one text editor is enabled and retrieving attachments for multiple text formats.');
+
+    // Case 4: a text editor available associated, but now with its JS settings
+    // being altered via hook_editor_js_settings_alter().
+    state()->set('editor_test_js_settings_alter_enabled', TRUE);
+    $expected['js'][0]['data']['editor']['formats']['full_html']['editorSettings']['ponyModeEnabled'] = FALSE;
+    $this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'hook_editor_js_settings_alter() works correctly.');
   }
 
 }
diff --git a/core/modules/editor/tests/modules/editor_test.module b/core/modules/editor/tests/modules/editor_test.module
index 4527dde9b44f..b638394bb26d 100644
--- a/core/modules/editor/tests/modules/editor_test.module
+++ b/core/modules/editor/tests/modules/editor_test.module
@@ -25,3 +25,17 @@ function editor_test_editor_default_settings_alter(&$settings, $editor) {
     $settings['sparkles'] = FALSE;
   }
 }
+
+/**
+ * Implements hook_editor_js_settings_alter().
+ */
+function editor_test_editor_js_settings_alter(&$settings) {
+  // Allow tests to enable or disable this alter hook.
+  if (!state()->get('editor_test_js_settings_alter_enabled', FALSE)) {
+    return;
+  }
+
+  if (isset($settings['full_html'])) {
+    $settings['full_html']['editorSettings']['ponyModeEnabled'] = FALSE;
+  }
+}
-- 
GitLab