[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser/tests - test_globalbrowsermenuservice.py:1.11.6.1
Peter Simmons
pete@bcmpweb.com
Sun, 13 Jul 2003 05:10:48 -0400
Update of /cvs-repository/Zope3/src/zope/app/publisher/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv29766/src/zope/app/publisher/browser/tests
Modified Files:
Tag: ozzope-menu
test_globalbrowsermenuservice.py
Log Message:
: ----------------------------------------------------------------------
: This branch contains the beginnings of a recursive menuing system
: Including a drop-down add menu written in javascript. It implements
: extension to the zcml which allows you to link menu items to menus thus
: creating submenus.
: Peter S and Dave F Melbourne Sprint
:
: Committing in .
:
: Modified Files:
: Tag: ozzope-menu
: products.zcml.in src/zope/app/browser/menu.py
: src/zope/app/browser/menus.zcml
: src/zope/app/browser/container/configure.zcml
: src/zope/app/browser/skins/configure.zcml
: src/zope/app/interfaces/publisher/browser.py
: src/zope/app/publisher/browser/configure.zcml
: src/zope/app/publisher/browser/globalbrowsermenuservice.py
: src/zope/app/publisher/browser/meta.zcml
:----------------------------------------------------------------------
=== Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py 1.11 => 1.11.6.1 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py:1.11 Wed Jul 9 21:35:15 2003
+++ Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py Sun Jul 13 05:10:42 2003
@@ -18,7 +18,9 @@
$Id$
"""
-from unittest import TestCase, main, makeSuite
+from unittest import TestCase, main, makeSuite, TestSuite
+from zope.testing.doctestunit import DocTestSuite
+
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.exceptions import Forbidden, Unauthorized, DuplicationError
from zope.interface import Interface, implements
@@ -49,24 +51,27 @@
raise Unauthorized, name
return self.f
-
+
class Test(PlacelessSetup, TestCase):
-
+
def __reg(self):
from zope.app.publisher.browser.globalbrowsermenuservice \
import GlobalBrowserMenuService
r = GlobalBrowserMenuService()
return r
-
+
def testDup(self):
r = self.__reg()
r.menu('test_id', 'test menu')
self.assertRaises(DuplicationError, r.menu, 'test_id', 'test menu')
def test(self):
+ #test action attribute
r = self.__reg()
r.menu('test_id', 'test menu')
+ r.menu('sub_test_id', 'test sub menu')
+ r.menu('subsub_test_id', 'test sub sub menu')
r.menuItem('test_id', Interface, 'a1', 't1', 'd1')
r.menuItem('test_id', I1, 'a2', 't2', 'd2')
r.menuItem('test_id', I11, 'a3', 't3', 'd3', 'context')
@@ -76,7 +81,15 @@
r.menuItem('test_id', I111, 'f7', 't7', 'd7')
r.menuItem('test_id', I111, 'u8', 't8', 'd8')
r.menuItem('test_id', I12, 'a9', 't9', 'd9')
-
+ r.menuItem('test_id', I11, 'a10', 't10', 'd10', submenu='sub_test_id')
+ r.menuItem('test_id', I11, 'a11', 't11', 'd11')
+ r.menuItem('sub_test_id', I11, 'sa1', 'st1', 'sd1')
+ r.menuItem('sub_test_id', I11, 'sa2', 'st2', 'sd2')
+ r.menuItem('sub_test_id', I11, 'sa3', 'st3', 'sd3', submenu='subsub_test_id')
+ r.menuItem('sub_test_id', I11, 'sa4', 'st4', 'sd4')
+ r.menuItem('subsub_test_id', I11, 'ssa1', 'sst1', 'ssd1')
+ r.menuItem('subsub_test_id', I11, 'ssa1', 'sst1', 'ssd1')
+
menu = r.getMenu('test_id', X(), TestRequest())
def d(n):
@@ -86,7 +99,24 @@
'selected': ''
}
- self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])
+ def sub(n):
+ return {'title': "st%s" % n,
+ 'description': "sd%s" % n,
+ 'action': "sa%s" % n,
+ }
+
+ def subsub(n):
+ return {'title': "sst%s" % n,
+ 'description': "ssd%s" % n,
+ 'action': "ssa%s" % n,
+ }
+
+ sub_sub = [subsub(2), subsub(1)]
+
+ sub_menu = [sub(4), sub_sub, sub(2), sub(1)]
+
+ self.assertEqual(list(menu), [d(11), sub_menu, d(5), d(6), d(3), d(2), d(1)])
+
def test_w_permission(self):
serviceManager.defineService(Permissions, IPermissionService)
@@ -199,9 +229,30 @@
r.menu('test_id2', 'test menu')
self.assertEqual(r.getMenuUsage('test_id2'), u'')
+def test_submenu(self):
+ """
+ >>> from zope.app.publisher.browser.globalbrowsermenuservice import GlobalBrowserMenuService
+ >>> r = GlobalBrowserMenuService()
+ >>> r.menu('test_id', 'test menu')
+ >>> r.menuItem('test_id', Interface, None, 'title1', 'desc1', submenu='sub1_id')
+ >>> r.menuItem('test_id', Interface, 'action12', 'title2', 'desc2')
+ >>> r.menu('sub1_id', 'test sub menu')
+ >>> r.menuItem('sub1_id', I1, 'sub_action1', 'sub_title1', 'sub_desc1')
+ >>> sub_menu = r.getMenu('sub1_id', X(), TestRequest())
+ >>> sub_menu
+ [{'action': 'sub_action1', 'selected': '', 'description': 'sub_desc1', 'title': 'sub_title1'}]
+ >>> menu = r.getMenu('test_id', X(), TestRequest())
+ >>> menu
+ [{'submenu': [{'action': 'sub_action1', 'selected': '', 'description': 'sub_desc1', 'title': 'sub_title1'}], 'description': 'desc1', 'title': 'title1'}, {'action': 'action12', 'selected': '', 'description': 'desc2', 'title': 'title2'}]
+ """
+
def test_suite():
- return makeSuite(Test)
+ suite = TestSuite()
+ suite.addTest(makeSuite(Test))
+ suite.addTest(DocTestSuite())
+
+ return suite
if __name__=='__main__':
main(defaultTest='test_suite')