collective.cdn.multiplehostnames
=================================

First some initial setup code::

    >>> app = layer['app']
    >>> portal = layer['portal']
    >>> request = layer['request']

    >>> from plone.testing.z2 import Browser
    >>> browser = Browser(app)

    >>> from zope.component import getUtility
    >>> from Products.CMFCore.interfaces import IPropertiesTool
    >>> ptool = getUtility(IPropertiesTool)
    >>> ptool.cdn_properties.enable_cdn_css == True
    False
    >>> ptool.cdn_properties.enable_cdn_js == True
    False
    >>> ptool.cdn_properties.enable_cdn_kss == True
    False
    >>> hostnames =  ['foobar','barfoo','barbar']
    >>> ptool.cdn_properties.cdn_hostname = hostnames


Multiple Hostname Support
--------------------------

Access the portal home and count the occurrences of 'portal_javascripts', 
'portal_css' and 'portal_kss'::

    >>> browser.handleErrors = False
    >>> browser.open('http://nohost/plone/')
    >>> pJsCount = browser.contents.count('http://nohost/plone/portal_javascripts')
    >>> pCssCount = browser.contents.count('http://nohost/plone/portal_css')
    >>> pKssCount = browser.contents.count('http://nohost/plone/portal_kss')

Now we will enable support for deploying skin objects from alternate hostnames, 
so we access the control panel and enable the cdn support::

Login as portal manager::

    >>> from plone.app.testing import SITE_OWNER_NAME, SITE_OWNER_PASSWORD
    >>> browser.open('http://nohost/plone/login_form')
    >>> browser.getControl(name='__ac_name').value = SITE_OWNER_NAME
    >>> browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD
    >>> browser.getControl(name='submit').click()
    
    >>> browser.open('http://nohost/plone/@@cdn-controlpanel')
    >>> browser.url.endswith('cdn-controlpanel')
    True
    >>> browser.getControl(name='form.enable_cdn_css').value = True
    >>> browser.getControl(name='form.enable_cdn_js').value = True
    >>> browser.getControl(name='form.enable_cdn_kss').value = True

Choose 'MultipleHostnames' as our CDN provider::

    >>> browser.getControl(name='form.cdn_provider').value = ['MultipleHostnames',]

Add hostnames::

    >>> browser.getControl(name='form.cdn_hostname.add').click()
    >>> browser.getControl(name='form.cdn_hostname.0.').value = 'foobar'
    >>> browser.getControl(name='form.cdn_hostname.add').click()
    >>> browser.getControl(name='form.cdn_hostname.1.').value = 'barfoo'
    >>> browser.getControl(name='form.cdn_hostname.add').click()
    >>> browser.getControl(name='form.cdn_hostname.2.').value = 'barbar'


Values for this alternate hostname::
    
    >>> browser.getControl(name='form.cdn_port').value = '80'
    >>> browser.getControl(name='form.cdn_path').value = 'longpath'
    
And click the save button::

    >>> browser.getControl(name="form.actions.save").click()
    >>> browser.url.endswith('cdn-controlpanel')
    True
    >>> 'Changes saved.' in browser.contents
    True

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

    >>> ptool.cdn_properties.enable_cdn_css
    True
    >>> ptool.cdn_properties.enable_cdn_js
    True
    >>> ptool.cdn_properties.enable_cdn_kss
    True
    >>> ptool.cdn_properties.cdn_provider
    u'MultipleHostnames'
    >>> ptool.cdn_properties.cdn_hostname
    (u'foobar', u'barfoo', u'barbar')
    >>> ptool.cdn_properties.cdn_port
    80
    >>> ptool.cdn_properties.cdn_path
    u'longpath'

Now we, again, access the portal home and changes must have been applied. To
be certain we will count the occurrences of 'portal_javascripts', 'portal_css'
 and 'portal_kss' and these numbers should match the ones we measured before ::

    >>> browser.open('http://nohost/plone/logout')
    >>> browser.handleErrors = False
    >>> browser.open('http://nohost/plone/')
    >>> pJsCDNCount = pCssCDNCount = pKssCDNCount = 0
    >>> for hostname in hostnames:
    ...     pJsCDNCount += browser.contents.count('http://%s/longpath/plone/portal_javascripts' % hostname)
    ...     pCssCDNCount += browser.contents.count('http://%s/longpath/plone/portal_css' % hostname)
    ...     pKssCDNCount += browser.contents.count('http://%s/longpath/plone/portal_kss' % hostname)
    >>> pJsCount == pJsCDNCount
    True
    >>> pCssCount == pCssCDNCount
    True
    >>> pKssCount == pKssCDNCount
    True

Let's turn everything back to factory settings by disabling 
MultipleHostnames caching::

    >>> browser.open('http://nohost/plone/login_form')
    >>> browser.getControl(name='__ac_name').value = SITE_OWNER_NAME
    >>> browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD
    >>> browser.getControl(name='submit').click()

    >>> browser.open('http://nohost/plone/@@cdn-controlpanel')
    >>> browser.url.endswith('cdn-controlpanel')
    True
    >>> browser.getControl(name='form.enable_cdn_css').value = False
    >>> browser.getControl(name='form.enable_cdn_js').value = False
    >>> browser.getControl(name='form.enable_cdn_kss').value = False
    >>> browser.getControl(name='form.cdn_provider').value = ['MultipleHostnames',]
    >>> browser.getControl(name="form.actions.save").click()
    >>> browser.url.endswith('cdn-controlpanel')
    True
    >>> 'Changes saved.' in browser.contents
    True

