Permalink
Browse files

Added test to show that extension fields are not migrated.

The test is only run when archetypes.schemaextender is available.
In a Plone 4 environment this is normally the case.
  • Loading branch information...
1 parent 7b0c6ec commit 293f71b7f374f5f49dd633e3941ccc76e2351149 @mauritsvanrees mauritsvanrees committed Apr 10, 2012
@@ -0,0 +1,51 @@
+;-*-Doctest-*-
+===================================
+archetypes.schemaextender migration
+===================================
+
+This tests migration of items that have been extended with extra
+fields by archetypes.schemaextender.
+
+ >>> from Products.CMFCore.permissions import ModifyPortalContent
+ >>> from Products.PloneTestCase.setup import _createObjectByType
+ >>> self.portal.manage_permission(
+ ... ModifyPortalContent, ['Manager', 'Owner'], acquire=0)
+
+ >>> foo_doc = _createObjectByType(
+ ... 'Document', self.portal, id='foo', title='Foo', extensive_text='Extra foo')
+ >>> foo_doc.portal_type, foo_doc.getId(), foo_doc.Title()
+ ('Document', 'foo', 'Foo')
+ >>> foo_doc.getField('extensive_text').get(foo_doc)
+ 'Extra foo'
+
+ >>> bar_doc = _createObjectByType(
+ ... 'Document', self.portal, id='bar', title='Bar', extensive_text='Extra bar')
+ >>> bar_doc.portal_type, bar_doc.getId(), bar_doc.Title()
+ ('Document', 'bar', 'Bar')
+ >>> bar_doc.getField('extensive_text').get(bar_doc)
+ 'Extra bar'
+
+ >>> from transaction import commit
+ >>> commit()
+
+ >>> from Products.contentmigration.archetypes import ATItemMigrator
+ >>> foo_migrator = ATItemMigrator(foo_doc)
+ >>> foo_migrator.dst_portal_type = 'Document'
+ >>> foo_migrator.dst_meta_type = 'ATDocument'
+ >>> foo_migrator.migrate()
+ >>> foo_new = self.portal.foo
+ >>> foo_new.portal_type, foo_new.getId(), foo_new.Title()
+ ('Document', 'foo', 'Foo')
+ >>> foo_new.getField('extensive_text').get(foo_new)
+ 'Extra foo'
+
+ >>> from Products.contentmigration.archetypes import InplaceATItemMigrator
+ >>> bar_migrator = InplaceATItemMigrator(bar_doc)
+ >>> bar_migrator.dst_portal_type = 'Document'
+ >>> bar_migrator.dst_meta_type = 'ATDocument'
+ >>> bar_migrator.migrate()
+ >>> bar_new = self.portal.bar
+ >>> bar_new.portal_type, bar_new.getId(), bar_new.Title()
+ ('Document', 'bar', 'Bar')
+ >>> bar_new.getField('extensive_text').get(bar_new)
+ 'Extra bar'
@@ -0,0 +1,13 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:zcml="http://namespaces.zope.org/zcml"
+ zcml:condition="installed archetypes.schemaextender">
+
+ <include package="archetypes.schemaextender" />
+
+ <adapter
+ factory=".tests.extensions.PageExtender"
+ name="contentmigration.tests.page"
+ />
+
+</configure>
@@ -2,6 +2,7 @@
from Products.contentmigration.migrator import InlineFieldActionMigrator
from Products.contentmigration.walker import CustomQueryWalker
from Products.contentmigration.tests.layer import TestLayer
+from Products.contentmigration.tests.layer import SchemaExtenderTestLayer
import transaction
@@ -60,3 +61,8 @@ def execute(self, query, actions, callBefore=None, **kwargs):
# Need this to avoid copy errors....
transaction.savepoint(optimistic=True)
walker.go(**kwargs)
+
+
+class SchemaExtenderMigratorTestCase(ContentMigratorTestCase):
+
+ layer = SchemaExtenderTestLayer
@@ -0,0 +1,30 @@
+from Products.ATContentTypes.interface import IATDocument
+from Products.Archetypes.public import StringField
+from Products.Archetypes.public import StringWidget
+from archetypes.schemaextender.field import ExtensionField
+from archetypes.schemaextender.interfaces import ISchemaExtender
+from zope.component import adapts
+from zope.interface import implements
+
+
+class MyStringField(ExtensionField, StringField):
+ """A trivial field."""
+
+
+class PageExtender(object):
+ adapts(IATDocument) # XXX Might not work on Plone 3.
+ implements(ISchemaExtender)
+
+ fields = [
+ MyStringField(
+ "extensive_text",
+ default="default text",
+ widget=StringWidget(
+ label="This page has extensive text")),
+ ]
+
+ def __init__(self, context):
+ self.context = context
+
+ def getFields(self):
+ return self.fields
@@ -23,3 +23,20 @@ def setUp(cls):
@classmethod
def tearDown(cls):
pass
+
+
+class SchemaExtenderTestLayer(PloneSite):
+ """ layer for integration tests with archetypes.schemaextender """
+
+ @classmethod
+ def setUp(cls):
+ metaconfigure.debug_mode = True
+ from Products import contentmigration
+ zcml.load_config('testing.zcml', package=contentmigration)
+ zcml.load_config('testing-schemaextender.zcml',
+ package=contentmigration)
+ metaconfigure.debug_mode = False
+
+ @classmethod
+ def tearDown(cls):
+ pass
@@ -0,0 +1,25 @@
+from doctest import ELLIPSIS
+
+from Testing.ZopeTestCase import ZopeDocFileSuite
+
+from Products.contentmigration.tests.cmtc import SchemaExtenderMigratorTestCase
+
+
+def test_suite():
+ try:
+ import archetypes.schemaextender
+ archetypes.schemaextender # pyflakes
+ except ImportError:
+ # No tests
+ suites = ZopeDocFileSuite()
+ else:
+ suites = (
+ ZopeDocFileSuite(
+ '../schemaextender.txt',
+ package='Products.contentmigration.tests',
+ optionflags=ELLIPSIS,
+ test_class=SchemaExtenderMigratorTestCase),
+ )
+
+ from unittest import TestSuite
+ return TestSuite(suites)
View
@@ -22,7 +22,7 @@
zip_safe=False,
extras_require=dict(
test=['zope.testing', 'Zope2', 'Products.CMFPlone',
- 'Products.PloneTestCase']),
+ 'Products.PloneTestCase', 'archetypes.schemaextender']),
install_requires=[
'setuptools',
],

0 comments on commit 293f71b

Please sign in to comment.