================
 Link Rendering
================

`test link rendering as a multiadapter`

wicked uses browser:page to take care of setting up the multiadapter +
template binding.  Lazy? yes. Future safe? probably better than hand
rolling.

    >>> from zope.component import getMultiAdapter
    >>> from Products.wicked.interfaces import IAmWicked
    >>> from Products.wicked import browser
    >>> try:
    ...     from zope.publisher.interfaces.browser import IDefaultBrowserLayer
    ... except:
    ...     from zope.publisher.interfaces.browser import IBrowserRequest as IDefaultBrowserLayer
    >>> from Products.Five.utilities.marker import mark
    >>> from zope.app.testing.placelesssetup import setUp, tearDown
    >>> from Products.Five import zcml
    >>> import Products.Five
    >>> import Products.testing as testing
    >>> setUp()
    >>> zcml.load_config('meta.zcml', Products.Five)
    >>> zcml.load_config("permissions.zcml", Products.Five)
    >>> zcml.load_config("renderer.zcml", browser)
    >>> zcml.load_config("traversal.zcml", testing)
    >>> from Products.Five.tests.testing import manage_addFiveTraversableFolder
    >>> from Products.wicked.lib.testing.general import dummy
    >>> request = dummy(dict(physicalPathToURL=lambda x, y, z: 'http://url'),
    ...                 iface=IDefaultBrowserLayer, name='request')
    >>> manage_addFiveTraversableFolder(self.folder, 'testfo', title='folder')
    >>> context = self.folder.testfo
    >>> mark(context, IAmWicked)
    >>> from zope.interface import Interface
    >>> renderer = getMultiAdapter((context, request), Interface, 'link_renderer')
    >>> renderer = self.folder.testfo.restrictedTraverse('@@link_renderer')
    >>> link=dict(path='/apath',
    ...           icon='anicon.ico',
    ...           uid='uid')
    >>> renderer.load([link], 'Chunk')
    >>> renderer.section='fieldname'
    >>> from Products.wicked.lib.testing.xml import xstrip
    >>> print  xstrip(renderer())
    <span class="wicked_resolved" id="fieldname-uid"><a href="http://nohost/apath"><img src="anicon.ico"><span class="chunk">Chunk</span></a></span>
    ...

    >>> renderer.load([link], u'laboratoire de g\u00E9omatique')
    >>> xstrip(renderer())
    '<span class="wicked_resolved" id="fieldname-uid"><a href="http://nohost/apath"><img src="anicon.ico"><span class="chunk">laboratoire de g\xc3\xa9omatique</span></a></span>\n'

    >>> renderer.load([], 'Chunk 2')
    >>> print xstrip(renderer())
    <span class="wicked_unresolved" id="fieldname-1"><a class="wickedadd" href="http://nohost/test_folder_1_/testfo/@@wickedadd?Title=Chunk%202&amp;section=fieldname"><span class="chunk">Chunk 2</span>+</a></span>
    ...

    >>> renderer.load([], u'laboratoire de g\u00E9omatique')

for some reason, the ampersand is being escaped too::

    >>> xstrip(renderer()) 
    '<span class="wicked_unresolved" id="fieldname-2"><a class="wickedadd" href="http://nohost/test_folder_1_/testfo/@@wickedadd?Title=laboratoire%20de%20g%C3%A9omatique&amp;section=fieldname"><span class="chunk">laboratoire de g\xc3\xa9omatique</span>+</a></span>\n'

Test counter::

    >>> renderer.load([], 'Chunk 3')
    >>> print xstrip(renderer())
    <span class="wicked_unresolved" id="fieldname-3"><a class="wickedadd" href="http://nohost/test_folder_1_/testfo/@@wickedadd?Title=Chunk%203&amp;section=fieldname"><span class="chunk">Chunk 3</span>+</a></span>...

Cleanup::

    >>> tearDown()
