Skip to content

Commit c44d17f

Browse files
committed
Add test
1 parent 8c7c7a8 commit c44d17f

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

djangocms_text/cms_plugins.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from cms.utils.urlutils import admin_reverse
4949

5050
from . import settings
51+
from .editors import get_editor_config
5152
from .forms import ActionTokenValidationForm, RenderPluginForm, TextForm
5253
from .html import render_dynamic_attributes
5354
from .models import Text, _MAX_RTE_LENGTH
@@ -62,7 +63,10 @@
6263
random_comment_exempt,
6364
replace_plugin_tags,
6465
)
65-
from .widgets import TextEditorWidget, rte_config
66+
from .widgets import TextEditorWidget
67+
68+
69+
rte_config = get_editor_config()
6670

6771

6872
def post_add_plugin(operation, **kwargs):

djangocms_text/cms_toolbars.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
from cms.toolbar_pool import toolbar_pool
1313

1414
from . import settings
15+
from .editors import get_editor_config
1516
from .utils import get_cancel_url, get_messages_url, get_render_plugin_url
16-
from .widgets import TextEditorWidget, get_url_endpoint, rte_config
17+
from .widgets import TextEditorWidget, get_url_endpoint
18+
19+
20+
rte_config = get_editor_config()
1721

1822

1923
class IconButton(Button):
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
window.CKEDITOR_BASEPATH = JSON.parse(document.getElementById('cms-editor-cfg').textContent).CKEDITOR_BASEPATH;
1+
// CKEDITOR_BASEPATH is setting for CKEditor 4 which reveals the base path from which to load config etc.
2+
// It can be configred by the TEXT_CKEDITOR_BASEPATH setting in the Django settings file.
3+
// It's loaded in this script since we avoid inline scripts (to better support CSP headers) and it needs to be
4+
// set before the CKEditor script is loaded which in turn needs to be loaded before the integration script.
5+
6+
window.CKEDITOR_BASEPATH = JSON.parse(document.getElementById('cms-editor-cfg').textContent).CKEDITOR_BASEPATH;

djangocms_text/widgets.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
from .editors import DEFAULT_TOOLBAR_CMS, DEFAULT_TOOLBAR_HTMLField, get_editor_base_config, get_editor_config
1919
from .utils import admin_reverse, cms_placeholder_add_plugin
2020

21-
rte_config = get_editor_config()
22-
#: The configuration for the text editor widget
23-
2421

2522
@cache
2623
def get_url_endpoint():
@@ -224,6 +221,7 @@ def get_installed_plugins(self):
224221
def get_global_settings(self, language):
225222
"""The global settings are shared by all widgets and are the same for all instances. They only need
226223
to be loaded once."""
224+
rte_config = get_editor_config()
227225
# Get the toolbar setting
228226
toolbar_setting = get_editor_base_config()
229227
for plugin in self.installed_plugins:

tests/integration/test_ckeditor4.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import pytest
23
from cms.utils.urlutils import admin_reverse
34
from playwright.sync_api import expect
@@ -30,6 +31,13 @@ def handle_console_message(msg):
3031

3132
page.goto(f"{live_server.url}{admin_reverse('cms_placeholder_edit_plugin', args=(text_plugin.pk,))}")
3233

34+
editor_config = json.loads(
35+
page.locator("#cms-editor-cfg").text_content()
36+
) # Ensure the editor configuration is loaded
37+
print(editor_config) # Debugging output
38+
assert "CKEDITOR_BASEPATH" in editor_config, "CKEDITOR_BASEPATH not found in editor configuration"
39+
assert editor_config["CKEDITOR_BASEPATH"] == "/static/djangocms_text/vendor/ckeditor4/"
40+
3341
editor = page.locator(".cke.cke_reset")
3442
expect(editor).to_be_visible() # Editor
3543

0 commit comments

Comments
 (0)