**************************************
Content Rules: Set layout
**************************************

Functional test: Using the control panel form
====================================================

Preparing the test
---------------------

First we will set some variables to be used on this test::

    >>> app = layer['app']
    >>> portal = layer['portal']
    >>> request = layer['request']

    >>> from plone.testing.z2 import Browser
    >>> from plone.app.testing import SITE_OWNER_NAME
    >>> from plone.app.testing import SITE_OWNER_PASSWORD

    >>> browser = Browser(app)
    >>> browser.handleErrors = False
    >>> portal_url = portal.absolute_url()
    >>> panel_url = portal_url + '/@@overview-controlpanel'

Logging in
---------------------

We will authenticate as manager using the *login_form*::

    >>> browser.open(portal_url + '/login_form')
    >>> browser.getControl(name='__ac_name').value = SITE_OWNER_NAME
    >>> browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD
    >>> browser.getControl(name='submit').click()

If everything worked as expected we will see the welcome message::

    >>> 'You are now logged in' in browser.contents
    True

Accessing the control panel
-------------------------------

Now, authenticated as an user with manager role, we will access the Plone
control panel.::

    >>> browser.open(panel_url)

 and look for the Content Rules configlet::

    >>> 'Content Rules' in browser.contents
    True

Clicking it will take us to the Content Rules configuration::

    >>> browser.getLink('Content Rules').click()
    >>> browser.url.endswith('@@rules-controlpanel')
    True
    >>> 'Content Rules' in browser.contents
    True


Creating a new content rule
-------------------------------

We will create a new content rule so we can test our add and edit views::

    >>> browser.getControl('Add content rule').click()


Fill the title, description and select 'Object added to this container' as
trigger::

    >>> browser.getControl(name='form.title').value = 'Set Layout'
    >>> browser.getControl(name='form.description').value = 'Set layout'
    >>> browser.getControl(name='form.event').value = ['Object added to this container']

Click save::

    >>> browser.getControl(name='form.actions.save').click()

And we are back to the Content Rules control panel::

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

Now we edit our, just created, content rule::

    >>> browser.getLink('Set Layout').click()
    >>> browser.url.endswith('@@manage-elements')
    True

Without Content Type condition
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Adding a new 'Set layout action'::

    >>> browser.getControl('Add action').value = ['sc.contentrules.actions.layout']
    >>> browser.getControl(name='form.button.AddAction').click()

And we should be redirected to our add view:

    >>> 'Add set layout content rules action' in browser.contents
    True

As we did not restricted our content rule to a content type, we will accept
the layout as '_default_view' and save it::

    >>> browser.getControl(name='form.layout').value = ['_default_view']
    >>> browser.getControl(name='form.actions.save').click()

Then we are back to the management of 'Set Layout' content rule::

    >>> browser.open('@@manage-elements')

In the list of actions, a message is displayed explaining we will use 
the _default_view for content items::

    >>> 'Set layout _default_view to a content item' in browser.contents
    True

With Content Type condition
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The Set Layout action is useful when you have a Content Type condition.

That way you are allowed to select from available views for a specific
content type.

To demonstrate that, we need to add a Content Type condition::

    >>> browser.getControl('Add condition').value = ['plone.conditions.PortalType']
    >>> browser.getControl(name='form.button.AddCondition').click()

We will select File as the content type::

    >>> browser.getControl(name='form.check_types:list').value = ['Folder']
    >>> browser.getControl(name='form.actions.save').click()

Then we are back to the management of 'Set Layout' content rule::

    >>> browser.open('@@manage-elements')

Our Content Type condition will be filter only Folder objects::

    >>> 'Content types are: Folder' in browser.contents
    True

Now we could select a Folder Summary View as the layout to be applied
to new folders::

    >>> browser.getControl(name='form.button.EditAction').click()
    
As we did not restricted our content rule to a content type, we will accept
the layout as 'folder_summary_view' and save it::

    >>> browser.getControl(name='form.layout').value = ['folder_summary_view']
    >>> browser.getControl(name='form.actions.save').click()
