Filter control panel
====================

First some initial setup code:

    >>> import sys
    >>> from zope.component import getUtility
    >>> from Products.PortalTransforms.interfaces import IPortalTransformsTool
    >>> from Products.CMFCore.utils import getToolByName

    >>> browser = self.browser
    >>> safe_html = getUtility(IPortalTransformsTool).safe_html
    >>> kupu_tool = getToolByName(self.portal, 'kupu_library_tool')
    >>> self.loginAsManager()

Viewing the search control panel
--------------------------------

    >>> browser.open('http://nohost/plone/@@filter-controlpanel')
    >>> browser.url.endswith('filter-controlpanel')
    True

Click the save button without making any changes:

    >>> browser.getControl(name="form.actions.save").click()
    >>> browser.url.endswith('filter-controlpanel')
    True

We should get a status message:

    >>> 'Changes saved.' in browser.contents
    True

Now click the cancel button:

    >>> browser.getControl(name="form.actions.cancel").click()
    >>> browser.url.endswith('plone_control_panel')
    True

There should be still no changes:

    >>> 'Changes canceled.' in browser.contents
    True

Look at the defaults
--------------------

    >>> browser.open('http://nohost/plone/@@filter-controlpanel')

    >>> def print_all_of(fieldname):
    ...     for i in xrange(sys.maxint):
    ...         key = 'form.%s.%s.' % (fieldname, i)
    ...         try:
    ...             print browser.getControl(name=key).value
    ...         except LookupError, e:
    ...             break

    >>> print_all_of('nasty_tags')
    applet
    embed
    object
    script

    >>> print_all_of('stripped_tags')
    button
    fieldset
    form
    input
    label
    legend
    link
    noscript
    object
    optgroup
    option
    param
    script
    select
    style
    textarea

    >>> print_all_of('custom_tags')
    u

    >>> print_all_of('stripped_attributes')
    lang
    valign
    halign
    border
    frame
    rules
    cellspacing
    cellpadding
    bgcolor

    # XXX Hello Duncan!
    >>> print_all_of('stripped_combinations')
    >>> print_all_of('style_whitelist')
    text-align
    list-style-type
    float
    >>> print_all_of('class_whitelist')

Changing some values
--------------------

Add a new nasty tag

    >>> browser.getControl("Add Nasty tags").click()
    >>> browser.getControl(name="form.nasty_tags.4.").value = "span"
    >>> browser.getControl(name="form.actions.save").click()
    >>> print_all_of('nasty_tags')
    applet
    embed
    object
    script
    span
    >>> print sorted(safe_html._config['nasty_tags'])
    [u'applet', u'embed', u'object', u'script', u'span']

Adding span to nasty tags should have automatically removed it from the valid tags.

Check that the filtering works
------------------------------

    >>> browser.open('http://nohost/plone/Members')
    >>> browser.getLink('Add new').click()
    >>> 'Add new item' in browser.contents
    True
    >>> browser.getControl('Page').click()
    >>> browser.getControl('Add').click()
    >>> browser.getControl('Body Text').value = \
    ... '<p>Testing that<span> tag and its contents get stripped</span> works.</p>'
    >>> browser.getControl('Title').value = 'My Page'
    >>> browser.getControl('Save').click()
    >>> 'Changes saved.' in browser.contents
    True
    >>> 'My Page' in browser.contents
    True

Must use print here to take advantage of whitespace folding
(whitespace in the body text may vary depending on the tidy_html transform).

    >>> print browser.contents
    <!DOCTYPE...
    <p>Testing that works.</p>...

Kupu tag stripping
==================

Initially 'table' is not stripped by kupu and is valid in safe_html:

    >>> print ', '.join(kupu_tool.get_stripped_tags())
    button, fieldset, ..., style, textarea
    >>> print sorted(safe_html._config['valid_tags'])
    [..., 'sup', 'table', 'tbody', ...]

Now add 'table' to the stripped tags using the control panel, and then check
that table appears in kupu's list of stripped tags and is no longer in
safe_html's list of valid tags.

    >>> print ', '.join(sorted(kupu_tool.get_stripped_tags()))
    button, ..., style, textarea

    >>> def findControl(nameprefix, value):
    ...    i = 0
    ...    for i in range(100):
    ...        c = browser.getControl(name=nameprefix+"%d."%i)
    ...        if c.value==value:
    ...            return c
    ...    raise RuntimeError("That didn't work")
    >>> browser.open('http://nohost/plone/@@filter-controlpanel')

    >>> browser.getControl("Add Stripped tags").click()
    >>> findControl("form.stripped_tags.", "").value = "table"
    >>> browser.getControl(name="form.actions.save").click()
    >>> print_all_of('stripped_tags')
    button
    ...
    style
    table
    textarea
    >>> print sorted(safe_html._config['valid_tags'])
    [..., 'sup', 'tbody', ...]
    >>> print ', '.join(sorted(kupu_tool.get_stripped_tags()))
    button, ..., style, table, textarea

Now remove 'table' from stripped tags and it will disappear from kupu
and reappear in safe_html.

    >>> idparts = findControl("form.stripped_tags.", "table").name.split('.')
    >>> idparts[2] = 'remove_' + idparts[2]
    >>> browser.getControl(name='.'.join(idparts[:-1])).value = True
    >>> browser.getControl(name="form.stripped_tags.remove").click()
    >>> browser.getControl(name="form.actions.save").click()
    >>> print_all_of('stripped_tags')
    button
    ...
    style
    textarea
    >>> browser.getControl(name="form.actions.save").click()
    >>> print sorted(safe_html._config['valid_tags'])
    [..., 'sup', 'table', 'tbody', ...]
    >>> print ', '.join(sorted(kupu_tool.get_stripped_tags()))
    button, ..., style, textarea
