===============
TinyMCE Utility
===============

First we'll get the TinyMCE utility.

    >>> from Products.TinyMCE.utility import form_adapter
    >>> utility = form_adapter(portal)
    >>> utility
    <TinyMCE at /plone/portal_tinymce>

Configuration
-------------

Let's get the configuration of TinyMCE and see if it returns a json structure.

    >>> utility.getConfiguration(portal)
    '{...}'

Now let's change some variables and see it still works.

    >>> utility.toolbar_cut = True
    >>> utility.toolbar_copy = True
    >>> utility.toolbar_paste = True
    >>> utility.toolbar_pastetext = True
    >>> utility.toolbar_pasteword = True
    >>> utility.toolbar_undo = True
    >>> utility.toolbar_redo = True
    >>> utility.toolbar_search = True
    >>> utility.toolbar_replace = True
    >>> utility.toolbar_underline = True
    >>> utility.toolbar_strikethrough = True
    >>> utility.toolbar_sub = True
    >>> utility.toolbar_sup = True
    >>> utility.toolbar_forecolor = True
    >>> utility.toolbar_backcolor = True
    >>> utility.toolbar_media = True
    >>> utility.toolbar_charmap = True
    >>> utility.toolbar_hr = True
    >>> utility.toolbar_advhr = True
    >>> utility.toolbar_insertdate = True
    >>> utility.toolbar_inserttime = True
    >>> utility.toolbar_emotions = True
    >>> utility.toolbar_nonbreaking = True
    >>> utility.toolbar_pagebreak = True
    >>> utility.toolbar_print = True
    >>> utility.toolbar_preview = True
    >>> utility.toolbar_spellchecker = True
    >>> utility.toolbar_removeformat = True
    >>> utility.toolbar_cleanup = True
    >>> utility.toolbar_visualaid = True
    >>> utility.toolbar_visualchars = True
    >>> utility.toolbar_attribs = True
    >>> utility.resizing = False

The result should at least contain the new buttons we added.

    >>> utility.getConfiguration(portal)
    '{...attribs...}'

Let's change some more settings.

    >>> utility.toolbar_external = True
    >>> utility.autoresize = True
    >>> utility.editor_width = u'100'
    >>> utility.editor_height = u'abc'
    >>> utility.toolbar_width = u'abc'
    >>> utility.contextmenu = False
    >>> utility.content_css = u'test.css'
    >>> utility.link_using_uids = True
    >>> utility.allow_captioned_images = True
    >>> utility.rooted = True
    >>> from Products.CMFCore.utils import getToolByName
    >>> props = getToolByName(self, 'portal_properties')
    >>> livesearch = props.site_properties.getProperty('enable_livesearch', False)
    >>> livesearch = False

The result should contain the settings specified.

    >>> utility.getConfiguration(portal)
    '{...external...}'

Let's call the portal_factory of a document and make sure the configuration
doesn't contain the save button:

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
    >>> self.app.acl_users.userFolderAddUser('root', 'secret', ['Manager'], [])
    >>> browser.addHeader('Authorization', 'Basic root:secret')
    >>> browser.open('http://nohost/plone/createObject?type_name=Document')
    >>> "&quot;save&quot;:" in browser.contents
    False


Do some more toolbar tests, specifically testing the spellchecker button.
First, we make sure that no spellchecker is loaded when the toolbar button is
hidden.

    >>> utility.toolbar_spellchecker = False
    >>> browser.open('http://nohost/plone/createObject?type_name=Document')

AtD shouldn't be there:
    >>> "&quot;AtD&quot;" in browser.contents
    False

Neither should iespell:
    >>> "&quot;iespell&quot;" in browser.contents
    False

Now, we enable the button and set AtD as the checker:
    >>> utility.toolbar_spellchecker = True
    >>> utility.libraries_spellchecker_choice = u'AtD'
    >>> browser.open('http://nohost/plone/createObject?type_name=Document')
    >>> "&quot;AtD&quot;" in browser.contents
    True

Now, we set iespell as the checker:
    >>> utility.libraries_spellchecker_choice = u'iespell'
    >>> browser.open('http://nohost/plone/createObject?type_name=Document')
    >>> "&quot;iespell&quot;" in browser.contents
    True

When we have browser as the checker, neither iespell nor AtD should load:
    >>> utility.libraries_spellchecker_choice = u'browser'
    >>> browser.open('http://nohost/plone/createObject?type_name=Document')
    >>> "&quot;iespell&quot;" in browser.contents
    False
    >>> "&quot;AtD&quot;" in browser.contents
    False


Configurable Image Dimensions
-----------------------------

The image scale dimensions being provided to the image chooser should be
gathered from the chosen AT content type. Let's begin by creating an
AT image:

    >>> self.setRoles(['Manager'])
    >>> id = portal.invokeFactory('News Item', id='test')
    >>> portal[id]
    <ATNewsItem at /plone/test>

Now the values being provided through JSON should be gotten from the ATNewsItem
schema:

    >>> primary_field = portal.test.schema['image']
    >>> scales = utility.getImageScales(primary_field)
    >>> from pprint import pprint
    >>> pprint(scales)
    [{'size': [0, 0], 'title': 'Original', 'value': ''},
    {'size': [16, 16], 'title': 'Listing', 'value': 'image_listing'},
    {'size': [32, 32], 'title': 'Icon', 'value': 'image_icon'},
    {'size': [64, 64], 'title': 'Tile', 'value': 'image_tile'},
    {'size': [128, 128], 'title': 'Thumb', 'value': 'image_thumb'},
    {'size': [200, 200], 'title': 'Mini', 'value': 'image_mini'},
    {'size': [400, 400], 'title': 'Preview', 'value': 'image_preview'},
    {'size': [768, 768], 'title': 'Large', 'value': 'image_large'}]

If no primary field is given, we should get the scale dimensions from ATImage:

    >>> scales = utility.getImageScales()
    >>> pprint(scales)
    [{'size': [0, 0], 'title': 'Original', 'value': ''},
    {'size': [16, 16], 'title': 'Listing', 'value': 'image_listing'},
    {'size': [32, 32], 'title': 'Icon', 'value': 'image_icon'},
    {'size': [64, 64], 'title': 'Tile', 'value': 'image_tile'},
    {'size': [128, 128], 'title': 'Thumb', 'value': 'image_thumb'},
    {'size': [200, 200], 'title': 'Mini', 'value': 'image_mini'},
    {'size': [400, 400], 'title': 'Preview', 'value': 'image_preview'},
    {'size': [768, 768], 'title': 'Large', 'value': 'image_large'}]

We need to specify a context, if we want the dimension of the original image

    >>> import os
    >>> imgdata = open(os.path.join(os.path.dirname(__file__), 'sample.png'))
    >>> portal[id].setImage(imgdata)

    >>> scales = utility.getImageScales(context=portal[id])
    >>> pprint(scales)
    [{'size': [52, 43], 'title': 'Original', 'value': ''},
    {'size': [16, 16], 'title': 'Listing', 'value': 'image_listing'},
    {'size': [32, 32], 'title': 'Icon', 'value': 'image_icon'},
    {'size': [64, 64], 'title': 'Tile', 'value': 'image_tile'},
    {'size': [128, 128], 'title': 'Thumb', 'value': 'image_thumb'},
    {'size': [200, 200], 'title': 'Mini', 'value': 'image_mini'},
    {'size': [400, 400], 'title': 'Preview', 'value': 'image_preview'},
    {'size': [768, 768], 'title': 'Large', 'value': 'image_large'}]

