Back to index

plone3  3.1.7
tests.py
Go to the documentation of this file.
00001 import unittest
00002 
00003 from Products.PloneTestCase import PloneTestCase as ptc
00004 ptc.setupPloneSite(extension_profiles=['Products.CMFPlone:testfixture'])
00005 
00006 from zope.interface import directlyProvides
00007 from zope.component import getUtility
00008 
00009 from zope.app.publisher.interfaces.browser import IBrowserMenu
00010 from zope.app.testing.placelesssetup import PlacelessSetup
00011 
00012 from Products.CMFCore.Expression import Expression
00013 from Products.CMFCore.utils import getToolByName
00014 
00015 from Products.CMFPlone.interfaces import ISelectableConstrainTypes
00016 from Products.CMFPlone.interfaces import INonStructuralFolder
00017 
00018 from plone.app.contentmenu.interfaces import IActionsMenu
00019 from plone.app.contentmenu.interfaces import IDisplayMenu
00020 from plone.app.contentmenu.interfaces import IFactoriesMenu
00021 from plone.app.contentmenu.interfaces import IWorkflowMenu
00022 
00023 from plone.locking.interfaces import ILockable
00024 
00025 from Products.CMFPlone.utils import _createObjectByType
00026 from Products.CMFPlone.tests import dummy
00027 
00028 
00029 class TestActionsMenu(ptc.PloneTestCase):
00030 
00031     def afterSetUp(self):
00032         self.menu = getUtility(IBrowserMenu, name='plone_contentmenu_actions', context=self.folder)
00033         self.request = self.app.REQUEST
00034 
00035     def testActionsMenuImplementsIBrowserMenu(self):
00036         self.failUnless(IBrowserMenu.providedBy(self.menu))
00037 
00038     def testActionsMenuImplementsIActionsMenu(self):
00039         self.failUnless(IActionsMenu.providedBy(self.menu))
00040 
00041     def testActionsMenuFindsActions(self):
00042         actions = self.menu.getMenuItems(self.folder, self.request)
00043         self.failUnless('copy' in [a['extra']['id'] for a in actions])
00044 
00045 
00046 class TestDisplayMenu(ptc.PloneTestCase):
00047 
00048     def afterSetUp(self):
00049         self.menu = getUtility(IBrowserMenu, name='plone_contentmenu_display', context=self.folder)
00050         self.request = self.app.REQUEST
00051 
00052     def testActionsMenuImplementsIBrowserMenu(self):
00053         self.failUnless(IBrowserMenu.providedBy(self.menu))
00054 
00055     def testActionsMenuImplementsIActionsMenu(self):
00056         self.failUnless(IDisplayMenu.providedBy(self.menu))
00057 
00058     # Template selection
00059 
00060     def testTemplatesIncluded(self):
00061         actions = self.menu.getMenuItems(self.folder, self.request)
00062         templates = [a['extra']['id'] for a in actions]
00063         self.failUnless('folder_listing' in templates)
00064 
00065     def testSingleTemplateIncluded(self):
00066         self.folder.invokeFactory('Document', 'doc1')
00067         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00068         self.assertEqual(len(actions), 1)
00069         self.assertEqual(actions[0]['extra']['id'], 'document_view')
00070 
00071     def testNonBrowserDefaultReturnsNothing(self):
00072         f = dummy.Folder()
00073         self.folder._setObject('f1', f)
00074         actions = self.menu.getMenuItems(self.folder.f1, self.request)
00075         self.assertEqual(len(actions), 0)
00076 
00077     def testDefaultPageIncludesParentOnlyWhenItemHasSingleView(self):
00078         self.folder.invokeFactory('Document', 'doc1')
00079         self.folder.setDefaultPage('doc1')
00080         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00081         self.failUnless('folderDefaultPageDisplay' in [a['extra']['id'] for a in actions])
00082         self.failIf('document_view' in [a['extra']['id'] for a in actions])
00083 
00084     def testDefaultPageIncludesParentAndItemViewsWhenItemHasMultipleViews(self):
00085         fti = self.portal.portal_types['Document']
00086         documentViews = fti.view_methods + ('base_view',)
00087         fti.manage_changeProperties(view_methods = documentViews)
00088         self.folder.invokeFactory('Document', 'doc1')
00089         self.folder.setDefaultPage('doc1')
00090         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00091         self.failUnless('folderDefaultPageDisplay' in [a['extra']['id'] for a in actions])
00092         self.failUnless('document_view' in [a['extra']['id'] for a in actions])
00093         self.failUnless('base_view' in [a['extra']['id'] for a in actions])
00094 
00095     def testCurrentTemplateSelected(self):
00096         layout = self.folder.getLayout()
00097         actions = self.menu.getMenuItems(self.folder, self.request)
00098         selected = [a['extra']['id'] for a in actions if a['selected']]
00099         self.assertEqual(selected, ['folder_listing'])
00100 
00101     # Default-page selection
00102 
00103     def testFolderCanSetDefaultPage(self):
00104         self.folder.invokeFactory('Folder', 'f1')
00105         self.failUnless(self.folder.f1.canSetDefaultPage())
00106         actions = self.menu.getMenuItems(self.folder.f1, self.request)
00107         self.failUnless('contextSetDefaultPage' in [a['extra']['id'] for a in actions])
00108 
00109     def testWithCanSetDefaultPageFalse(self):
00110         self.folder.invokeFactory('Folder', 'f1')
00111         self.folder.f1.manage_permission('Modify view template', ('Manager',))
00112         self.failIf(self.folder.f1.canSetDefaultPage())
00113         actions = self.menu.getMenuItems(self.folder.f1, self.request)
00114         self.failIf('contextSetDefaultPage' in [a['extra']['id'] for a in actions])
00115 
00116     def testSelectItemNotIncludedInNonStructuralFolder(self):
00117         self.folder.invokeFactory('Folder', 'f1')
00118         directlyProvides(self.folder.f1, INonStructuralFolder)
00119         actions = self.menu.getMenuItems(self.folder.f1, self.request)
00120         self.failIf('contextSetDefaultPage' in [a['extra']['id'] for a in actions])
00121 
00122     def testDefaultPageSelectedAndOverridesLayout(self):
00123         self.folder.invokeFactory('Document', 'doc1')
00124         self.folder.setDefaultPage('doc1')
00125         actions = self.menu.getMenuItems(self.folder, self.request)
00126         selected = [a['extra']['id'] for a in actions if a['selected']]
00127         self.assertEqual(selected, ['contextDefaultPageDisplay'])
00128 
00129     def testDefaultPageCanBeChangedInContext(self):
00130         self.folder.invokeFactory('Document', 'doc1')
00131         self.folder.setDefaultPage('doc1')
00132         actions = self.menu.getMenuItems(self.folder, self.request)
00133         self.failUnless('contextChangeDefaultPage' in [a['extra']['id'] for a in actions])
00134 
00135     def testDefaultPageCanBeChangedInFolder(self):
00136         self.folder.invokeFactory('Document', 'doc1')
00137         self.folder.setDefaultPage('doc1')
00138         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00139         self.failUnless('folderChangeDefaultPage' in [a['extra']['id'] for a in actions])
00140         self.failIf('contextChangeDefaultPage' in [a['extra']['id'] for a in actions])
00141 
00142     # Headers/separators
00143 
00144     def testSeparatorsIncludedWhenViewingDefaultPageWithViews(self):
00145         fti = self.portal.portal_types['Document']
00146         documentViews = fti.view_methods + ('base_view',)
00147         fti.manage_changeProperties(view_methods = documentViews)
00148         self.folder.invokeFactory('Document', 'doc1')
00149         self.folder.setDefaultPage('doc1')
00150         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00151         ids = [a['extra']['id'] for a in actions]
00152         self.failUnless('folderHeader' in ids)
00153         self.failUnless('contextHeader' in ids)
00154 
00155     def testSeparatorsNotIncludedWhenViewingDefaultPageWithoutViews(self):
00156         self.folder.invokeFactory('Document', 'doc1')
00157         self.folder.setDefaultPage('doc1')
00158         self.assertEqual(len(self.folder.doc1.getAvailableLayouts()), 1)
00159         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00160         ids = [a['extra']['id'] for a in actions]
00161         self.failIf('folderHeader' in ids)
00162         self.failIf('contextHeader' in ids)
00163 
00164     def testSeparatorsNotDisplayedWhenViewingFolder(self):
00165         fti = self.portal.portal_types['Document']
00166         documentViews = fti.view_methods + ('base_view',)
00167         fti.manage_changeProperties(view_methods = documentViews)
00168         self.folder.invokeFactory('Document', 'doc1')
00169         self.folder.setDefaultPage('doc1')
00170         actions = self.menu.getMenuItems(self.folder, self.request)
00171         ids = [a['extra']['id'] for a in actions]
00172         self.failIf('folderHeader' in ids)
00173         self.failIf('contextHeader' in ids)
00174 
00175     # Regressions
00176 
00177     def testDefaultPageTemplateTitle(self):
00178         self.folder.setDefaultPage('sitemap') # Use a template in portal_skins
00179         actions = self.menu.getMenuItems(self.folder, self.request)
00180         changeAction = [x for x in actions if x['extra']['id'] == 'contextDefaultPageDisplay'][0]
00181         changeAction['title'].default
00182         self.assertEquals(u"Sitemap", changeAction['title'].mapping['contentitem'])
00183 
00184 
00185 class TestFactoriesMenu(ptc.PloneTestCase):
00186 
00187     def afterSetUp(self):
00188         self.folder.invokeFactory('Document', 'doc1')
00189         self.menu = getUtility(IBrowserMenu, name='plone_contentmenu_factory', context=self.folder)
00190         self.request = self.app.REQUEST
00191 
00192     def testMenuImplementsIBrowserMenu(self):
00193         self.failUnless(IBrowserMenu.providedBy(self.menu))
00194 
00195     def testMenuImplementsIFactoriesMenu(self):
00196         self.failUnless(IFactoriesMenu.providedBy(self.menu))
00197 
00198     def testMenuIncludesFactories(self):
00199         actions = self.menu.getMenuItems(self.folder, self.request)
00200         self.failUnless('image' in [a['extra']['id'] for a in actions])
00201 
00202     def testTypeNameIsURLQuoted(self):
00203         actions = self.menu.getMenuItems(self.folder, self.request)
00204         self.failUnless(self.folder.absolute_url() + '/createObject?type_name=News+Item' in [a['action'] for a in actions])
00205 
00206     def testMenuIncludesFactoriesOnNonFolderishContext(self):
00207         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00208         img = None
00209         for a in actions:
00210             if a['extra']['id'] == 'image':
00211                 img = a
00212                 break
00213         self.failIf(img is None)
00214         action = img['action']
00215         url = self.folder.absolute_url()
00216         self.failUnless(action.startswith(url))
00217         url = self.folder.doc1.absolute_url()
00218         self.failIf(action.startswith(url))
00219 
00220     def testNoAddableTypes(self):
00221         actions = self.menu.getMenuItems(self.portal, self.request)
00222         self.assertEqual(len(actions), 0)
00223         
00224         # set no types for folders and check the menu is not shown
00225         folder_fti = self.portal.portal_types['Folder']
00226         folder_fti.manage_changeProperties(filter_content_types=True, allowed_content_types=[])
00227         actions = self.menu.getMenuItems(self.folder, self.request)
00228         self.assertEqual(len(actions), 0)
00229 
00230     def testConstrainTypes(self):
00231         constraints = ISelectableConstrainTypes(self.folder)
00232         constraints.setConstrainTypesMode(1)
00233         constraints.setLocallyAllowedTypes(('Document',))
00234         constraints.setImmediatelyAddableTypes(('Document',))
00235         actions = self.menu.getMenuItems(self.folder, self.request)
00236         self.assertEqual(len(actions), 2)
00237         self.assertEqual(actions[0]['extra']['id'], 'document')
00238         self.assertEqual(actions[1]['extra']['id'], 'settings')
00239 
00240     def testSettingsIncluded(self):
00241         actions = self.menu.getMenuItems(self.folder, self.request)
00242         self.assertEqual(actions[-1]['extra']['id'], 'settings')
00243 
00244     def testSettingsNotIncludedWhereNotSupported(self):
00245         self.folder.manage_permission('Modify constrain types', ('Manager',))
00246         actions = self.menu.getMenuItems(self.folder, self.request)
00247         self.failIf('_settings' in [a['extra']['id'] for a in actions])
00248 
00249     def testMoreIncluded(self):
00250         constraints = ISelectableConstrainTypes(self.folder)
00251         constraints.setConstrainTypesMode(1)
00252         constraints.setLocallyAllowedTypes(('Document', 'Image',))
00253         constraints.setImmediatelyAddableTypes(('Document',))
00254         actions = self.menu.getMenuItems(self.folder, self.request)
00255         self.failIf('image' in [a['extra']['id'] for a in actions])
00256         self.failUnless('document' in [a['extra']['id'] for a in actions])
00257         self.failUnless('more' in [a['extra']['id'] for a in actions])
00258         self.failUnless('settings' in [a['extra']['id'] for a in actions])
00259 
00260     def testMoreNotIncludedWhenNotNecessary(self):
00261         constraints = ISelectableConstrainTypes(self.folder)
00262         constraints.setConstrainTypesMode(1)
00263         constraints.setLocallyAllowedTypes(('Document',))
00264         constraints.setImmediatelyAddableTypes(('Document',))
00265         actions = self.menu.getMenuItems(self.folder, self.request)
00266         self.assertEqual(len(actions), 2)
00267         self.assertEqual(actions[0]['extra']['id'], 'document')
00268         self.assertEqual(actions[1]['extra']['id'], 'settings')
00269 
00270     def testNonStructualFolderShowsParent(self):
00271         # Cope with an unfortunate side-effect of running all plone.* tests at
00272         # once. Some tests setup the Archetypes examples types and don't use
00273         # their own layer for it :(
00274         for t in ('ATBIFolder', 'ComplexType', 'DDocument'):
00275             if t in self.portal.portal_types.keys():
00276                 self.portal.portal_types[t].global_allow = False
00277 
00278         self.folder.invokeFactory('Folder', 'folder1')
00279         directlyProvides(self.folder.folder1, INonStructuralFolder)
00280         constraints = ISelectableConstrainTypes(self.folder.folder1)
00281         constraints.setConstrainTypesMode(1)
00282         constraints.setLocallyAllowedTypes(('Document',))
00283         constraints.setImmediatelyAddableTypes(('Document',))
00284         actions = self.menu.getMenuItems(self.folder.folder1, self.request)
00285         self.failUnless('event' in actions[0]['extra']['id'])
00286 
00287 
00288 class TestWorkflowMenu(ptc.PloneTestCase):
00289 
00290     def afterSetUp(self):
00291         self.folder.invokeFactory('Document', 'doc1')
00292         self.menu = getUtility(IBrowserMenu, name='plone_contentmenu_workflow', context=self.folder)
00293         self.request = self.app.REQUEST
00294 
00295     def testMenuImplementsIBrowserMenu(self):
00296         self.failUnless(IBrowserMenu.providedBy(self.menu))
00297 
00298     def testMenuImplementsIActionsMenu(self):
00299         self.failUnless(IWorkflowMenu.providedBy(self.menu))
00300 
00301     def testMenuIncludesActions(self):
00302         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00303         self.failUnless('workflow-transition-submit' in
00304                         [a['extra']['id'] for a in actions])
00305         self.failUnless('http://nohost/plone/Members/test_user_1_/doc1/content_status_modify?workflow_action=submit' in
00306                         [a['action'] for a in actions])
00307 
00308         # Let us try that again but with an empty url action, like is
00309         # usual in older workflows, and which is nice to keep
00310         # supporting.
00311         context = self.folder.doc1
00312         wf_tool = getToolByName(context, "portal_workflow")
00313         submit = wf_tool.plone_workflow.transitions['submit']
00314         submit.actbox_url = ""
00315         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00316         self.failUnless('workflow-transition-submit' in
00317                         [a['extra']['id'] for a in actions])
00318         self.failUnless('http://nohost/plone/Members/test_user_1_/doc1/content_status_modify?workflow_action=submit' in
00319                         [a['action'] for a in actions])
00320 
00321     def testNoTransitions(self):
00322         self.logout()
00323         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00324         self.assertEqual(len(actions), 0)
00325 
00326     def testLockedItem(self):
00327         membership_tool = getToolByName(self.folder, 'portal_membership')
00328         membership_tool.addMember('anotherMember', 'secret', ['Member'], [])
00329         locking = ILockable(self.folder.doc1)
00330         locking.lock()
00331         self.login('anotherMember')
00332         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00333         self.assertEqual(len(actions), 0)
00334 
00335     def testAdvancedIncluded(self):
00336         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00337         url = self.folder.doc1.absolute_url() + '/content_status_history'
00338         self.failUnless(url in [a['action'] for a in actions])
00339 
00340     def testPolicyIncludedIfCMFPWIsInstalled(self):
00341         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00342         url = self.folder.doc1.absolute_url() + '/placeful_workflow_configuration'
00343         self.failIf(url in [a['action'] for a in actions])
00344         self.portal.portal_quickinstaller.installProduct('CMFPlacefulWorkflow')
00345         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00346         self.failUnless(url in [a['action'] for a in actions])
00347 
00348 
00349 class TestContentMenu(ptc.PloneTestCase):
00350 
00351     def afterSetUp(self):
00352         self.menu = getUtility(IBrowserMenu, name='plone_contentmenu', context=self.folder)
00353         self.request = self.app.REQUEST
00354 
00355     # Actions sub-menu
00356 
00357     def testActionsSubMenuIncluded(self):
00358         items = self.menu.getMenuItems(self.folder, self.request)
00359         actionsMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-actions'][0]
00360         self.assertEqual(actionsMenuItem['action'], self.folder.absolute_url() + '/folder_contents')
00361         self.failUnless(len(actionsMenuItem['submenu']) > 0)
00362 
00363     # Display sub-menu
00364 
00365     def testDisplayMenuIncluded(self):
00366         items = self.menu.getMenuItems(self.folder, self.request)
00367         displayMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-display'][0]
00368         self.assertEqual(displayMenuItem['action'], self.folder.absolute_url() + '/select_default_view')
00369         self.failUnless(len(displayMenuItem['submenu']) > 0)
00370 
00371     def testDisplayMenuNotIncludedIfContextDoesNotSupportBrowserDefault(self):
00372         # We need to create an object that does not have IBrowserDefault enabled
00373         _createObjectByType('ATListCriterion', self.folder, 'c1')
00374         items = self.menu.getMenuItems(self.folder.c1, self.request)
00375         self.assertEqual([i for i in items if i['extra']['id'] == 'plone-contentmenu-display'], [])
00376 
00377     def testDisplayMenuShowFolderDefaultPageWhenContextDoesNotSupportSelectableBrowserDefault(self):
00378         # We need to create an object that is not ISelectableBrowserDefault aware
00379         _createObjectByType('ATListCriterion', self.folder, 'c1')
00380         self.folder.c1.setTitle('Foo')
00381         self.folder.setDefaultPage('c1')
00382         items = self.menu.getMenuItems(self.folder.c1, self.request)
00383         displayMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-display'][0]
00384         selected =  [a for a in displayMenuItem['submenu'] if a['selected']][0]
00385         self.assertEqual(u'Foo', selected['title'].mapping['contentitem'])
00386 
00387     def testDisplayMenuNotIncludedIfNoActionsAvailable(self):
00388         self.folder.invokeFactory('Document', 'doc1')
00389         items = self.menu.getMenuItems(self.folder.doc1, self.request)
00390         self.assertEqual([i for i in items if i['extra']['id'] == 'plone-contentmenu-display'], [])
00391 
00392     def testDisplayMenuDisabledIfIndexHtmlInFolder(self):
00393         self.folder.invokeFactory('Document', 'index_html')
00394         items = self.menu.getMenuItems(self.folder, self.request)
00395         displayMenuItems = [i for i in items if i['extra']['id'] == 'plone-contentmenu-display']
00396         self.assertEqual(len(displayMenuItems), 0)
00397 
00398     def testDisplayMenuDisabledIfIndexHtmlInFolderAndContextIsIndexHtml(self):
00399         self.folder.invokeFactory('Document', 'index_html')
00400         items = self.menu.getMenuItems(self.folder.index_html, self.request)
00401         displayMenuItems = [i for i in items if i['extra']['id'] == 'plone-contentmenu-display']
00402         self.assertEqual(len(displayMenuItems), 0)
00403 
00404     # Add sub-menu
00405 
00406     def testAddMenuIncluded(self):
00407         items = self.menu.getMenuItems(self.folder, self.request)
00408         factoriesMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-factories'][0]
00409         self.assertEqual(factoriesMenuItem['action'], self.folder.absolute_url() + '/folder_factories')
00410         self.failUnless(len(factoriesMenuItem['submenu']) > 0)
00411         self.assertEqual(factoriesMenuItem['extra']['hideChildren'], False)
00412 
00413     def testAddMenuNotIncludedIfNothingToAdd(self):
00414         self.logout()
00415         items = self.menu.getMenuItems(self.folder, self.request)
00416         self.assertEqual([i for i in items if i['extra']['id'] == 'plone-contentmenu-factories'], [])
00417 
00418     def testAddMenuWithNothingToAddButWithAvailableConstrainSettings(self):
00419         self.folder.setConstrainTypesMode(1)
00420         self.folder.setLocallyAllowedTypes(())
00421         self.folder.setImmediatelyAddableTypes(())
00422         items = self.menu.getMenuItems(self.folder, self.request)
00423         factoriesMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-factories'][0]
00424         self.assertEqual(len(factoriesMenuItem['submenu']), 1)
00425         self.assertEqual(factoriesMenuItem['submenu'][0]['extra']['id'], 'settings')
00426 
00427     def testAddMenuWithNothingToAddButWithAvailableMorePage(self):
00428         self.folder.setConstrainTypesMode(1)
00429         self.folder.setLocallyAllowedTypes(('Document',))
00430         self.folder.setImmediatelyAddableTypes(())
00431         self.folder.manage_permission('Modify constrain types', ('Manager',))
00432         items = self.menu.getMenuItems(self.folder, self.request)
00433         factoriesMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-factories'][0]
00434         self.assertEqual(len(factoriesMenuItem['submenu']), 1)
00435         self.assertEqual(factoriesMenuItem['submenu'][0]['extra']['id'], 'more')
00436 
00437     def testAddMenuRelativeToNonStructuralFolder(self):
00438         self.folder.invokeFactory('Folder', 'f1')
00439         directlyProvides(self.folder.f1, INonStructuralFolder)
00440         items = self.menu.getMenuItems(self.folder.f1, self.request)
00441         factoriesMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-factories']
00442         self.failIf(factoriesMenuItem)
00443 
00444     def testAddMenuWithSingleItemCollapses(self):
00445         # we need a dummy to test this - should test that if the item does not
00446         # support constrain types and there is
00447         self.folder.setConstrainTypesMode(1)
00448         self.folder.setLocallyAllowedTypes(('Document',))
00449         self.folder.setImmediatelyAddableTypes(('Document',))
00450         self.folder.manage_permission('Modify constrain types', ('Manager',))
00451         items = self.menu.getMenuItems(self.folder, self.request)
00452         factoriesMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-factories'][0]
00453         self.assertEqual(factoriesMenuItem['action'], self.folder.absolute_url() + '/createObject?type_name=Document')
00454         self.assertEqual(factoriesMenuItem['extra']['hideChildren'], True)
00455 
00456     # Workflow sub-menu
00457 
00458     def testWorkflowMenuIncluded(self):
00459         items = self.menu.getMenuItems(self.folder, self.request)
00460         workflowMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-workflow'][0]
00461         self.assertEqual(workflowMenuItem['action'], self.folder.absolute_url() + '/content_status_history')
00462         self.failUnless(len(workflowMenuItem['submenu']) > 0)
00463 
00464     def testWorkflowMenuWithNoTransitionsDisabled(self):
00465         self.logout()
00466         items = self.menu.getMenuItems(self.folder, self.request)
00467         workflowMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-workflow'][0]
00468         self.assertEqual(workflowMenuItem['action'], '')
00469 
00470     # XXX: Unable to write a proper test so far
00471     def DISABLED_testWorkflowMenuWithNoTransitionsEnabledAsManager(self):
00472         # set workflow guard condition that fails, so there are no transitions.
00473         # then show that manager will get a drop-down with settings whilst
00474         # regular users won't
00475 
00476         self.portal.portal_workflow.doActionFor(self.folder, 'hide')
00477         wf = self.portal.portal_workflow['folder_workflow']
00478         wf.transitions['show'].guard.expr = Expression('python: False')
00479         wf.transitions['publish'].guard.expr = Expression('python: False')
00480 
00481         items = self.menu.getMenuItems(self.folder, self.request)
00482         workflowMenuItem = [i for i in items if i['extra']['id'] == 'plone-contentmenu-workflow'][0]
00483 
00484         # A regular user doesn't see any actions
00485         self.failUnless(workflowMenuItem['action'] == '')
00486         self.failUnless(workflowMenuItem['submenu'] is None)
00487 
00488         self.fail('Unable to write a proper test so far')
00489 
00490     def testWorkflowMenuWithNoWorkflowNotIncluded(self):
00491         self.portal.portal_workflow.setChainForPortalTypes(('Document',), ())
00492         self.folder.invokeFactory('Document', 'doc1')
00493         actions = self.menu.getMenuItems(self.folder.doc1, self.request)
00494         self.failIf('plone_contentmenu_workflow' in [a['extra']['id'] for a in actions])
00495 
00496 
00497 class TestDisplayViewsMenu(PlacelessSetup, unittest.TestCase):
00498 
00499     def setUp(self):
00500         from Products.Five import zcml
00501         import Products.Five
00502         import plone.app.contentmenu
00503         zcml.load_config("meta.zcml", Products.Five)
00504         zcml.load_config('configure.zcml', plone.app.contentmenu)
00505         zcml.load_config('tests.zcml', plone.app.contentmenu)
00506         self.menu = getUtility(IBrowserMenu, 'plone_displayviews')
00507 
00508     def _getMenuItemByAction(self, action):
00509         from zope.publisher.browser import TestRequest
00510         context = dummy.Dummy()
00511         request = TestRequest()
00512         return self.menu.getMenuItemByAction(context, request, action)
00513 
00514     def testInterface(self):
00515         """A DisplayViewsMenu implements an extended interface"""
00516         from interfaces import IDisplayViewsMenu
00517         self.assertTrue(IDisplayViewsMenu.providedBy(self.menu))
00518 
00519     def testSimpleAction(self):
00520         """Retrieve a registered IBrowserMenuItem"""
00521         item = self._getMenuItemByAction('foo.html')
00522         self.assertFalse(item is None)
00523         self.assertEqual(item.title, 'Test Menu Item')
00524 
00525     def testViewAction(self):
00526         """Retrieve a registered IBrowserMenuItem"""
00527         item = self._getMenuItemByAction('bar.html')
00528         self.assertFalse(item is None)
00529         self.assertEqual(item.title, 'Another Test Menu Item')
00530 
00531         item = self._getMenuItemByAction('@@bar.html')
00532         self.assertEqual(item.title, 'Another Test Menu Item')
00533         item = self._getMenuItemByAction('++view++bar.html')
00534         self.assertEqual(item.title, 'Another Test Menu Item')
00535 
00536     def testNonExisting(self):
00537         """Attempt to retrieve a non-registered IBrowserMenuItem"""
00538         item = self._getMenuItemByAction('nonesuch.html')
00539         self.assertTrue(item is None)
00540 
00541 
00542 def test_suite():
00543     from unittest import TestSuite, makeSuite
00544     suite = TestSuite()
00545     suite.addTest(makeSuite(TestActionsMenu))
00546     suite.addTest(makeSuite(TestDisplayMenu))
00547     suite.addTest(makeSuite(TestFactoriesMenu))
00548     suite.addTest(makeSuite(TestWorkflowMenu))
00549     suite.addTest(makeSuite(TestContentMenu))
00550     suite.addTest(makeSuite(TestDisplayViewsMenu))
00551     return suite