vendor/Five/1.2b-r20590

view browser/tests/test_menu.py @ 0:3673ed425f80

Vendor import of Five 1.2b+ (r20590)
author fguillaume
date Fri, 02 Dec 2005 20:25:42 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2004, 2005 Zope Corporation and Contributors.
4 # All Rights Reserved.
5 #
6 # This software is subject to the provisions of the Zope Public License,
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11 # FOR A PARTICULAR PURPOSE.
12 #
13 ##############################################################################
14 """Test browser menus
16 $Id: test_menu.py 14595 2005-07-12 21:26:12Z philikon $
17 """
18 import os, sys
19 if __name__ == '__main__':
20 execfile(os.path.join(sys.path[0], 'framework.py'))
22 def test_menu():
23 """
24 Test menus
26 Before we can start we need to set up a few things. For menu
27 configuration, we have to start a new interaction:
29 >>> import Products.Five.browser.tests
30 >>> from Products.Five import zcml
31 >>> zcml.load_config("configure.zcml", Products.Five)
32 >>> zcml.load_config('menu.zcml', package=Products.Five.browser.tests)
34 >>> from Products.Five.security import newInteraction
35 >>> newInteraction()
37 Now for some actual testing... Let's look up the menu we registered:
39 >>> from Products.Five.traversable import FakeRequest
40 >>> from zope.app.publisher.browser.globalbrowsermenuservice import \\
41 ... globalBrowserMenuService
43 >>> request = FakeRequest()
44 >>> menu = globalBrowserMenuService.getMenu(
45 ... 'testmenu', self.folder, request)
47 It should have
49 >>> len(menu)
50 4
52 Sort menu items by title so we get a stable testable result:
54 >>> menu.sort(lambda x, y: cmp(x['title'], y['title']))
55 >>> from pprint import pprint
56 >>> pprint(menu)
57 [{'action': '@@cockatiel_menu_public.html',
58 'description': '',
59 'extra': None,
60 'selected': '',
61 'title': u'Page in a menu (public)'},
62 {'action': u'seagull.html',
63 'description': u'This is a test menu item',
64 'extra': None,
65 'selected': '',
66 'title': u'Test Menu Item'},
67 {'action': u'parakeet.html',
68 'description': u'This is a test menu item',
69 'extra': None,
70 'selected': '',
71 'title': u'Test Menu Item 2'},
72 {'action': u'falcon.html',
73 'description': u'This is a test menu item',
74 'extra': None,
75 'selected': '',
76 'title': u'Test Menu Item 3'}]
78 Let's create a manager user account and log in.
80 >>> uf = self.folder.acl_users
81 >>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
82 >>> self.login('manager')
83 >>> newInteraction()
85 >>> menu = globalBrowserMenuService.getMenu(
86 ... 'testmenu', self.folder, request)
88 We should get the protected menu items now:
90 >>> len(menu)
91 7
93 >>> menu.sort(lambda x, y: cmp(x['title'], y['title']))
94 >>> pprint(menu)
95 [{'action': '@@cockatiel_menu_protected.html',
96 'description': '',
97 'extra': None,
98 'selected': '',
99 'title': u'Page in a menu (protected)'},
100 {'action': '@@cockatiel_menu_public.html',
101 'description': '',
102 'extra': None,
103 'selected': '',
104 'title': u'Page in a menu (public)'},
105 {'action': u'seagull.html',
106 'description': u'This is a protected test menu item',
107 'extra': None,
108 'selected': '',
109 'title': u'Protected Test Menu Item'},
110 {'action': u'falcon.html',
111 'description': u'This is a protected test menu item',
112 'extra': None,
113 'selected': '',
114 'title': u'Protected Test Menu Item 2'},
115 {'action': u'seagull.html',
116 'description': u'This is a test menu item',
117 'extra': None,
118 'selected': '',
119 'title': u'Test Menu Item'},
120 {'action': u'parakeet.html',
121 'description': u'This is a test menu item',
122 'extra': None,
123 'selected': '',
124 'title': u'Test Menu Item 2'},
125 {'action': u'falcon.html',
126 'description': u'This is a test menu item',
127 'extra': None,
128 'selected': '',
129 'title': u'Test Menu Item 3'}]
132 Clean up:
134 >>> from zope.app.tests.placelesssetup import tearDown
135 >>> tearDown()
136 """
138 def test_suite():
139 from Testing.ZopeTestCase import ZopeDocTestSuite
140 return ZopeDocTestSuite()
142 if __name__ == '__main__':
143 framework()