Back to index

plone3  3.1.7
testDisplayContentsTab.py
Go to the documentation of this file.
00001 #
00002 # Tests for displayContentsTab script
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 
00007 from Products.CMFCore.permissions import ListFolderContents
00008 from Products.CMFCore.permissions import ModifyPortalContent
00009 from Products.CMFCore.permissions import AddPortalContent
00010 from Products.CMFCore.permissions import ReviewPortalContent
00011 from AccessControl.Permissions import copy_or_move
00012 from AccessControl.Permissions import delete_objects
00013 
00014 import transaction
00015 
00016 
00017 # XXX: This is done in the PloneView now, and perhaps these tests should be
00018 # moved there.  We will leave the script around for a while, so we still test
00019 # there for now.
00020 class TestDisplayContentsTab(PloneTestCase.PloneTestCase):
00021     '''For the contents tab to display a user must have the ListFolderContents,
00022        and one of the (Modify portal contents, Copy or move, Add portal contents,
00023        Delete objects) permissions either on the object itself, or on the
00024        parent object if the object is not folderish or is the default page for
00025        its parent.
00026     '''
00027 
00028     def afterSetUp(self):
00029         self.parent = self.folder.aq_parent
00030         self.folder.invokeFactory('Folder', id='foo')
00031         self.folder.foo.invokeFactory('Document', id='doc1')
00032         self.folder.foo.invokeFactory('Folder', id='folder1')
00033         folder_path = '/'.join(self.folder.foo.folder1.getPhysicalPath())
00034         transaction.savepoint(optimistic=True) # make rename work
00035         # Make the folder the default page
00036         self.setupAuthenticator()
00037         self.setRequestMethod('POST')
00038         self.folder.folder_rename(paths=[folder_path], new_ids=['index_html'], new_titles=['Default Folderish Document'])
00039         self.setRequestMethod('GET')
00040 
00041     def getModificationPermissions(self):
00042         return [ModifyPortalContent,
00043                 AddPortalContent,
00044                 copy_or_move,
00045                 delete_objects,
00046                 ReviewPortalContent]
00047 
00048     def removePermissionsFromObject(self, permissions, object):
00049         for permission in permissions:
00050             object.manage_permission(permission, ['Manager'], acquire=0)
00051 
00052     def testDisplayContentsTab(self):
00053         # We should see the tab
00054         self.failUnless(self.folder.displayContentsTab())
00055 
00056     def testAnonymous(self):
00057         # Anonymous should not see the tab
00058         self.logout()
00059         self.failIf(self.folder.displayContentsTab())
00060 
00061     def testNoListPermission(self):
00062         # We should not see the tab without ListFolderContents
00063         self.folder.manage_permission(ListFolderContents, ['Manager'], acquire=0)
00064         self.failIf(self.folder.displayContentsTab())
00065 
00066     def testNoModificationPermissions(self):
00067         # We should see the tab with only copy_or_move
00068         perms = self.getModificationPermissions()
00069         self.removePermissionsFromObject(perms, self.folder)
00070         self.failIf(self.folder.displayContentsTab())
00071 
00072     def testOnlyModifyPermission(self):
00073         # We should see the tab with only ModifyPortalContent
00074         perms = self.getModificationPermissions()
00075         perms.remove(ModifyPortalContent)
00076         self.removePermissionsFromObject(perms, self.folder)
00077         self.failUnless(self.folder.displayContentsTab())
00078 
00079     def testOnlyCopyPermission(self):
00080         # We should NOT see the tab with only copy_or_move (r8620)
00081         # Otherwise Members always get the green border.
00082         perms = self.getModificationPermissions()
00083         perms.remove(copy_or_move)
00084         self.removePermissionsFromObject(perms, self.folder)
00085         self.failIf(self.folder.displayContentsTab())
00086 
00087     def testOnlyDeletePermission(self):
00088         # We should see the tab with only copy_or_move
00089         perms = self.getModificationPermissions()
00090         perms.remove(delete_objects)
00091         self.removePermissionsFromObject(perms, self.folder)
00092         self.failUnless(self.folder.displayContentsTab())
00093 
00094     def testOnlyAddPermission(self):
00095         # We should see the tab with only copy_or_move
00096         perms = self.getModificationPermissions()
00097         perms.remove(AddPortalContent)
00098         self.removePermissionsFromObject(perms, self.folder)
00099         self.failUnless(self.folder.displayContentsTab())
00100 
00101     def testNonFolderishObjectDoesNotShowTab(self):
00102         # The availability of the contents tab on a non-folderish object should be
00103         # based on the parents permissions.
00104         doc = self.folder.foo.doc1
00105         self.failIf(doc.displayContentsTab())
00106 
00107     def testFolderishDefaultPageUsesParentPermissions(self):
00108         # The availability of the contents tab on a default page should be
00109         # based on the parents permissions, whether the default page is
00110         # folderish or not.
00111         def_page = self.folder.foo.index_html
00112         self.failUnless(def_page.displayContentsTab())
00113         self.folder.foo.manage_permission(ListFolderContents, ['Manager'], acquire=0)
00114         # Clear the memoized results, as it would happen for a new request
00115         del self.app.REQUEST.__annotations__
00116         self.failIf(def_page.displayContentsTab())
00117 
00118 
00119 def test_suite():
00120     from unittest import TestSuite, makeSuite
00121     suite = TestSuite()
00122     suite.addTest(makeSuite(TestDisplayContentsTab))
00123     return suite