##########
Versioning
##########

Versioning is provided by CMFEditions product which is packaged in default
Plone 3.x installers.

CMFEditions deals with all ZODB stuff (attributes, annotations) but not out of
the box with FileSystemStorage.

Create a dummy content::

    >>> self.setRoles(('Manager',))
    >>> self.portal.invokeFactory(type_name='FSSItem', id="dummy",
    ...                           title="Foo title", text="Foo text")
    'dummy'
    >>> dummy_content = self.portal['dummy']
    >>> dummy_content
    <FSSItem at ...>

Check if data has been correctly set::

    >>> dummy_content.Title()
    'Foo title'
    >>> dummy_content.getText()
    'Foo text'

To create a new version, make sure CMFEditions is correctly configured for FSSItem portal type::

    >>> types = portal.portal_repository.getVersionableContentTypes()
    >>> new_types = set(types).union(['FSSItem'])
    >>> portal.portal_repository.setVersionableContentTypes(new_types)
    >>> 'FSSItem' in set(portal.portal_repository.getVersionableContentTypes())
    True
    >>> portal.portal_repository.isVersionable(dummy_content)
    True

Store the current version of dummy_content::

    >>> self.portal.portal_repository.save(obj=dummy_content, comment='first')
    >>> dummy_content.version_id
    0
    >>> history = self.portal.portal_repository.getHistory(obj=dummy_content)
    >>> len(history)
    1

Create another version of dummy content::

    >>> dummy_content.setTitle('Foo title 2')
    >>> dummy_content.Title()
    'Foo title 2'
    >>> dummy_content.setText('Foo text 2')
    >>> dummy_content.getText()
    'Foo text 2'
    >>> self.portal.portal_repository.save(obj=dummy_content, comment='second')
    >>> dummy_content.version_id
    1
    >>> history = self.portal.portal_repository.getHistory(obj=dummy_content)
    >>> len(history)
    2

Verify we still have the first version archived::

   >>> archive = self.portal.portal_repository.retrieve(obj=dummy_content,
   ...                                                           selector=0).object
   >>> archive.version_id
   0
   >>> archive.Title()
   'Foo title'
   >>> archive.getText()
   'Foo text'

Modify title and text fields::

    >>> dummy_content.setTitle('Foo title 3')
    >>> dummy_content.Title()
    'Foo title 3'
    >>> dummy_content.setText('Foo text 3')
    >>> dummy_content.getText()
    'Foo text 3'

Revert to first version of dummy content::

    >>> self.portal.portal_repository.revert(obj=dummy_content, selector=1)
    >>> dummy_content.version_id
    1
    >>> dummy_content.Title()
    'Foo title 2'
    >>> dummy_content.getText()
    'Foo text 2'
