Commit b1f4d28e by cahrens

Test for style block being maintained.

parent d73f65c3
...@@ -318,15 +318,16 @@ def i_am_shown_a_notification(step): ...@@ -318,15 +318,16 @@ def i_am_shown_a_notification(step):
assert world.is_css_present('.wrapper-prompt') assert world.is_css_present('.wrapper-prompt')
def type_in_codemirror(index, text): def type_in_codemirror(index, text, find_prefix="$"):
script = """ script = """
var cm = $('div.CodeMirror:eq({})').get(0).CodeMirror; var cm = {find_prefix}('div.CodeMirror:eq({index})').get(0).CodeMirror;
cm.getInputField().focus(); cm.getInputField().focus();
cm.setValue(arguments[0]); cm.setValue(arguments[0]);
cm.getInputField().blur();""".format(index) cm.getInputField().blur();""".format(index=index, find_prefix=find_prefix)
world.browser.driver.execute_script(script, str(text)) world.browser.driver.execute_script(script, str(text))
world.wait_for_ajax_complete() world.wait_for_ajax_complete()
def get_codemirror_value(index=0): def get_codemirror_value(index=0):
return world.browser.driver.execute_script(""" return world.browser.driver.execute_script("""
return $('div.CodeMirror:eq({})').get(0).CodeMirror.getValue(); return $('div.CodeMirror:eq({})').get(0).CodeMirror.getValue();
......
...@@ -24,4 +24,17 @@ Feature: CMS.HTML Editor ...@@ -24,4 +24,17 @@ Feature: CMS.HTML Editor
Given I have created a Blank HTML Page Given I have created a Blank HTML Page
When I edit the page When I edit the page
And I add an image with a static link via the Image Plugin Icon And I add an image with a static link via the Image Plugin Icon
Then the image static link is rewritten to translate the path Then the image static link is rewritten to translate the path
\ No newline at end of file
Scenario: TinyMCE and CodeMirror preserve style tags
Given I have created a Blank HTML Page
When I edit the page
And type "<p class='title'>pages</p><style><!-- .title { color: red; } --></style>" in the code editor and press OK
And I save the page
Then the page has text:
"""
<p class="title">pages</p>
<style><!--
.title { color: red; }
--></style>
"""
\ No newline at end of file
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
# pylint: disable=C0111 # pylint: disable=C0111
from lettuce import world, step from lettuce import world, step
from nose.tools import assert_in # pylint: disable=no-name-in-module from nose.tools import assert_in, assert_equal # pylint: disable=no-name-in-module
from common import type_in_codemirror
@step('I have created a Blank HTML Page$') @step('I have created a Blank HTML Page$')
...@@ -38,18 +39,44 @@ def i_click_on_edit_icon(step): ...@@ -38,18 +39,44 @@ def i_click_on_edit_icon(step):
@step('I add an image with a static link via the Image Plugin Icon$') @step('I add an image with a static link via the Image Plugin Icon$')
def i_click_on_image_plugin_icon(step): def i_click_on_image_plugin_icon(step):
# Click on image plugin button use_plugin(
world.css_click('.mce-i-image') '.mce-i-image',
lambda: world.css_fill('.mce-textbox', '/static/image.jpg', 0)
)
@step('type "(.*)" in the code editor and press OK$')
def type_in_codemirror_plugin(step, text):
use_plugin(
'.mce-i-code',
lambda: type_in_codemirror(0, text, "$('iframe').contents().find")
)
def use_plugin(button_class, action):
# Click on plugin button
world.css_click(button_class)
# Wait for the editing window to open. # Wait for the editing window to open.
world.wait_for_visible('.mce-window') world.wait_for_visible('.mce-window')
# Fill in the first field (source). # Trigger the action
world.css_fill('.mce-textbox', '/static/image.jpg', 0) action()
# Click OK # Click OK
world.css_click('.mce-primary') world.css_click('.mce-primary')
@step('I save the page$')
def i_click_on_save(step):
world.save_component(step)
@step('the page has text:')
def check_page_text(step):
assert_equal(step.multiline, world.css_find('.xmodule_HtmlModule').html.strip())
@step('the image static link is rewritten to translate the path$') @step('the image static link is rewritten to translate the path$')
def image_static_link_is_rewritten(step): def image_static_link_is_rewritten(step):
# Find the TinyMCE iframe within the main window # Find the TinyMCE iframe within the main window
......
...@@ -46,6 +46,12 @@ class @HTMLEditingDescriptor ...@@ -46,6 +46,12 @@ class @HTMLEditingDescriptor
height: '400px', height: '400px',
menubar: false, menubar: false,
statusbar: false, statusbar: false,
# Necessary to avoid stripping of style tags.
valid_children : "+body[style]",
# Prevent TinyMCE from adding extra <p>&nbsp;</p> in code.
forced_root_block : "",
force_br_newlines : true,
force_p_newlines : false,
setup: @setupTinyMCE, setup: @setupTinyMCE,
# Cannot get access to tinyMCE Editor instance (for focusing) until after it is rendered. # Cannot get access to tinyMCE Editor instance (for focusing) until after it is rendered.
# The tinyMCE callback passes in the editor as a paramter. # The tinyMCE callback passes in the editor as a paramter.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment