.. -*-doctest-*-

===============
History Viewlet
===============

We use zope.testbrowser to simulate browser interaction in order to show how
the history viewlet works.

Open a browser logged in as a Manager.

    >>> app = layer['app']
    >>> from plone.testing.zope import Browser
    >>> from plone.app.testing import SITE_OWNER_PASSWORD
    >>> browser = Browser(app)
    >>> browser.handleErrors = False
    >>> browser.addHeader('Authorization', f'Basic admin:{SITE_OWNER_PASSWORD}')
    >>> portal_url = 'http://nohost/plone'

By default, only HTTP error codes (e.g. 500 Server Side Error) are shown when an
error occurs on the server. To see more details, set handleErrors to False:

    >>> browser.handleErrors = False

Create a public page without workflow.

    >>> browser.open(portal_url)
    >>> browser.follow(id='document')
    >>> browser.getControl('Title').value = "Doc1"
    >>> browser.getControl('Save').click()
    >>> urldoc1 = browser.url

Check that the form has been properly submitted

    >>> browser.url
    'http://nohost/plone/doc1/view'

The history viewlet gracefully handles content without workflow.

    >>> browser.follow(url='@@historyview')

Create a public page with workflow.

    >>> portal = layer['portal']
    >>> portal.portal_workflow.setDefaultChain('simple_publication_workflow')

    >>> import transaction
    >>> transaction.commit()

    >>> browser.open(portal_url)
    >>> browser.follow(id='document')
    >>> browser.getControl('Title').value = "Doc2"
    >>> browser.getControl('Summary').value = "First revision"
    >>> browser.getControl('Save').click()
    >>> urldoc2 = browser.url

The history viewlet gracefully handles initial default workflow state.

    >>> browser.follow(url='@@historyview')
    >>> from __future__ import print_function
    >>> print(browser.contents)
    <...<span class="historyAction state-private">Create</span>...


The history viewlet handles revert actions sucessfully. Let's make a revision.

    >>> browser.open(urldoc2)
    >>> browser.follow('Edit')
    >>> browser.getControl('Summary').value = "Changed for revision 2"
    >>> browser.getControl('Save').click()

The history viewlet now shows a Revert button.

    >>> browser.follow(url='@@historyview')
    >>> browser.contents
    '...<button class="btn btn-warning" type="submit">Revert to this revision</button>...'

After action success, user is redirected to Document, reverted to chosen revision.

    >>> browser.getControl('Revert').click()
    >>> browser.url in urldoc2
    True
    >>> browser.contents
    '...<p class="lead">First revision</p>...'
