==========================================
Role Mapper Plone <-> Mediawiki configlet
==========================================

This test is adapted from the examples in the book Profesional Plone
Develompment by Martin Aspeli, which in turn is adapted from the onw in
plone.app.controlpanel. :-)

Create the browser object we'll be using.

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
    >>> portal_url = self.portal.absolute_url()
    >>> browser.handleErrors = False
    >>> self.portal.error_log._ignored_exceptions = ()


Some initial setup code:

    >>> from zope.component import getUtility
    >>> from iccommunity.mediawiki.interfaces import IicCommunityManagementMediawikiRolesMapper
    >>> settings = getUtility(IicCommunityManagementMediawikiRolesMapper, name='iccommunity.configuration', context=self.portal)
    >>> self.loginAsPortalOwner()

    >>> settings.rolemap = [u'Role;Role']

Log in into the site as manager.

    >>> from Products.PloneTestCase.setup import portal_owner, default_user, default_password
    >>> login_url = portal_url + '/login_form'
    >>> logout_url = portal_url + '/logout'
    >>> browser.open(login_url)

We have the login portlet, so let's use that.

    >>> browser.getControl(name='__ac_name').value = portal_owner
    >>> browser.getControl(name='__ac_password').value = default_password
    >>> browser.getControl(name='submit').click()
    >>> browser.open(portal_url)
    >>> browser.url == portal_url
    True

Viewing the Mediawiki role mapper control panel.

    >>> browser.getLink('Site Setup').click()
    >>> browser.getLink('icCommunity').click()
    >>> browser.getLink('Mediawiki Roles Mapper').click()
    >>> browser.url
    'http://nohost/plone/@@manage-mediawiki-roles-map'

Click the save button without making any changes:

    >>> browser.getControl("Apply").click()
    >>> browser.url.endswith('manage-mediawiki-roles-map')
    True

We should get a status message.

    >>> 'You entered a non valid Plone role' in browser.contents
    True

Let's enter some invalid Plone role.

    >>> browser.url.endswith('manage-mediawiki-roles-map')
    True
    >>> browser.getControl('Add Map').click()
    >>> browser.getControl(name='form.rolemap.0.').value = 'Manager;A Mediawiki Role'
    >>> browser.getControl('Add Map').click()
    >>> browser.getControl(name='form.rolemap.1.').value = 'Another Plone Role;Another Mediawiki Role'


Click the save button:

    >>> browser.getControl("Apply").click()
    >>> browser.url.endswith('manage-mediawiki-roles-map')
    True
    >>> 'You entered a non valid Mediawiki role' in browser.contents
    True

Finally, let's enter valid data.

    >>> browser.url.endswith('manage-mediawiki-roles-map')
    True
    >>> browser.getControl('Add Map').click()
    >>> browser.getControl(name='form.rolemap.0.').value = 'Manager;sysop'
    >>> browser.getControl('Add Map').click()
    >>> browser.getControl(name='form.rolemap.1.').value = 'Member;sysop'

Click the save button:

    >>> browser.getControl("Apply").click()
    >>> browser.url.endswith('manage-mediawiki-roles-map')
    True
    >>> 'Updated on' in browser.contents
    True


Make sure the changes have been applied correctly to the tool:

    >>> settings.rolemap
    [u'Manager;sysop', u'Member;sysop', None]
