*********************************************
Content Rules: Set Rights
*********************************************

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
    >>> 'Overview of the content rules that' 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()
    >>> browser.url.endswith('plone.ContentRule')
    True

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

    >>> browser.getControl(name='form.title').value = 'Sample Rule'
    >>> browser.getControl(name='form.description').value = 'Sample Rule'
    >>> 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.url.endswith('http://nohost/plone/@@rules-controlpanel')
    True

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

    >>> browser.getLink('Sample Rule').click()
    >>> browser.url.endswith('@@manage-elements')
    True

Add Set Rights Action
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We add a set rights action::

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

We will set rights as *de*::

    >>> browser.getControl(name='form.rights').value = 'Creative Commons 2.0'
    >>> browser.getControl(name='form.actions.save').click()

Then we are back to the management of 'Sample Rule' content rule::

    >>> browser.url.endswith('@@manage-elements')
    True

Our action is listed here::

    >>> "Set rights 'Creative Commons 2.0', only if rights was not set." in browser.contents
    True

Now we will not bother if there was a rights set on the content item::

    >>> browser.getControl(name='form.button.EditAction').click()
    >>> browser.getControl(name='form.rights').value = 'Creative Commons 2.0'
    >>> browser.getControl(name='form.only_empty').value = False
    >>> browser.getControl(name='form.actions.save').click()

Back to the management screen::

    >>> browser.url.endswith('@@manage-elements')
    True

Now we are informed this action will set *de* as rights::

    >>> "Set rights 'Creative Commons 2.0'." in browser.contents
    True
