1##############################################################################
2#
3# Copyright (c) 2005 Zope Foundation and Contributors.
4# All Rights Reserved.
5#
6# This software is subject to the provisions of the Zope Public License,
7# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11# FOR A PARTICULAR PURPOSE.
12#
13##############################################################################
14"""Traversing test fixtures
15"""
16__docformat__ = "reStructuredText"
17
18import zope.component
19import zope.interface
20from zope.publisher.interfaces.browser import IDefaultBrowserLayer
21from zope.location.traversing \
22    import LocationPhysicallyLocatable, RootPhysicallyLocatable
23from zope.location.interfaces import ILocationInfo, IRoot
24from zope.traversing.interfaces import ITraversable, ITraverser
25from zope.traversing.adapters import DefaultTraversable
26from zope.traversing.adapters import Traverser
27from zope.traversing.browser import SiteAbsoluteURL, AbsoluteURL
28from zope.traversing.browser.interfaces import IAbsoluteURL
29from zope.traversing.namespace import etc
30
31def setUp():
32    zope.component.provideAdapter(Traverser, (None,), ITraverser)
33    zope.component.provideAdapter(DefaultTraversable, (None,), ITraversable)
34    zope.component.provideAdapter(LocationPhysicallyLocatable,
35                                  (None,), ILocationInfo)
36    zope.component.provideAdapter(RootPhysicallyLocatable,
37                                  (IRoot,), ILocationInfo)
38    # set up the 'etc' namespace
39    zope.component.provideAdapter(etc, (None,), ITraversable, name="etc")
40    zope.component.provideAdapter(etc, (None, None), ITraversable, name="etc")
41
42    browserView(None, "absolute_url", AbsoluteURL)
43    browserView(IRoot, "absolute_url", SiteAbsoluteURL)
44
45    browserView(None, '', AbsoluteURL, providing=IAbsoluteURL)
46    browserView(IRoot, '', SiteAbsoluteURL, providing=IAbsoluteURL)
47
48
49def browserView(for_, name, factory, providing=zope.interface.Interface):
50    zope.component.provideAdapter(factory, (for_, IDefaultBrowserLayer),
51                                  providing, name=name)
52
53def browserResource(name, factory, providing=zope.interface.Interface):
54    zope.component.provideAdapter(factory, (IDefaultBrowserLayer,),
55                                  providing, name=name)
56