Skin Switching based on authentication
======================================

By default we do not care if the user is authenticated.  This is based
on the need_authentication property::

    >>> from Products.CMFCore.utils import getToolByName
    >>> context = portal
    >>> portal_props = getToolByName(context, 'portal_properties')
    >>> editskin_props = portal_props.get('editskin_switcher')
    >>> editskin_props.getProperty('need_authentication')
    False

We would want to check if we are authenticated by calling
portal_membership.isAnonymousUser().  This works fine in our tests,
but fails in real life.  So we check for the ``__ac`` cookie instead.

We prepare a request to an edit url for someone who is logged in::

    >>> from collective.editskinswitcher.tests.utils import TestRequest
    >>> request = TestRequest(SERVER_URL='http://127.0.0.1')
    >>> request._cookies['__ac'] = "We are the Knights Who Say Ni!"

On an edit url we normally get the edit skin::

    >>> context.switchskin(context, request)
    >>> context.getCurrentSkinName()
    'Plone Default'

In these tests, whenever we have really changed the skin, we need to
manually switch the skin back to our default, which normally happens
automatically when your browser makes a new request.

    >>> context.changeSkin('Monty Python Skin', TestRequest())

Now we change the settings so the url has no influence anymore::

    >>> editskin_props.based_on_url = False
    >>> context.switchskin(context, request)
    >>> context.getCurrentSkinName()
    'Monty Python Skin'

Now we set need_authentication to True.  Since we are logged in, we
should get the edit skin::

    >>> editskin_props.need_authentication = True
    >>> context.switchskin(context, request)
    >>> context.getCurrentSkinName()
    'Plone Default'
    >>> context.changeSkin('Monty Python Skin', TestRequest())

Now we logout::

    >>> self.logout()
    >>> del request._cookies['__ac']
    >>> context.switchskin(context, request)
    >>> context.getCurrentSkinName()
    'Monty Python Skin'
