Test if navigation is correct
=============================

Lets define some globals
>>> from plone.testing.z2 import Browser
>>> import transaction
>>> from plone.app.testing import TEST_USER_NAME, TEST_USER_PASSWORD
>>> app = layer['app']
>>> portal = layer['portal']
>>> request = layer['request']
>>> from ftw.book.portlets import gotoparent
>>> from zope.publisher.browser import BrowserView
>>> from plone.portlets.interfaces import IPortletManager
>>> from zope.component import getUtility, getMultiAdapter
>>> from plone.portlets.interfaces import IPortletAssignmentMapping
>>> from ftw.book.eventhandler import left_slot_portlets
>>> from pyquery import PyQuery


Lets create some content
>>> portal.invokeFactory('Folder', "folder")
'folder'
>>> folder = portal['folder']
>>> folder.invokeFactory('Folder', "2_level")
'2_level'
>>> secfolder = folder['2_level']
>>> secfolder.invokeFactory('Folder', "3_level", title="3. Level")
'3_level'
>>> parent_folder = secfolder['3_level']
>>> parent_folder = portal['folder']['2_level']['3_level']
>>> book = parent_folder.invokeFactory('Book', 'mybook', title="mybook")
>>> mybook = parent_folder['mybook']
>>> mybook.invokeFactory('Chapter', 'mychapter', title="mychapter")
'mychapter'
>>> left_slot_portlets(mybook)
>>> transaction.commit()
>>> browser = Browser(app)
>>> browser.open(mybook.absolute_url())
>>> pq = PyQuery(browser.contents)
>>> portletcolumn = pq('#portal-column-one')
>>> parent = portletcolumn('dl.portletGoToParent')
>>> link = parent('a')
>>> link.attr('href')
'http://nohost/plone/folder/2_level/3_level'
>>> print link('span')
<span>3. Level</span>
>>> navtree = portletcolumn('dl.portletNavigationTree')
>>> navportlet = navtree('dd.portletItem')
>>> firstitem = navportlet('li.navTreeCurrentNode')
>>> link = firstitem('a')
>>> link.attr('href')
'http://nohost/plone/folder/2_level/3_level/mybook'
>>> link('a').text()
'mybook'
>>> seconditem = navportlet('li.section-mychapter')
>>> link = seconditem('a')
>>> link.attr('href')
'http://nohost/plone/folder/2_level/3_level/mybook/mychapter'
>>> link('span').text()
'mychapter'
