Back to index

plone3  3.1.7
test_fiveactionstool.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for five actions tool.
00014 
00015 $Id: test_fiveactionstool.py 71020 2006-11-01 15:42:13Z yuppie $
00016 """
00017 
00018 import unittest
00019 from Testing import ZopeTestCase
00020 
00021 
00022 def test_fiveactionstool():
00023     """
00024     Test the Five actions tool.
00025 
00026     Some basic setup:
00027 
00028       >>> import Products.Five
00029       >>> import Products.CMFCore
00030       >>> from Products.Five import zcml
00031       >>> zcml.load_config('meta.zcml', Products.Five)
00032       >>> zcml.load_config('permissions.zcml', Products.Five)
00033       >>> zcml.load_config('meta.zcml', Products.CMFCore)
00034       >>> folder = self.folder
00035 
00036     For menus to work, the request must have defaultSkin.
00037     
00038       >>> from zope.publisher.browser import setDefaultSkin
00039       >>> setDefaultSkin(self.folder.REQUEST)
00040       
00041     We need to make Zope 3 use Zope 2s security policy
00042     
00043       >>> from zope.security.management import thread_local
00044       >>> thread_local.interaction = None
00045       >>> from Products.Five.security import newInteraction
00046       >>> newInteraction()
00047 
00048     Log in as manager
00049    
00050       >>> uf = self.folder.acl_users
00051       >>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
00052       >>> self.login('manager')
00053 
00054     Let's create a Five actions tool:
00055 
00056       >>> from Products.CMFCore.fiveactionstool import FiveActionsTool
00057       >>> folder.tool = FiveActionsTool()
00058       >>> tool = folder.tool # rewrap
00059 
00060     Let's create some simple content object providing ISimpleContent:
00061 
00062       >>> from Products.Five.tests.testing.simplecontent import SimpleContent
00063       >>> id = self.folder._setObject('foo', SimpleContent('foo', 'Foo'))
00064       >>> foo = self.folder.foo
00065 
00066     Now we'll load a configuration file specifying some menu and menu
00067     items for ISimpleContent.
00068 
00069       >>> import Products.CMFCore.tests
00070       >>> zcml.load_config('fiveactions.zcml', Products.CMFCore.tests)
00071 
00072     Let's look what the tool lists as actions for such an object. 
00073 
00074       >>> actions = tool.listActions(object=foo)
00075       >>> [(action.category, action.id) for action in actions]
00076       [('mymenu', 'action_foo_public.html'), ('mymenu', 'action_foo_protected.html')]
00077 
00078     But if we log in as a user who is not manager, we should not get the
00079     protected menu item, , as it was protected by a more restrictive permission:
00080     
00081       >>> uf = self.folder.acl_users
00082       >>> uf._doAddUser('user', 'user', [], [])
00083       >>> self.login('user')
00084       
00085       >>> actions = tool.listActions(object=foo)
00086       >>> [(action.category, action.id) for action in actions]
00087       [('mymenu', 'action_foo_public.html')]
00088 
00089     When looking at an object not implementing ISimpleContent, we see no
00090     actions:
00091 
00092       >>> tool.listActions(object=folder)
00093       ()
00094 
00095     The tool itself doesn't have any actions:
00096 
00097       >>> tool.listActions()
00098       ()
00099 
00100     Cleanup:
00101 
00102       >>> from zope.testing.cleanup import cleanUp
00103       >>> cleanUp()
00104     """
00105 
00106 
00107 def test_suite():
00108     return unittest.TestSuite((
00109         ZopeTestCase.ZopeDocTestSuite(),
00110         ))
00111 
00112 if __name__ == '__main__':
00113     unittest.main(defaultTest='test_suite')