Five Site Manager
=================

In this test we want to test Five's implementation of a site manager.
First, we need to set a few things up...

  >>> from zope.app.tests.placelesssetup import setUp, tearDown
  >>> setUp()

  >>> import Products.Five
  >>> from Products.Five import zcml
  >>> zcml.load_config("meta.zcml", Products.Five)
  >>> zcml.load_config("permissions.zcml", Products.Five)
  >>> zcml.load_config("configure.zcml", Products.Five.site)
  >>> zcml_text = """\
  ... <five:localsite
  ...     xmlns:five="http://namespaces.zope.org/five"
  ...     class="Products.Five.site.tests.dummy.DummySite" />"""
  >>> zcml.load_string(zcml_text)

...for example some sort of site object:

  >>> from Products.Five.site.tests.dummy import manage_addDummySite
  >>> nothing = manage_addDummySite(self.folder, 'dummysite')
  >>> dummysite = self.folder.dummysite


Local vs. global sites
----------------------

Let's make the possible site a real site:

  >>> from Products.Five.site.localsite import enableLocalSiteHook
  >>> enableLocalSiteHook(dummysite)

and tell Zope 3 about it:

  >>> from zope.app.component.hooks import setSite
  >>> setSite(dummysite)

That seems to have worked (we test this by using the context property
of FiveSiteManager):

  >>> from zope.app import zapi
  >>> zapi.getServices().context == dummysite
  True

Since there's no other local site in between this one and the global
one, the next site manager is the global one:

  >>> from zope.app import zapi
  >>> zapi.getServices().next is zapi.getGlobalServices()
  True

The Zope 3 API agrees with that:

  >>> from zope.app.component.localservice import getNextServices
  >>> getNextServices(dummysite.getSiteManager()) is zapi.getGlobalServices()
  True


IServiceService API
-------------------

Test the IServiceService API here.  It isn't really important because
it's going to go away anyways, but still...

  >>> from pprint import pprint
  >>> pprint(zapi.getServices().getServiceDefinitions())
  [('Services', <InterfaceClass zope.component.interfaces.IServiceService>),
   ('Presentation',
   <InterfaceClass zope.component.interfaces.IPresentationService>),
   ('Adapters', <InterfaceClass zope.component.interfaces.IAdapterService>),
   ('Utilities', <InterfaceClass zope.component.interfaces.IUtilityService>)]

  >>> zapi.getServices().getInterfaceFor(zapi.servicenames.Utilities)
  <InterfaceClass zope.component.interfaces.IUtilityService>

  >>> zapi.getService(zapi.servicenames.Adapters) is \
  ...     zapi.getGlobalService(zapi.servicenames.Adapters)
  True

  >>> from Products.Five.site.interfaces import IFiveUtilityService
  >>> IFiveUtilityService.providedBy(zapi.getService(zapi.servicenames.Utilities))
  True


Nesting sites
-------------

Let's set up another site to test nested sites:

  >>> nothing = manage_addDummySite(self.folder.dummysite, 'subsite')
  >>> subsite = self.folder.dummysite.subsite

Now we set the current site to the ``subsite``:

  >>> enableLocalSiteHook(subsite)
  >>> setSite(subsite)

When we call getServices() now, we get the correct site manager:

  >>> zapi.getServices().context == subsite
  True

The "next" site is the less local one:

  >>> zapi.getServices().next.context == dummysite
  True

The Zope 3 API for this agrees with that:

  >>> getNextServices(subsite.getSiteManager()).context == dummysite
  True


Finally, some clean up:

  >>> tearDown()
