=====================================
Mediawiki SQL Server 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 IicCommunityManagementMediawikiSQLServer
    >>> settings = getUtility(IicCommunityManagementMediawikiSQLServer, name='iccommunity.configuration', context=self.portal)
    >>> self.loginAsPortalOwner()

    >>> settings.hostname = 'localhost'
    >>> settings.username = 'admin'
    >>> settings.password = u'admin'

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)

Viewing the SQL server control panel.

    >>> browser.getLink('Site Setup').click()
    >>> browser.getLink('icCommunity').click()
    >>> browser.getLink('Mediawiki SQL Server').click()
    >>> browser.url
    'http://nohost/plone/@@manage-mediawiki-sql-server'

Click the save button without making any changes:

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

We should get a status message telling that there were errors because there some
required fields.

    >>> 'There were errors' in browser.contents
    True

Make some changes.

    >>> browser.open('http://nohost/plone/@@manage-mediawiki-sql-server')
    >>> browser.url.endswith('manage-mediawiki-sql-server')
    True

    >>> browser.getControl(name='form.hostname').value = 'http://localhost.com'
    >>> browser.getControl(name='form.username').value = 'admin2'
    >>> browser.getControl(name='form.password').value = 'admin2'

Click the save button:

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

We should be informed that something has changed:

    >>> 'Updated on' in browser.contents
    True

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

    >>> settings.hostname
    'http://localhost.com'
    >>> settings.username
    'admin2'
    >>> settings.password
    u'admin2'
