Back to index

plone3  3.1.7
testCMFPlacefulWorkflow.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 ## CMFPlacefulWorkflow
00003 ## Copyright (C)2005 Ingeniweb
00004 
00005 ## This program is free software; you can redistribute it and/or modify
00006 ## it under the terms of the GNU General Public License as published by
00007 ## the Free Software Foundation; either version 2 of the License, or
00008 ## (at your option) any later version.
00009 
00010 ## This program is distributed in the hope that it will be useful,
00011 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ## GNU General Public License for more details.
00014 
00015 ## You should have received a copy of the GNU General Public License
00016 ## along with this program; see the file COPYING. If not, write to the
00017 ## Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 """
00019 CMFPlacefulWorkflow Unittest
00020 """
00021 __version__ = "$Revision: 61119 $"
00022 # $Source: /cvsroot/ingeniweb/CMFPlacefulWorkflow/tests/testCMFPlacefulWorkflow.py,v $
00023 # $Id: testCMFPlacefulWorkflow.py 61119 2008-03-25 14:21:45Z encolpe $
00024 __docformat__ = 'restructuredtext'
00025 
00026 
00027 import transaction
00028 from Testing import ZopeTestCase
00029 from zExceptions import Forbidden
00030 from Products.PloneTestCase import PloneTestCase
00031 
00032 from Products.CMFPlacefulWorkflow.PlacefulWorkflowTool import WorkflowPolicyConfig_id
00033 from Products.CMFPlacefulWorkflow.interfaces import IPlacefulMarker
00034 from CMFPlacefulWorkflowTestCase import CMFPlacefulWorkflowTestCase
00035 
00036 try:
00037     _standard_permissions = ZopeTestCase._standard_permissions
00038 except AttributeError:
00039     _standard_permissions = ZopeTestCase.standard_permissions
00040 
00041 _edit_permissions     = [] # [PlacefulWorkflowPolicy_editPermission,]
00042 _all_permissions      = _edit_permissions
00043 
00044 #Install our product
00045 PloneTestCase.installProduct('CMFPlacefulWorkflow')
00046 PloneTestCase.setupPloneSite()
00047 
00048 # Other imports
00049 from Products.CMFCore.utils import getToolByName
00050 
00051 class TestPlacefulWorkflow(CMFPlacefulWorkflowTestCase):
00052     """ Testing all add-on and modified method for workflow stuff """
00053 
00054     def createMember(self, id, pw, email, roles=('Member',)):
00055         pr = self.portal.portal_registration
00056         member = pr.addMember(id, pw, roles, properties={ 'username': id, 'email' : email })
00057         #self.failUnless(id in self.portal.Members.objectIds())
00058         return member
00059 
00060     def installation(self, productName):
00061         self.qi = self.portal.portal_quickinstaller
00062         self.qi.installProduct(productName)
00063 
00064     def setupSecurityContext(self,):
00065         self.logout()
00066         self.loginAsPortalOwner()
00067         # Create a few members
00068         self.user1 = self.createMember('user1', 'abcd4', 'abc@domain.tld')
00069         self.user2 = self.createMember('user2', 'abcd4', 'abc@domain.tld')
00070         self.user3 = self.createMember('user3', 'abcd4', 'abc@domain.tld')
00071 
00072         self.folder = self.portal.portal_membership.getHomeFolder('user1')
00073         self.installation('CMFPlacefulWorkflow')
00074         self.logout()
00075 
00076     def afterSetUp(self,):
00077         """
00078         afterSetUp(self) => This method is called to create an empty PloneArticle.
00079         It also joins three users called 'user1', 'user2' and 'user3'.
00080         """
00081         #some usefull properties/tool
00082         self.catalog = getToolByName(self.portal, 'portal_catalog')
00083         self.workflow = getToolByName(self.portal, 'portal_workflow')
00084         self.membershipTool = getToolByName(self.portal, 'portal_membership')
00085         self.memberdataTool = getToolByName(self.portal, 'portal_memberdata')
00086 
00087         self.portal_placeful_workflow = getToolByName(self.portal, 'portal_placeful_workflow')
00088 
00089         self.setupSecurityContext()
00090 
00091         self.login('user1')
00092         #self.createPolicy()
00093 
00094     def createArticle(self, ):
00095         """
00096         Create new policy
00097         """
00098         # Content creation
00099         self.contentId = 'myPolicy'
00100 
00101         # XXX
00102 
00103     def test_marker_applied_and_unapplied(self):
00104         """
00105         Check that the IPlacefulMarker is applied to the workflow tool by
00106         the install, and removed by the uninstall.
00107         """
00108         self.failUnless(IPlacefulMarker.providedBy(self.workflow))
00109         self.loginAsPortalOwner()
00110         self.qi.uninstallProducts(['CMFPlacefulWorkflow'])
00111         self.failIf(IPlacefulMarker.providedBy(self.workflow))
00112         self.qi.installProduct('CMFPlacefulWorkflow')
00113         self.failUnless(IPlacefulMarker.providedBy(self.workflow))
00114 
00115     def test_reinstall(self):
00116         """
00117         Test if upgrade is going the good way
00118         """
00119         self.qi = self.portal.portal_quickinstaller
00120         self.qi.installProduct('CMFPlacefulWorkflow', reinstall=True)
00121 
00122     def test_prefs_workflow_policy_mapping_set_PostOnly(self):
00123         """
00124         Check POST on mapping policy
00125         """
00126         self.loginAsPortalOwner()
00127         # add a policy to edit
00128         pwt = self.portal_placeful_workflow
00129         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00130                                      'default_workflow_policy (Simple Policy)')
00131         # use a GET request which should fail
00132         self.app.REQUEST.set('REQUEST_METHOD', 'GET')
00133         self.assertRaises(Forbidden,
00134                           self.portal.prefs_workflow_policy_mapping_set,
00135                           True, 'foo_bar_policy', 'title', 'description',
00136                           {'Document': 'plone_workflow'}, 'plone_workflow')
00137 
00138 
00139     def test_01_addWorkflowPolicyConfig(self,):
00140         """
00141         Add workflow policy config
00142         """
00143         # No policy config should exist before
00144         self.failIf(WorkflowPolicyConfig_id in self.portal.objectIds() )
00145         # Add a policy config
00146         self.portal.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00147         # Make sure the policy config is there
00148         self.failUnless( WorkflowPolicyConfig_id in self.portal.objectIds() )
00149 
00150     def test_02_checkWorkflowPolicyConfig(self,):
00151         """
00152         Add workflow policy config
00153         """
00154         self.portal.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00155         pc = getattr(self.portal, WorkflowPolicyConfig_id)
00156         self.failUnless(pc.getPolicyBelow()==None)
00157         self.failUnless(pc.getPolicyIn()==None)
00158 
00159     def test_03_addWorkflowPolicy(self,):
00160         """
00161         Add workflow policy
00162         """
00163         pwt = self.portal_placeful_workflow
00164         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00165                                      'default_workflow_policy (Simple Policy)')
00166         gsp = getattr(pwt, 'foo_bar_policy', None)
00167         self.failUnless(gsp!=None)
00168 
00169     def test_04_addWorkflowPolicyAndConfigForIt(self,):
00170         """
00171         Add workflow policy
00172         """
00173         self.loginAsPortalOwner()
00174         pwt = self.portal_placeful_workflow
00175         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00176                                      'default_workflow_policy (Simple Policy)')
00177         self.portal.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00178         pc = getattr(self.portal, WorkflowPolicyConfig_id)
00179         pc.setPolicyIn('foo_bar_policy')
00180         pc.setPolicyBelow('foo_bar_policy')
00181         self.failUnless(pc.getPolicyInId()=='foo_bar_policy')
00182         self.failUnless(pc.getPolicyBelowId()=='foo_bar_policy')
00183 
00184         self.logout()
00185 
00186     def test_04_addWorkflowPolicyAndDuplicateConfiguration(self,):
00187         """Add a workflow policy and duplicate another one
00188 
00189         Use a python script that can duplicate another policy or portal_workflow configuration
00190         """
00191         self.loginAsPortalOwner()
00192         pw_tool = self.portal_placeful_workflow
00193         wf_tool = self.portal.portal_workflow
00194         ptypes = self.portal.portal_types.objectIds()
00195 
00196         ## Part One: duplicate portal_workflow
00197         pw_tool.manage_addWorkflowPolicy(id='foo_bar_policy',
00198                                          duplicate_id='portal_workflow',
00199                                          )
00200 
00201         policy = pw_tool.getWorkflowPolicyById('foo_bar_policy')
00202 
00203         self.assertEqual(policy.getDefaultChain('XXX'), wf_tool._default_chain)
00204         for ptype in ptypes:
00205             chain = policy.getChainFor(ptype)
00206             if chain is None:
00207                 # Default empty chain is None in a policy and () in portal_workflow
00208                 chain = ()
00209             self.assertEqual(chain , wf_tool.getChainFor(ptype))
00210 
00211 
00212         ## Part Two: duplicate another policy
00213         policy.setDefaultChain(['plone_workflow', 'folder_workflow'])
00214         policy.setChainForPortalTypes(['Document','Folder', 'Large Plone Folder'], ['plone_workflow', 'folder_workflow'])
00215         pw_tool.manage_addWorkflowPolicy(id='foo_bar_policy2',
00216                                          duplicate_id='foo_bar_policy',
00217                                          )
00218 
00219         policy2 = pw_tool.getWorkflowPolicyById('foo_bar_policy2')
00220 
00221         self.assertEqual(policy.getDefaultChain('XXX'), ('plone_workflow', 'folder_workflow'))
00222         for ptype in ptypes:
00223             if ptype not in ('Document','Folder', 'Large Plone Folder'):
00224                 self.assertEqual(policy2.getChainFor(ptype), policy.getChainFor(ptype))
00225             else:
00226                 self.assertEqual(policy2.getChainFor(ptype), ('plone_workflow', 'folder_workflow'))
00227 
00228         self.logout()
00229 
00230     def test_05_editWorkflowPolicy(self,):
00231         """Edit workflow policy
00232         """
00233         pwt = self.portal_placeful_workflow
00234         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00235                                      'default_workflow_policy (Simple Policy)')
00236         gsp = pwt.getWorkflowPolicyById('foo_bar_policy')
00237         gsp.setChainForPortalTypes(['Document','Folder'], ['plone_workflow','folder_workflow'])
00238         self.assertEqual(gsp.getChainFor('Document'), ('plone_workflow','folder_workflow',))
00239         self.assertEqual(gsp.getChainFor('Folder'), ('plone_workflow','folder_workflow',))
00240 
00241     def test_06_getWorkflowPolicyIds(self,):
00242         pwt = self.portal_placeful_workflow
00243         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00244                                      'default_workflow_policy (Simple Policy)')
00245         pwt.manage_addWorkflowPolicy('foo_bar_policy_2',
00246                                      'default_workflow_policy (Simple Policy)')
00247         wp_ids=pwt.getWorkflowPolicyIds()
00248         self.failUnless('foo_bar_policy' in wp_ids)
00249         self.failUnless('foo_bar_policy_2' in wp_ids)
00250         # There are 4 base policies
00251         self.failUnless(len(wp_ids)==6)
00252 
00253     def test_07_getChainFor(self,):
00254         # Let's see what the chain is before
00255         self.logout()
00256         self.loginAsPortalOwner()
00257 
00258         pw = self.portal.portal_workflow
00259         self.failUnless(pw.getChainFor('Document')==('plone_workflow',) )
00260 
00261         self.portal.invokeFactory('Document', id='doc_before', text='foo bar baz')
00262 
00263         # The chain should be different now
00264         # Workflow tool should look for policy definition and return
00265         # the chain of the correct policy
00266         self.failUnless(pw.getChainFor(self.portal.doc_before)==('plone_workflow',) )
00267 
00268         # Let's define another policy
00269         pwt = self.portal_placeful_workflow
00270         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00271                                      'default_workflow_policy (Simple Policy)')
00272 
00273         # And redefine the chain for Document
00274         gsp = pwt.getWorkflowPolicyById('foo_bar_policy')
00275 
00276         gsp.setChainForPortalTypes(['Document'], ['folder_workflow'])
00277 
00278         # Try getting the new chain directly
00279         self.assertEqual(gsp.getChainFor('Document'), ('folder_workflow',) )
00280 
00281         # Add a config at the root that will use the new policy
00282         self.portal.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00283         self.failUnless('.wf_policy_config' in self.portal.objectIds())
00284 
00285         # Let's set the policy to the config
00286         pc = getattr(self.portal, WorkflowPolicyConfig_id)
00287         pc.setPolicyIn('foo_bar_policy')
00288         pc.setPolicyBelow('foo_bar_policy')
00289 
00290         self.assertEqual(pc.getPlacefulChainFor('Document', start_here=1), ('folder_workflow',))
00291 
00292         self.portal.invokeFactory('Document', id='doc', text='foo bar baz')
00293 
00294         # The chain should be different now
00295         # Workflow tool should look for policy definition and return
00296         # the chain of the correct policy
00297         self.assertEqual(pw.getChainFor(self.portal.doc), ('folder_workflow',) )
00298         # The chain for the first document should have changed now
00299         self.assertEqual(pw.getChainFor(self.portal.doc_before), ('folder_workflow',) )
00300 
00301     def test_08_getChainFor(self,):
00302         # Let's see what the chain is before
00303         pwt = self.portal_placeful_workflow
00304         self.failUnless(pwt.getMaxChainLength()==1)
00305         pwt.setMaxChainLength(2)
00306         self.failUnless(pwt.getMaxChainLength()==2)
00307 
00308     def test_09_wft_getChainFor(self,):
00309         self.logout()
00310         self.loginAsPortalOwner()
00311         self.portal.invokeFactory('Folder', id='folder')
00312         self.portal.folder.invokeFactory('Document', id='document', text='foo')
00313 
00314         # Check default
00315         wft = self.portal.portal_workflow
00316         chain = wft.getChainFor('Document')
00317         self.assertEqual(tuple(chain), ('plone_workflow',))
00318 
00319         # Check global chain
00320         wft.setChainForPortalTypes(('Document',), ('wf',))
00321         chain = wft.getChainFor('Document')
00322         self.assertEqual(tuple(chain), ('wf',))
00323 
00324         # Check global chain, using object
00325         chain = wft.getChainFor(self.portal.folder.document)
00326         self.assertEqual(tuple(chain), ('wf',))
00327 
00328         # Remove global chain
00329         wft.setChainForPortalTypes(('Document',), ())
00330         chain = wft.getChainFor(self.portal.folder.document)
00331         self.assertEqual(tuple(chain), ())
00332 
00333     def test_10_wft_getChainFor_placeful(self):
00334         self.logout()
00335         self.loginAsPortalOwner()
00336         wft = self.portal.portal_workflow
00337         self.portal.invokeFactory('Folder', id='folder')
00338         self.portal.folder.invokeFactory('Document', id='document')
00339         self.portal.folder.invokeFactory('Folder', id='folder2')
00340         self.portal.folder.folder2.invokeFactory('Document', id='document2')
00341 
00342         # Create a policy
00343         pwt = self.portal_placeful_workflow
00344         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00345                                      'default_workflow_policy (Simple Policy)')
00346 
00347         # And redefine the chain for Document
00348         gsp1 = pwt.getWorkflowPolicyById('foo_bar_policy')
00349         gsp1.setChainForPortalTypes(['Document'], ['folder_workflow'])
00350 
00351         # Add a config to the folder using the policy
00352         self.portal.folder.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00353 
00354         # Set the policy for the config
00355         pc = getattr(self.portal.folder, WorkflowPolicyConfig_id)
00356         pc.setPolicyIn('foo_bar_policy')
00357         pc.setPolicyBelow('foo_bar_policy')
00358 
00359         chain = wft.getChainFor(self.portal.folder.document)
00360         self.assertEqual(tuple(chain), ('folder_workflow',))
00361 
00362         # Create a different policy
00363         pwt = self.portal_placeful_workflow
00364         pwt.manage_addWorkflowPolicy('foo_bar_policy2',
00365                                      'default_workflow_policy (Simple Policy)')
00366 
00367         # And redefine the chain for Document
00368         gsp2 = pwt.getWorkflowPolicyById('foo_bar_policy2')
00369         gsp2.setChainForPortalTypes(['Document'], ['plone_workflow'])
00370 
00371         # Add a different config in the second folder
00372         self.portal.folder.folder2.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00373         pc = getattr(self.portal.folder.folder2, WorkflowPolicyConfig_id)
00374         pc.setPolicyIn('foo_bar_policy2')
00375         pc.setPolicyBelow('foo_bar_policy2')
00376 
00377         # Check inheritance order
00378         chain = wft.getChainFor(self.portal.folder.folder2.document2)
00379         self.assertEqual(tuple(chain), ('plone_workflow',))
00380 
00381         # Check empty chain
00382         gsp2.setChain('Document', ())
00383         chain = wft.getChainFor(self.portal.folder.folder2.document2)
00384         self.assertEqual(tuple(chain), ())
00385 
00386         # Check default
00387         wft.setDefaultChain('folder_workflow')
00388         gsp2.setChainForPortalTypes(('Document',), ('(Default)',))
00389         chain = wft.getChainFor(self.portal.folder.folder2.document2)
00390         self.assertEqual(tuple(chain), ('folder_workflow',))
00391 
00392     def test_11_In_and_Below(self):
00393         """In and below"""
00394         self.logout()
00395         self.loginAsPortalOwner()
00396         wft = self.portal.portal_workflow
00397         self.portal.portal_types['Large Plone Folder']._setPropValue('global_allow', True)
00398         self.portal.invokeFactory('Large Plone Folder', id='folder')
00399         self.portal.folder.invokeFactory('Document', id='document')
00400         self.portal.folder.invokeFactory('Large Plone Folder', id='folder2')
00401         self.portal.folder.folder2.invokeFactory('Document', id='document2')
00402         self.portal.folder.invokeFactory('Large Plone Folder', id='large_folder3')
00403         self.portal.folder.large_folder3.invokeFactory('Document', id='document3')
00404 
00405         # Create a policy
00406         pwt = self.portal_placeful_workflow
00407         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00408                                      'default_workflow_policy (Simple Policy)')
00409 
00410         # And redefine the chain for Document
00411         gsp1 = pwt.getWorkflowPolicyById('foo_bar_policy')
00412         gsp1.setChainForPortalTypes(['Document'], ['plone_workflow'])
00413         gsp1.setChainForPortalTypes(['Folder'], ['plone_workflow'])
00414         gsp1.setChainForPortalTypes(['Large Plone Folder'], ['plone_workflow'])
00415 
00416         # Create a policy
00417         pwt = self.portal_placeful_workflow
00418         pwt.manage_addWorkflowPolicy('foo_bar_policy2',
00419                                      'default_workflow_policy (Simple Policy)')
00420 
00421         # And redefine the chain for Document
00422         gsp2 = pwt.getWorkflowPolicyById('foo_bar_policy2')
00423         gsp2.setChainForPortalTypes(['Document'], ['folder_workflow'])
00424         gsp2.setChainForPortalTypes(['Folder'], ['folder_workflow'])
00425         gsp2.setChainForPortalTypes(['Large Plone Folder'], ['folder_workflow'])
00426 
00427         # Add a config to the folder using the policy
00428         self.portal.folder.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00429 
00430         # Set the policy for the config
00431         pc = getattr(self.portal.folder, WorkflowPolicyConfig_id)
00432 
00433         # In folder 1, we want to have plone_workflow
00434         # We set PolicyIn to the first policy in folder 1
00435         pc.setPolicyIn('foo_bar_policy')
00436 
00437         # In folder 2, we want to have folder_workflow
00438         # We set PolicyBelow to the second policy in folder 2
00439         pc.setPolicyBelow('foo_bar_policy2')
00440 
00441         # A document in folder 2 should have folder_workflow
00442         chain = wft.getChainFor(self.portal.folder.folder2.document2)
00443         self.assertEqual(tuple(chain), ('folder_workflow',))
00444 
00445         # Folder 2 should have folder_workflow
00446         chain = wft.getChainFor(self.portal.folder.document)
00447         self.assertEqual(tuple(chain), ('folder_workflow',))
00448 
00449         # A document in folder 1 should have folder_workflow
00450         chain = wft.getChainFor(self.portal.folder.document)
00451         self.assertEqual(tuple(chain), ('folder_workflow',))
00452 
00453         # Folder 1 should have plone_workflow
00454         chain = wft.getChainFor(self.portal.folder)
00455         self.assertEqual(tuple(chain), ('plone_workflow',))
00456 
00457     def test_11_copy_paste(self):
00458         """ Test security after a copy/paste
00459         """
00460         self.logout()
00461         self.loginAsPortalOwner()
00462         wft = self.portal.portal_workflow
00463         self.portal.invokeFactory('Document', id='document')
00464         self.portal.invokeFactory('Folder', id='folder')
00465 
00466         # Create a policy
00467         pwt = self.portal_placeful_workflow
00468         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00469                                      'default_workflow_policy (Simple Policy)')
00470 
00471         # And redefine the chain for Document
00472         gsp1 = pwt.getWorkflowPolicyById('foo_bar_policy')
00473         gsp1.setChainForPortalTypes(['Document'], ['folder_workflow'])
00474 
00475         # Add a config to the folder using the policy
00476         self.portal.folder.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00477 
00478         # Set the policy for the config
00479         pc = getattr(self.portal.folder, WorkflowPolicyConfig_id)
00480 
00481         # In folder, we want to have folder_workflow
00482         # We set PolicyIn to the first policy in folder
00483         pc.setPolicyIn('foo_bar_policy')
00484 
00485         cb = self.portal.manage_copyObjects(['document'])
00486         self.portal.folder.manage_pasteObjects(cb_copy_data=cb)
00487 
00488         # A document in plone root should have plone_workflow
00489         chain = wft.getChainFor(self.portal.document)
00490         self.assertEqual(tuple(chain), ('plone_workflow',))
00491 
00492         # Folder should have folder_workflow
00493         chain = wft.getChainFor(self.portal.folder)
00494         self.assertEqual(tuple(chain), ('folder_workflow',))
00495 
00496         # A document in folder should have folder_workflow
00497         chain = wft.getChainFor(self.portal.folder.document)
00498         self.assertEqual(tuple(chain), ('folder_workflow',))
00499 
00500     def test_11_getWorkflowPolicyById_edge_cases(self):
00501         pwt = self.portal_placeful_workflow
00502         self.assertEqual(pwt.getWorkflowPolicyById('dummy'), None)
00503 
00504     def test_12_getWorkflowPolicyById_edge_cases(self):
00505         pwt = self.portal_placeful_workflow
00506         self.assertEqual(pwt.getWorkflowPolicyById(None), None)
00507 
00508 
00509     def test_13_getWorkflowPolicyConfig(self):
00510         pwt = self.portal_placeful_workflow
00511         config = pwt.getWorkflowPolicyConfig(self.portal)
00512         self.assertEqual(config, None)
00513 
00514     def test_14_getWorkflowPolicyConfig(self):
00515         self.logout()
00516         self.loginAsPortalOwner()
00517         wft = self.portal.portal_workflow
00518         self.portal.invokeFactory('Folder', id='folder')
00519         self.portal.folder.invokeFactory('Document', id='document')
00520         self.portal.folder.invokeFactory('Folder', id='folder2')
00521         self.portal.folder.folder2.invokeFactory('Document', id='document2')
00522 
00523         # Create a policy
00524         pwt = self.portal_placeful_workflow
00525         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00526                                      'default_workflow_policy (Simple Policy)')
00527         # And redefine the chain for Document
00528         gsp1 = pwt.getWorkflowPolicyById('foo_bar_policy')
00529         gsp1.setChainForPortalTypes(['Document'], ['folder_workflow'])
00530 
00531         # Add a config to the folder using the policy
00532         self.portal.folder.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00533 
00534         # Set the policy for the config
00535         pc = getattr(self.portal.folder, WorkflowPolicyConfig_id)
00536         pc.setPolicyIn('foo_bar_policy')
00537         pc.setPolicyBelow('foo_bar_policy')
00538 
00539         # You should only be able to get a config in the folder itself
00540         config = pwt.getWorkflowPolicyConfig(self.portal.folder)
00541         self.failUnless(config!=None)
00542 
00543         # Not in the folder above
00544         config = pwt.getWorkflowPolicyConfig(self.portal)
00545         self.assertEqual(config, None)
00546 
00547         # Not in a document in the folder
00548         config = pwt.getWorkflowPolicyConfig(self.portal.folder.document)
00549         self.assertEqual(config, None)
00550 
00551         # Not in a folder below
00552         config = pwt.getWorkflowPolicyConfig(self.portal.folder.folder2)
00553         self.assertEqual(config, None)
00554 
00555         # Not in a document in a folder below
00556         config = pwt.getWorkflowPolicyConfig(self.portal.folder.folder2.document2)
00557         self.assertEqual(config, None)
00558 
00559     def test_15_wft_getChainFor_placeful_with_strange_wrapper(self):
00560         self.logout()
00561         self.loginAsPortalOwner()
00562         wft = self.portal.portal_workflow
00563         self.portal.invokeFactory('Folder', id='folder')
00564         self.portal.folder.invokeFactory('Document', id='document')
00565         self.portal.invokeFactory('Folder', id='folder2')
00566         self.portal.folder2.invokeFactory('Document', id='document2')
00567 
00568         # Create a policy
00569         pwt = self.portal_placeful_workflow
00570         pwt.manage_addWorkflowPolicy('foo_bar_policy',
00571                                      'default_workflow_policy (Simple Policy)')
00572 
00573         # And redefine the chain for Document
00574         gsp1 = pwt.getWorkflowPolicyById('foo_bar_policy')
00575         gsp1.setChainForPortalTypes(['Document'], ['folder_workflow'])
00576 
00577         # Add a config to the folder using the policy
00578         self.portal.folder.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00579 
00580         # Set the policy for the config
00581         pc = getattr(self.portal.folder, WorkflowPolicyConfig_id)
00582         pc.setPolicyIn('foo_bar_policy')
00583         pc.setPolicyBelow('foo_bar_policy')
00584 
00585         chain = wft.getChainFor(self.portal.folder2.document2)
00586         self.assertEqual(tuple(chain), ('plone_workflow',))
00587 
00588         # What if we acquired the doc from the wrong place
00589         wrapped_doc = self.portal.folder2.document2.__of__(self.portal.folder)
00590         chain = wft.getChainFor(wrapped_doc)
00591         self.assertEqual(tuple(chain), ('plone_workflow',))
00592 
00593         # What if we acquired the container from the wrong place
00594         wrapped_doc = self.portal.folder2.__of__(self.portal.folder).document2
00595         chain = wft.getChainFor(wrapped_doc)
00596         self.assertEqual(tuple(chain), ('plone_workflow',))
00597 
00598     def test_16_getWorklists(self):
00599         """Verify if worklists are always accessible with a policy
00600         """
00601         wf_tool = self.portal.portal_workflow
00602         placeful_tool = self.portal_placeful_workflow
00603 
00604         self.loginAsPortalOwner()
00605 
00606         self.portal.invokeFactory('Folder', id='folder')
00607         self.portal.folder.invokeFactory('Document', id='document')
00608 
00609         # Create a policy
00610         placeful_tool.manage_addWorkflowPolicy('foo_bar_policy',
00611                                                'default_workflow_policy (Simple Policy)',
00612                                                'portal_workflow',)
00613         # And redefine the chain for Document in portal_workflow
00614         wf_tool.setChainForPortalTypes(['Document'], ())
00615 
00616         # Add a config to the folder using the policy
00617         self.portal.folder.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
00618 
00619         # Set the policy for the config
00620         config = getattr(self.portal.folder, WorkflowPolicyConfig_id)
00621         config.setPolicyBelow('foo_bar_policy')
00622 
00623         # we make the document pending
00624         document = self.portal.folder.document
00625         wf_tool.doActionFor(document, 'submit', comment="unittest transition")
00626 
00627         self.assertEqual(
00628             sorted(tuple(wf_tool.getWorklists().keys())),
00629             sorted(('folder_workflow', 'plone_workflow',
00630                     'intranet_folder_workflow', 'one_state_workflow',
00631                     'simple_publication_workflow',
00632                     'intranet_workflow')))
00633         self.assertEqual(tuple(self.portal.my_worklist()), (document,))
00634 
00635         self.logout()
00636 
00637 
00638 def test_suite():
00639     from unittest import TestSuite, makeSuite
00640     suite = TestSuite()
00641     suite.addTest(makeSuite(TestPlacefulWorkflow))
00642     return suite