Archetypes edit forms
---------------------

Here we want to test the standard edit view for Archetypes objects.

Let's set up a test browser:

  >>> from Products.Five.testbrowser import Browser
  >>> browser = Browser()
  >>> browser.handleErrors = False

Set the authorization headers:

  >>> browser.addHeader('Authorization',
  ...                   'Basic %s:%s' % ('test_user_1_', 'secret'))

Field validation
----------------

Let's add a new document and verify that required fields are actually
required -- across schemata.

  >>> id = folder.invokeFactory(id='document', type_name='Document')
  >>> document = folder[id]
  >>> document.setTitle('Test document')
  
  >>> url = document.absolute_url()

We'll try and set the title (a required field) to the empty string:
  
  >>> document.Schema().getField('title').required
  1
  >>> browser.open(url+'/edit')
  >>> browser.getControl('Title').value = ''
  >>> browser.getControl('Save').click()

We're not allowed to do so:
  
  >>> document.title_or_id()
  'Test document'

What if title was in a different schemata? This is interesting to examine
since the default edit view now includes fields from all schematas and
we want to make sure all of them are validated.

  >>> schema = document.__class__.schema
  >>> previous_schemata = schema['title'].schemata
  >>> schema['title'].schemata = 'categorization'

  >>> document.Schema().getField('title').schemata
  'categorization'
  >>> browser.open(url+'/edit')
  >>> browser.getControl('Title').value = ''
  >>> browser.getControl('Save').click()
  >>> document.title_or_id()
  'Test document'

  >>> schema['title'].schemata = previous_schemata


Buttons name verification
----------------

Let's verify that the buttons have the correct name:
  
  >>> browser.open(url+'/edit')
  >>> browser.getControl('Save').name
  'form.button.save'
  
  >>> browser.getControl('Cancel').name
  'form.button.cancel'
  
Now to see the previous and next buttons, we need to make the
document provide Products.Archetypes.interfaces.IMultiPageSchema
and change the schemata of one of its fields

  >>> from Products.Archetypes.interfaces import IMultiPageSchema
  >>> from Products.Five.utilities import marker
  >>> from zope import interface
  >>> IMultiPageSchema.providedBy(document)
  False
  >>> interface.alsoProvides(document, IMultiPageSchema)

  >>> schema = document.__class__.schema
  >>> previous_schemata = schema['text'].schemata
  >>> schema['text'].schemata = 'someschemata'

  >>> document.Schema().getField('text').schemata
  'someschemata'
  
  >>> browser.open(url+'/edit')
  >>> browser.getControl('Next').name
  'form.button.next'
  
  >>> browser.getLink('someschemata').click()
  >>> browser.getControl('Previous').name
  'form.button.previous'

  >>> marker.erase(document, IMultiPageSchema)
  >>> IMultiPageSchema.providedBy(document)
  False
  >>> schema['text'].schemata = previous_schemata
  

  
TODO: Add more general editing testing!
