**************************************
Content Rules: Tags Condition
**************************************

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']

    >>> import transaction
    >>> from plone.app.testing import login
    >>> from plone.app.testing import logout
    >>> from plone.app.testing import setRoles
    >>> from plone.app.testing import TEST_USER_ID
    >>> from plone.app.testing import TEST_USER_NAME
    >>> login(portal, TEST_USER_NAME)
    >>> setRoles(portal, TEST_USER_ID, ['Manager'])
    >>> fId = portal.invokeFactory('Folder', 'folder')
    >>> folder = portal[fId]
    >>> folder.setSubject(['Foo', ])
    >>> folder.reindexObject()
    >>> transaction.commit()
    >>> logout()

    >>> 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 Tag condition
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We add a Tag condition::

    >>> browser.getControl('Add condition').value = ['sc.contentrules.conditions.Subject']
    >>> browser.getControl(name='form.button.AddCondition').click()

We will select Foo as a needed Tag::

    >>> browser.getControl(name='form.subject:list').value = ['Foo']
    >>> 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 condition is listed here::

    >>> 'Tags contains Foo' in browser.contents
    True

Now we will leave the Tags control empty:

    >>> browser.getControl(name='form.button.EditCondition').click()

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

Back to the management screen::

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

Now we are informed this condition applies when there is no tag selected in 
the content::

    >>> 'No tags selected' in browser.contents
    True
