Calendar control panel
======================

First some initial setup code:

    >>> from Products.CMFCore.utils import getToolByName
    >>> ctool = getToolByName(self.portal, 'portal_calendar')
    >>> self.loginAsManager()

Viewing the calendar control panel
----------------------------------

    >>> self.browser.open('http://nohost/plone/@@calendar-controlpanel')
    >>> self.browser.url
    'http://nohost/plone/@@calendar-controlpanel'

Click the save button without making any changes:

    >>> self.browser.getControl(name="form.actions.save").click()
    >>> self.browser.url.endswith('calendar-controlpanel')
    True

We should get a status message:

    >>> 'No changes made.' in self.browser.contents
    True

Now click the cancel button:

    >>> self.browser.getControl(name="form.actions.cancel").click()
    >>> self.browser.url.endswith('plone_control_panel')
    True

There should be still no changes:

    >>> 'Changes canceled.' in self.browser.contents
    True

Make some changes
-----------------

    >>> self.browser.open('http://nohost/plone/@@calendar-controlpanel')
    >>> self.browser.url.endswith('calendar-controlpanel')
    True

    >>> self.browser.getControl(name='form.firstweekday').value = ['3']

Click the save button:

    >>> self.browser.getControl(name="form.actions.save").click()
    >>> self.browser.url.endswith('calendar-controlpanel')
    True

We should be informed that something has changed:

    >>> 'Changes saved.' in self.browser.contents
    True

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

    >>> ctool.firstweekday
    3

Different Locale
----------------

Lets emulate a different locale, to be able to get the weekday names
in the native language. We'll use Brazilian Portuguese, of course... ;-)

    >>> from plone.app.controlpanel import widgets
    >>> PT_BR = ((u'Segunda', 0),
    ...          (u'Terça', 1),
    ...          (u'Quarta', 2),
    ...          (u'Quinta', 3),
    ...          (u'Sexta', 4),
    ...          (u'Sábado', 5),
    ...          (u'Domingo', 6))
    >>> widgets.WEEKDAYS = PT_BR

An int field with a fake context.

    >>> from zope.schema import Int
    >>> field = Int(title=u'Day of week')
    >>> field.context = object()

We need a request too.

    >>> from zope.publisher.browser import TestRequest
    >>> request = TestRequest()

Now create the widget itself and access a localized term.

    >>> widget = widgets.WeekdayWidget(field, request)
    >>> term = widget.vocabulary.getTerm(3)
    >>> term.title
    u'Quinta'
