===============
WYSIWYG Support
===============

Setup
-----

Get a browser.

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()

Unhide exceptions.

    >>> self.portal.error_log._ignored_exceptions = ()

Go to the portal root.

    >>> portal_url = self.portal.absolute_url()

Get an account and login via the login form.

    >>> from Products.PloneTestCase.setup import portal_owner, default_password
    >>> browser.open(portal_url + '/login_form')
    >>> browser.getControl(name='__ac_name').value = portal_owner
    >>> browser.getControl(name='__ac_password').value = default_password
    >>> browser.getControl(name='submit').click()

Create a blank page for test edits. (front-page is too noisy.)

    >>> testpage = self.folder.absolute_url() + '/' + self.folder.invokeFactory('Document', 'testpage') + '/edit'
    >>> print(testpage)
    http://nohost/plone/Members/test_user_1_/testpage/edit

Set up personalize_form

    >>> personalizer = portal_url + '/personalize_form'
    >>> print(personalizer)
    http://nohost/plone/personalize_form
    >>> browser.open(personalizer)
    >>> browser.getControl(name='email').value = 'test@example.org'
    >>> browser.getControl(name='form.button.Save').click()
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <dd>Your personal settings have been saved.</dd> ...


Test different editors
----------------------
Which editor is used is set globally and can be overridden in the personal preferences.
This results in the following matrix:
=====       =====                   ======
Global      Personal                Expected
=====       =====                   ======
TinyMCE     Use site's default      TinyMCE
TinyMCE     None                    Basic textarea
TinyMCE     TinyMCE                 TinyMCE
<empty>     Use site's default      Basic textarea
<empty>     None                    Basic textarea
<empty>     TinyMCE                 TinyMCE
=====       =====                   ======


Set the editor globally to TinyMCE:
    >>> self.portal.portal_properties.site_properties.default_editor = 'TinyMCE'

If the user sets 'Use site's default'...
    >>> browser.open(personalizer)
    >>> browser.getControl(name='wysiwyg_editor').value = ['']
    >>> browser.getControl(name='form.button.Save').click()
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <dd>Your personal settings have been saved.</dd> ...

we should get TinyMCE:
    >>> browser.open(testpage)
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <script type="text/javascript">
    tinymce.dom.Event.add(window, 'load', function(e) { var config = new TinyMCEConfig('text'); config.init(); });</script> ...


If the user sets 'None'...
    >>> browser.open(personalizer)
    >>> browser.getControl(name='wysiwyg_editor').value = ['None']
    >>> browser.getControl(name='form.button.Save').click()
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <dd>Your personal settings have been saved.</dd> ...

we should get just a textarea:
    >>> browser.open(testpage)
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <textarea name="text" rows="25" id="text"></textarea> ...


If the user sets 'TinyMCE'...
    >>> browser.open(personalizer)
    >>> browser.getControl(name='wysiwyg_editor').value = ['TinyMCE']
    >>> browser.getControl(name='form.button.Save').click()
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <dd>Your personal settings have been saved.</dd> ...

we should get TinyMCE:
    >>> browser.open(testpage)
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <script type="text/javascript">
    tinymce.dom.Event.add(window, 'load', function(e) { var config = new TinyMCEConfig('text'); config.init(); });</script> ...


Set the editor globally to nothing:
    >>> self.portal.portal_properties.site_properties.default_editor = ''

If the user sets 'Use site's default'...
    >>> browser.open(personalizer)
    >>> browser.getControl(name='wysiwyg_editor').value = ['']
    >>> browser.getControl(name='form.button.Save').click()
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <dd>Your personal settings have been saved.</dd> ...

we should get just a textarea:
    >>> browser.open(testpage)
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <textarea name="text" rows="25" id="text"></textarea> ...


If the user sets 'None'...
    >>> browser.open(personalizer)
    >>> browser.getControl(name='wysiwyg_editor').value = ['None']
    >>> browser.getControl(name='form.button.Save').click()
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <dd>Your personal settings have been saved.</dd> ...

we should get just a textarea:
    >>> browser.open(testpage)
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <textarea name="text" rows="25" id="text"></textarea> ...


If the user sets 'TinyMCE'...
    >>> browser.open(personalizer)
    >>> browser.getControl(name='wysiwyg_editor').value = ['TinyMCE']
    >>> browser.getControl(name='form.button.Save').click()
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <dd>Your personal settings have been saved.</dd> ...

we should get TinyMCE:
    >>> browser.open(testpage)
    >>> print(browser.contents)
    <!DOCTYPE html PUBLIC ...
    <script type="text/javascript">
    tinymce.dom.Event.add(window, 'load', function(e) { var config = new TinyMCEConfig('text'); config.init(); });</script> ...
