Next previous navigation
========================

Say we have a 'Folder' content type::

  >>> portal = layer['portal']
  >>> from plone.dexterity.fti import DexterityFTI
  >>> fti = DexterityFTI('folder')
  >>> portal.portal_types._setObject('folder', fti)
  'folder'
  >>> fti.klass = 'plone.dexterity.content.Container'
  >>> fti.filter_content_types = False

We can declare that it supports the "Next previous navigation toggle" behavior defined in
plone.app.dexterity (normally this would be done via Generic Setup)::

  >>> fti.behaviors = ('plone.app.dexterity.behaviors.nextprevious.INextPreviousToggle',
  ...                  'plone.app.dexterity.behaviors.metadata.IBasic')

Now let's fire up the browser and add a Folder::

  >>> from plone.app.testing import TEST_USER_ID, TEST_USER_NAME, TEST_USER_PASSWORD, setRoles
  >>> setRoles(portal, TEST_USER_ID, ['Manager'])
  >>> import transaction; transaction.commit()
  >>> from plone.testing.z2 import Browser
  >>> browser = Browser(layer['app'])
  >>> browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,))

  >>> browser.open('http://nohost/plone/++add++folder')
  >>> browser.getControl('Title').value = 'Folder'
  >>> nextPreviousEnabled = browser.getControl('Enable next previous navigation')

The default "Enable next previous navigation" value is taken from the parent folder::

  >>> nextPreviousEnabled.selected
  False

We'll set it to True instead::

  >>> nextPreviousEnabled.selected = True
  >>> browser.getControl('Save').click()
  >>> browser.url
  'http://nohost/plone/folder/view'

When creating a sub-folder, the default "Enable next previous navigation" value is now True::

  >>> browser.open('http://nohost/plone/folder/++add++folder')
  >>> browser.getControl('Title').value = 'Sub Folder'
  >>> nextPreviousEnabled = browser.getControl('Enable next previous navigation')
  >>> nextPreviousEnabled.selected
  True

We'll continue and create another sub-folder::

  >>> browser.getControl('Save').click()
  >>> browser.url
  'http://nohost/plone/folder/folder/view'
  >>> browser.open('http://nohost/plone/folder/++add++folder')
  >>> browser.getControl('Title').value = 'Another Sub Folder'
  >>> browser.getControl('Save').click()
  >>> browser.url
  'http://nohost/plone/folder/folder-1/view'

We can see the next and previous links::

  >>> previous = browser.getLink('Previous')
  >>> previous.url
  'http://nohost/plone/folder/folder'
  >>> previous.click()
  >>> next = browser.getLink('Next')
  >>> next.url
  'http://nohost/plone/folder/folder-1'

The next previous setting is looked up on the parent, so even if we disable
next previous navigation for one of the sub-folders, when viewing the
sub-folder itself the next link will still be shown::

  >>> browser.open('http://nohost/plone/folder/folder/edit')
  >>> nextPreviousEnabled = browser.getControl('Enable next previous navigation')
  >>> nextPreviousEnabled.selected = False
  >>> browser.getControl('Save').click()
  >>> next = browser.getLink('Next')
  >>> next.url
  'http://nohost/plone/folder/folder-1'

Only when we disable the next previous setting on the parent does the next
link disappear::

  >>> browser.open('http://nohost/plone/folder/edit')
  >>> nextPreviousEnabled = browser.getControl('Enable next previous navigation')
  >>> nextPreviousEnabled.selected = False
  >>> browser.getControl('Save').click()
  >>> browser.open('http://nohost/plone/folder/folder')
  >>> next = browser.getLink('Next')
  Traceback (most recent call last):
  ...
  LinkNotFoundError
