
Setup
-----

  >>> self.portal.portal_quickinstaller.installProduct('plone.app.iterate')
  ''

  >>> from Products.Five.testbrowser import Browser
  >>> from Testing.ZopeTestCase import user_password
  >>> browser = Browser()
  >>> browser.addHeader('Authorization',
  ...                   'Basic %s:%s' % ('portal_owner', user_password))

Create a document
-----------------

Go to our folder and create a document:

  >>> browser.open(self.portal.absolute_url())
  >>> browser.getLink('Add new').click()
  >>> 'Add new item' in browser.contents
  True
  >>> browser.getControl('Page').click()
  >>> browser.getControl('Add').click()
  >>> browser.getControl('Title').value = 'Hello, World!'
  >>> browser.getControl('Body Text').value = 'Hello, World!'
  >>> browser.getControl('Save').click()
  >>> 'Changes saved.' in browser.contents
  True

Check it out
------------

Let's check out the document.  For this, we'll go to the *Check out*
form directly.  From there, we'll check out to the parent folder:

  >>> browser.open(browser.url + '/@@content-checkout')
  >>> 'This is a working copy' in browser.contents
  True
  >>> browser.url
  'http://nohost/plone/copy_of_hello-world'

When viewing the original document, we should see a note that
someone's working on a working copy:

  >>> browser.open('http://nohost/plone/hello-world')
  >>> 'This item is being edited' in browser.contents
  True

We'll now edit the working copy and save it:

  >>> browser.open('http://nohost/plone/copy_of_hello-world/edit')
  >>> browser.getControl('Title').value = 'Hello, World! version 2.0'
  >>> browser.getControl('Save').click()
  >>> 'Changes saved.' in browser.contents
  True
  >>> browser.url
  'http://nohost/plone/copy_of_hello-world'

Check it in
-----------

Now that we've made our changes we'll check the working copy in:

  >>> browser.open(browser.url + '/@@content-checkin')
  >>> browser.getControl('Check in').click()
  >>> 'Checked in' in browser.contents
  True
  >>> browser.url
  'http://nohost/plone/hello-world'
  >>> 'Hello, World! version 2.0' in browser.contents
  True

Permissions
-----------

For the community workflow, we expect Editors to be able to check out
published pages:

  >>> portal.portal_workflow.setDefaultChain('plone_workflow')
  >>> ignore = portal.portal_workflow.updateRoleMappings()
  >>> browser.getLink("Publish").click()
  >>> "Item state changed" in browser.contents
  True

  >>> portal.acl_users._doAddUser('editor' , 'secret', ['Editor'], [])
  >>> portal.portal_membership.memberareaCreationFlag = 1
  >>> portal.portal_membership.createMemberArea('editor')
  >>> browser = Browser()
  >>> browser.addHeader('Authorization', 'Basic editor:secret')

  >>> browser.open(portal.absolute_url() + '/hello-world')
  >>> browser.getLink("Check out").click()
  >>> "Check-out created" in browser.contents
  True

They should not, however, be able to check in their working copy
again.  That's because the item is in the ``published`` state and
therefore our Editor lacks permissions to modify the original:

  >>> browser.getLink("Cancel check-out")
  <Link ...>
  >>> browser.getLink("Check in")
  Traceback (most recent call last):
  ...
  LinkNotFoundError

The Editor could, however, retract the original to gain permissions
again and check in (and then possibly request for review):

  >>> browser.open(portal.absolute_url() + '/hello-world')
  >>> browser.getLink("Published").click()
  >>> browser.getControl("Retract").click()
  >>> browser.getControl("Save").click()
  >>> browser.getLink("working copy").click()
  >>> browser.getLink("Check in").click()
  >>> browser.getControl("Check in").click()
  >>> "Checked in" in browser.contents
  True

The "Cancel check-out" action should not be present on items that are
not checked out (#8735):

  >>> browser.getLink("Cancel check-out")
  Traceback (most recent call last):
  ...
  LinkNotFoundError
