Skin Switching based on URL
===========================

Skin switching is done when the based_on_url property is True.  This
is the default::

    >>> from Products.CMFCore.utils import getToolByName
    >>> context = portal
    >>> portal_props = getToolByName(context, 'portal_properties')
    >>> editskin_props = portal_props.get('editskin_switcher')
    >>> editskin_props.getProperty('switch_skin_action')
    ('based on edit URL',)


We rely on the getURL() method.  So we check that we can fool the test
instance into believing it is on a different url::

    >>> from collective.editskinswitcher.tests.utils import TestRequest
    >>> TestRequest().getURL()
    'http://127.0.0.1'
    >>> TestRequest(SERVER_URL='http://edit.domain.org').getURL()
    'http://edit.domain.org'

On localhost we show visitors the default skin.  We test that by
faking traversal::

    >>> from collective.editskinswitcher.tests.utils import FakeTraversalEvent
    >>> from collective.editskinswitcher.traversal import switch_skin
    >>> request = TestRequest(SERVER_URL='http://localhost')
    >>> event = FakeTraversalEvent(context, request)
    >>> switch_skin(context, event)
    >>> context.getCurrentSkinName()
    'Monty Python Skin'

We have smart content editors as they know they can go to 127.0.0.1
and view the same site.  They get a different skin then, which is the
whole purpose of this package.  Content editors should be happy with
just the Sunburst Theme skin::

    >>> request = TestRequest(SERVER_URL='http://127.0.0.1')
    >>> event = FakeTraversalEvent(context, request)
    >>> switch_skin(context, event)
    >>> context.getCurrentSkinName()
    'Sunburst Theme'

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

    >>> from collective.editskinswitcher.tests.utils import changeSkin
    >>> changeSkin(context, 'Monty Python Skin')

Visitors on localhost still see our fabulous Monty Python Skin::

    >>> request = TestRequest(SERVER_URL='http://localhost')
    >>> event = FakeTraversalEvent(context, request)
    >>> switch_skin(context, event)
    >>> context.getCurrentSkinName()
    'Monty Python Skin'

Any content editors that arrive via a url beginning with 'edit' (or
'cms' or 'manage') will get their beloved Sunburst Theme skin again::

    >>> request = TestRequest(SERVER_URL='http://edit.domain.org')
    >>> event = FakeTraversalEvent(context, request)
    >>> switch_skin(context, event)
    >>> context.getCurrentSkinName()
    'Sunburst Theme'

When we set the switch_skin_action to none so no switching is done,
so everyone gets the default skin::

    >>> changeSkin(context, 'Monty Python Skin')
    >>> editskin_props.switch_skin_action = 'no URL based switching'
    >>> request = TestRequest(SERVER_URL='http://localhost')
    >>> event = FakeTraversalEvent(context, request)
    >>> switch_skin(context, event)
    >>> context.getCurrentSkinName()
    'Monty Python Skin'
    >>> request = TestRequest(SERVER_URL='http://edit.domain.org')
    >>> event = FakeTraversalEvent(context, request)
    >>> switch_skin(context, event)
    >>> context.getCurrentSkinName()
    'Monty Python Skin'
