
Setup
-----

  >>> result = self.portal.portal_setup.runAllImportStepsFromProfile(
  ...   'profile-plone.app.iterate:plone.app.iterate')

  >>> from Products.Five.testbrowser import Browser
  >>> from Testing.ZopeTestCase import user_password
  >>> browser = Browser()
  >>> browser.handleErrors = False
  >>> 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'], [])
  <PloneUser '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

Folders
-------

Turn on versioning for folders.

  >>> from Products.CMFCore.utils import getToolByName
  >>> tool = getToolByName(portal, 'portal_repository')
  >>> tool.addPolicyForContentType('Folder', u'at_edit_autoversion')
  >>> tool.addPolicyForContentType('Folder', u'version_on_revert')
  >>> versionable_types = tool.getVersionableContentTypes()
  >>> versionable_types.append('Folder')
  >>> tool.setVersionableContentTypes(versionable_types)

Go to our folder and create a folder.

  >>> browser = Browser()
  >>> browser.handleErrors = False
  >>> browser.addHeader('Authorization',
  ...                   'Basic %s:%s' % ('portal_owner', user_password))
  >>> browser.open(self.portal.absolute_url())
  >>> browser.getLink('Folder').click()
  >>> browser.getControl('Title').value = 'Foo Folder'
  >>> browser.getControl('Save').click()
  >>> 'Changes saved.' in browser.contents
  True

Add an item to the folder.

  >>> browser.getLink('Foo Folder').click()
  >>> browser.getLink('Page').click()
  >>> browser.getControl('Title').value = 'Bar Page'
  >>> browser.getControl('Save').click()
  >>> 'Changes saved.' in browser.contents
  True

Check out the folder.

  >>> browser.getLink('Foo Folder').click()
  >>> browser.open(browser.url + '/@@content-checkout')
  >>> 'This is a working copy' in browser.contents
  True
  >>> wc_url = browser.url
  >>> wc_url
  'http://nohost/plone/copy_of_foo-folder'

Add another item to the checked out copy.

  >>> browser.getLink('Page').click()
  >>> browser.getControl('Title').value = 'Qux Page'
  >>> browser.getControl('Save').click()
  >>> 'Changes saved.' in browser.contents
  True

Now that we've added another item, check the working copy in.

  >>> browser.open(wc_url)
  >>> browser.open(browser.url + '/@@content-checkin')
  >>> browser.getControl('Check in').click()
  >>> 'Checked in' in browser.contents
  True
  >>> browser.url
  'http://nohost/plone/foo-folder'
  >>> browser.getLink('Qux Page')
  <Link text='Qux Page' url='http://nohost/plone/foo-folder/qux-page'>

Bugs
----

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

Some items, like the Plone site root, don't do references.  This broke
the condition for the "Cancel check-out" action on these items
(#8737):

  >>> self.loginAsPortalOwner()
  >>> if 'front-page' in portal:
  ...     portal.manage_delObjects(['front-page'])
  >>> browser.open(portal.absolute_url())
