Automatic filename-to-id behavior
=================================

Say we have a 'File' content type::

  >>> portal = layer['portal']
  >>> from plone.dexterity.fti import DexterityFTI
  >>> fti = DexterityFTI('file_type')
  >>> portal.portal_types._setObject('file_type', fti)
  'file_type'
  >>> fti.klass = 'plone.dexterity.content.Item'
  >>> from zope.interface import Interface, alsoProvides
  >>> from plone.namedfile.field import NamedFile
  >>> from plone.rfc822.interfaces import IPrimaryField
  >>> import plone.app.dexterity.tests
  >>> class IFile(Interface):
  ...     file = NamedFile(title=u'File')
  >>> alsoProvides(IFile['file'], IPrimaryField)
  >>> plone.app.dexterity.tests.IFile = IFile
  >>> fti.schema = 'plone.app.dexterity.tests.IFile'

We can declare that it supports the "name from file name" behavior (normally
this would be done via Generic Setup)::

  >>> fti.behaviors = ('plone.app.dexterity.behaviors.filename.INameFromFileName',
  ...     'plone.app.dexterity.behaviors.metadata.IBasic',)

Now let's fire up the browser and confirm that new content gets renamed
appropriately::

  >>> from plone.app.testing import TEST_USER_ID, TEST_USER_NAME, TEST_USER_PASSWORD, setRoles
  >>> setRoles(portal, TEST_USER_ID, ['Manager'])
  >>> import transaction; transaction.commit()
  >>> from plone.testing.z2 import Browser
  >>> browser = Browser(layer['app'])
  >>> browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,))

  >>> browser.open('http://nohost/plone/++add++file_type')
  >>> browser.getControl('Title').value = 'A test file'
  >>> from io import BytesIO
  >>> browser.getControl(name="form.widgets.file").add_file(
  ...     BytesIO(b'File contents'), 'text/plain', 'foo.txt')
  >>> browser.getControl('Save').click()
  >>> browser.url
  'http://nohost/plone/foo.txt/view'
