Document Views
--------------

Set up Document and user.

    >>> from Products.CMFDefault.Document import Document
    >>> id = app.site._setObject('myDocument', Document('myDocument'))

    >>> uf = app.site.acl_users
    >>> uf._doAddUser('mgr', 'mgrpw', ['Manager'], [])
    >>> from zope.app.component.hooks import setSite
    >>> setSite(app.site)

Create the browser object we'll be using.

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
    >>> browser.handleErrors = False
    >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')

Use the edit form with invalid input.

    >>> browser.open('http://localhost/site/myDocument/@@edit.html')
    >>> browser.getControl('[[cmf_default][Body]]').value = '<script>'
    >>> browser.getControl('[[cmf_default][Change]]').click()
    >>> '[[zope][There were errors]]' in browser.contents
    True
    >>> '[[cmf_default][Dynamic tag \'script\' not ' in browser.contents
    True

Use the edit form with valid input.

    >>> browser.getControl('[[cmf_default][Body]]').value = 'spam'
    >>> browser.getControl('[[cmf_default][Change]]').click()
    >>> '[[zope][There were errors]]' in browser.contents
    False

Look at the result.

    >>> browser.open('http://localhost/site/myDocument/@@view.html')
    >>> 'spam' in browser.contents
    True

Changes can't be saved if the safety belt is invalid.

    >>> browser.open('http://localhost/site/myDocument/@@edit.html')

    >>> app.site.myDocument._safety_belt = '1'

    >>> browser.getControl('[[cmf_default][Body]]').value = 'spam and eggs'
    >>> browser.getControl('[[cmf_default][Change]]').click()
    >>> '[[zope][There were errors]]' in browser.contents
    True
    >>> '[[cmf_default][Intervening changes from ' in browser.contents
    True

Changes can't be saved if the document is locked.

    >>> browser.open('http://localhost/site/myDocument/@@edit.html')

    >>> from webdav.LockItem import LockItem
    >>> lock = LockItem(uf.getUser('mgr').__of__(uf))
    >>> app.site.myDocument.wl_setLock(lock.getLockToken(), lock)

    >>> browser.getControl('[[cmf_default][Body]]').value = 'spam and eggs'
    >>> browser.getControl('[[cmf_default][Change]]').click()
    >>> '[[zope][There were errors]]' in browser.contents
    True
    >>> '[[cmf_default][This resource is locked ' in browser.contents
    True
