Back to index

plone3  3.1.7
testCopyRename.py
Go to the documentation of this file.
00001 #
00002 # Test copying/pasting of controller objects
00003 #
00004 
00005 import unittest
00006 
00007 try:
00008     from Products.PloneTestCase import PloneTestCase
00009     PloneTestCase.setupPloneSite()
00010     HAS_PLONE = True
00011 except ImportError:
00012     HAS_PLONE = False
00013 
00014 from Products.CMFFormController.FormAction import FormAction
00015 from Products.CMFFormController.FormValidator import FormValidator
00016 import transaction
00017 
00018 if HAS_PLONE:
00019     class TestCopyRename(PloneTestCase.PloneTestCase):
00020 
00021         def testRename(self):
00022             formcontroller = self.portal.portal_form_controller
00023             self.folder.manage_addProduct['CMFFormController'].manage_addControllerPageTemplate('test', 'Test', '<html>test</html>')
00024 
00025             pt = self.folder.test
00026             pt.actions.set(FormAction(pt.getId(), 'success', None, None, 'traverse_to', 'test3', self.portal.portal_form_controller))
00027             self.assertEqual(len(pt.actions.getFiltered(object_id='test')), 1)
00028             self.assertEqual(pt.actions.match('test', 'success', 'Document', 'submit').getActionArg(), 'test3')
00029 
00030             pt.validators.set(FormValidator(pt.getId(), None, None, 'a,b,c', self.portal.portal_form_controller))
00031             self.assertEqual(len(pt.validators.getFiltered(object_id='test')), 1)
00032             self.assertEqual(pt.validators.match('test', 'Document', 'submit').getValidators(), ['a','b','c'])
00033         
00034             formcontroller.actions.set(FormAction(pt.getId(), 'success', None, None, 'traverse_to', 'test4', self.portal.portal_form_controller))
00035             self.assertEqual(len(formcontroller.actions.getFiltered(object_id='test')), 1)
00036             self.assertEqual(formcontroller.actions.match('test', 'success', 'Document', 'submit').getActionArg(), 'test4')
00037 
00038             formcontroller.validators.set(FormValidator(pt.getId(), None, None, 'd,e,f', self.portal.portal_form_controller))
00039             self.assertEqual(len(formcontroller.validators.getFiltered(object_id='test')), 1)
00040             self.assertEqual(formcontroller.validators.match('test', 'Document', 'submit').getValidators(), ['d','e','f'])
00041 
00042             transaction.savepoint(optimistic=True)
00043 
00044             self.loginAsPortalOwner()
00045             self.folder.manage_renameObjects(['test'], ['test2'])
00046             pt2 = self.folder.test2
00047             self.assertEqual(len(pt2.actions.getFiltered(object_id='test')), 0)
00048             self.assertEqual(len(pt2.actions.getFiltered(object_id='test2')), 1)
00049             self.assertEqual(formcontroller.actions.match('test2', 'success', 'Document', 'submit').getActionArg(), 'test4')
00050             self.assertEqual(formcontroller.actions.match('test', 'success', 'Document', 'submit').getActionArg(), 'test4')
00051 
00052             self.assertEqual(len(pt2.validators.getFiltered(object_id='test')), 0)
00053             self.assertEqual(len(pt2.validators.getFiltered(object_id='test2')), 1)
00054             self.assertEqual(formcontroller.validators.match('test2', 'Document', 'submit').getValidators(), ['d','e','f'])
00055             self.assertEqual(formcontroller.validators.match('test', 'Document', 'submit').getValidators(), ['d','e','f'])
00056 
00057             formcontroller._purge()
00058             self.assertEqual(formcontroller.validators.match('test2', 'Document', 'submit').getValidators(), ['d','e','f'])
00059             self.assertEqual(formcontroller.validators.match('test', 'Document', 'submit'), None)
00060 
00061         def testCopy(self):
00062             formcontroller = self.portal.portal_form_controller
00063             self.folder.manage_addProduct['CMFFormController'].manage_addControllerPageTemplate('test', 'Test', '<html>test</html>')
00064 
00065             pt = self.folder.test
00066             pt.actions.set(FormAction(pt.getId(), 'success', None, None, 'traverse_to', 'test3', self.portal.portal_form_controller))
00067             self.assertEqual(len(pt.actions.getFiltered()), 1)
00068             self.assertEqual(pt.actions.match('test', 'success', 'Document', 'submit').getActionArg(), 'test3')
00069 
00070             pt.validators.set(FormValidator(pt.getId(), None, None, 'a,b,c', self.portal.portal_form_controller))
00071             self.assertEqual(len(pt.validators.getFiltered(object_id='test')), 1)
00072             self.assertEqual(pt.validators.match('test', 'Document', 'submit').getValidators(), ['a','b','c'])
00073         
00074             formcontroller.actions.set(FormAction(pt.getId(), 'success', None, None, 'traverse_to', 'test4', self.portal.portal_form_controller))
00075             self.assertEqual(len(pt.actions.getFiltered()), 1)
00076             self.assertEqual(formcontroller.actions.match('test', 'success', 'Document', 'submit').getActionArg(), 'test4')
00077 
00078             formcontroller.validators.set(FormValidator(pt.getId(), None, None, 'd,e,f', self.portal.portal_form_controller))
00079             self.assertEqual(len(formcontroller.validators.getFiltered(object_id='test')), 1)
00080             self.assertEqual(formcontroller.validators.match('test', 'Document', 'submit').getValidators(), ['d','e','f'])
00081 
00082             transaction.savepoint(optimistic=True)
00083 
00084             self.loginAsPortalOwner()
00085             cb = self.folder.manage_copyObjects(['test'])
00086             self.folder.manage_pasteObjects(cb)
00087             pt2 = self.folder.copy_of_test
00088             self.assertEqual(len(pt2.actions.getFiltered(object_id='test')), 0)
00089             self.assertEqual(len(pt2.actions.getFiltered(object_id='copy_of_test')), 1)
00090             self.assertEqual(formcontroller.actions.match('copy_of_test', 'success', 'Document', 'submit').getActionArg(), 'test4')
00091             self.assertEqual(formcontroller.actions.match('test', 'success', 'Document', 'submit').getActionArg(), 'test4')
00092 
00093             self.assertEqual(len(pt2.validators.getFiltered(object_id='test')), 0)
00094             self.assertEqual(len(pt2.validators.getFiltered(object_id='copy_of_test')), 1)
00095             self.assertEqual(formcontroller.validators.match('copy_of_test', 'Document', 'submit').getValidators(), ['d','e','f'])
00096             self.assertEqual(formcontroller.validators.match('test', 'Document', 'submit').getValidators(), ['d','e','f'])
00097 
00098             formcontroller._purge()
00099             self.assertEqual(formcontroller.actions.match('test', 'success', 'Document', 'submit').getActionArg(), 'test4')
00100             self.assertEqual(formcontroller.actions.match('copy_of_test', 'success', 'Document', 'submit').getActionArg(), 'test4')
00101             self.assertEqual(formcontroller.validators.match('copy_of_test', 'Document', 'submit').getValidators(), ['d','e','f'])
00102             self.assertEqual(formcontroller.validators.match('test', 'Document', 'submit').getValidators(), ['d','e','f'])
00103 
00104 def test_suite():
00105     suite = unittest.TestSuite()
00106     if HAS_PLONE:
00107         suite.addTest(unittest.makeSuite(TestCopyRename))
00108     return suite
00109 
00110 if __name__ == '__main__':
00111     unittest.main(defaultTest="test_suite")