[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser/tests - testusage.pt:1.1 test_directives.py:1.13 test_globalbrowsermenuservice.py:1.8 test_globalbrowsermenuservicedirectives.py:1.3
Godefroid Chapelle
gotcha@swing.be
Fri, 11 Apr 2003 18:16:18 -0400
Update of /cvs-repository/Zope3/src/zope/app/publisher/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv9040/app/publisher/browser/tests
Modified Files:
test_directives.py test_globalbrowsermenuservice.py
test_globalbrowsermenuservicedirectives.py
Added Files:
testusage.pt
Log Message:
- added usage argument to ZCML menu directive
The menu usage is used by the configuration to initialize
the page view usage in case a page is registered as a
menu item included in a menu declared with a usage argument.
- added corresponding tests
- various ZCML refactorings to improve usage initialization
- added tests for menu and usage on page directive
=== Added File Zope3/src/zope/app/publisher/browser/tests/testusage.pt ===
<tal:usage replace="usage" />
=== Zope3/src/zope/app/publisher/browser/tests/test_directives.py 1.12 => 1.13 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_directives.py:1.12 Thu Feb 20 13:24:58 2003
+++ Zope3/src/zope/app/publisher/browser/tests/test_directives.py Fri Apr 11 18:15:47 2003
@@ -29,7 +29,10 @@
from zope.proxy.introspection import removeAllProxies
import zope.configuration
+from zope.app.publisher.browser.globalbrowsermenuservice import \
+ globalBrowserMenuService
from zope.component.tests.request import Request
+from zope.publisher.browser import TestRequest
from zope.publisher.interfaces.browser import IBrowserPresentation
@@ -119,6 +122,204 @@
v = queryView(ob, 'test', request)
self.assert_(issubclass(v.__class__, V1))
+
+ def testPageWithClassWithMenu(self):
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+ testusage = os.path.join(tests_path, 'testusage.pt')
+
+
+ xmlconfig(StringIO(template % (
+ """
+ <browser:menu id="test_menu" title="Test menu" usage="objectview"/>
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
+ for="zope.component.tests.views.IC"
+ permission="zope.Public"
+ template="%s"
+ menu="test_menu"
+ title="Test View"
+ />
+ """ % testusage
+ )))
+
+ menuItem = globalBrowserMenuService.getFirstMenuItem('test_menu', ob, TestRequest())
+ self.assertEqual(menuItem["title"], "Test View")
+ self.assertEqual(menuItem["action"], "@@test")
+ v = queryView(ob, 'test', request)
+ self.assertEqual(v(), "objectview\n")
+
+ def testPageWithClassWithUsage(self):
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+ testusage = os.path.join(tests_path, 'testusage.pt')
+
+
+ xmlconfig(StringIO(template % (
+ """
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
+ for="zope.component.tests.views.IC"
+ permission="zope.Public"
+ template="%s"
+ usage="objectview"
+ />
+ """ % testusage
+ )))
+
+ v = queryView(ob, 'test', request)
+ self.assertEqual(v(), "objectview\n")
+
+ def testPageWithClassWithMenuAndUsage(self):
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+ testusage = os.path.join(tests_path, 'testusage.pt')
+
+
+ xmlconfig(StringIO(template % (
+ """
+ <browser:menu id="test_menu" title="Test menu" usage="overridden"/>
+ <browser:page name="test"
+ class="zope.component.tests.views.V1"
+ for="zope.component.tests.views.IC"
+ permission="zope.Public"
+ template="%s"
+ menu="test_menu"
+ title="Test View"
+ usage="objectview"
+ />
+ """ % testusage
+ )))
+
+ menuItem = globalBrowserMenuService.getFirstMenuItem('test_menu', ob, TestRequest())
+ self.assertEqual(menuItem["title"], "Test View")
+ self.assertEqual(menuItem["action"], "@@test")
+ v = queryView(ob, 'test', request)
+ self.assertEqual(v(), "objectview\n")
+
+ def testPageWithTemplateWithMenu(self):
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+ testusage = os.path.join(tests_path, 'testusage.pt')
+
+
+ xmlconfig(StringIO(template % (
+ """
+ <browser:menu id="test_menu" title="Test menu" usage="objectview"/>
+ <browser:page name="test"
+ for="zope.component.tests.views.IC"
+ permission="zope.Public"
+ template="%s"
+ menu="test_menu"
+ title="Test View"
+ />
+ """ % testusage
+ )))
+
+ menuItem = globalBrowserMenuService.getFirstMenuItem('test_menu', ob, TestRequest())
+ self.assertEqual(menuItem["title"], "Test View")
+ self.assertEqual(menuItem["action"], "@@test")
+ v = queryView(ob, 'test', request)
+ self.assertEqual(v(), "objectview\n")
+
+ def testPageWithTemplateWithUsage(self):
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+ testusage = os.path.join(tests_path, 'testusage.pt')
+
+
+ xmlconfig(StringIO(template % (
+ """
+ <browser:page name="test"
+ for="zope.component.tests.views.IC"
+ permission="zope.Public"
+ template="%s"
+ usage="objectview"
+ />
+ """ % testusage
+ )))
+
+ v = queryView(ob, 'test', request)
+ self.assertEqual(v(), "objectview\n")
+
+ def testPageWithTemplateWithMenuAndUsage(self):
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+ testusage = os.path.join(tests_path, 'testusage.pt')
+
+
+ xmlconfig(StringIO(template % (
+ """
+ <browser:menu id="test_menu" title="Test menu" usage="overridden"/>
+ <browser:page name="test"
+ for="zope.component.tests.views.IC"
+ permission="zope.Public"
+ template="%s"
+ menu="test_menu"
+ title="Test View"
+ usage="objectview"
+ />
+ """ % testusage
+ )))
+
+ menuItem = globalBrowserMenuService.getFirstMenuItem('test_menu', ob, TestRequest())
+ self.assertEqual(menuItem["title"], "Test View")
+ self.assertEqual(menuItem["action"], "@@test")
+ v = queryView(ob, 'test', request)
+ self.assertEqual(v(), "objectview\n")
+
+ def testPageInPagesWithTemplateWithMenu(self):
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+ testusage = os.path.join(tests_path, 'testusage.pt')
+
+
+ xmlconfig(StringIO(template % (
+ """
+ <browser:menu id="test_menu" title="Test menu" usage="objectview"/>
+ <browser:pages for="zope.component.tests.views.IC"
+ permission="zope.Public">
+ <browser:page name="test"
+ template="%s"
+ menu="test_menu"
+ title="Test View"
+ />
+ </browser:pages>
+ """ % testusage
+ )))
+
+ menuItem = globalBrowserMenuService.getFirstMenuItem('test_menu', ob, TestRequest())
+ self.assertEqual(menuItem["title"], "Test View")
+ self.assertEqual(menuItem["action"], "@@test")
+ v = queryView(ob, 'test', request)
+ self.assertEqual(v(), "objectview\n")
+
+ def testPageInPagesWithClassWithMenu(self):
+ self.assertEqual(queryView(ob, 'test', request),
+ None)
+ testusage = os.path.join(tests_path, 'testusage.pt')
+
+
+ xmlconfig(StringIO(template % (
+ """
+ <browser:menu id="test_menu" title="Test menu" usage="objectview"/>
+ <browser:pages for="zope.component.tests.views.IC"
+ class="zope.component.tests.views.V1"
+ permission="zope.Public">
+ <browser:page name="test"
+ template="%s"
+ menu="test_menu"
+ title="Test View"
+ />
+ </browser:pages>
+ """ % testusage
+ )))
+
+ menuItem = globalBrowserMenuService.getFirstMenuItem('test_menu', ob, TestRequest())
+ self.assertEqual(menuItem["title"], "Test View")
+ self.assertEqual(menuItem["action"], "@@test")
+ v = queryView(ob, 'test', request)
+ self.assertEqual(v(), "objectview\n")
def testDefaultView(self):
self.assertEqual(queryView(ob, 'test', request,
=== Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py:1.7 Tue Feb 11 21:17:28 2003
+++ Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py Fri Apr 11 18:15:47 2003
@@ -158,6 +158,13 @@
menu = r.getMenu('test_id', X(), TestRequest())
self.assertEqual(list(menu), [])
+ def testUsage(self):
+ r = self.__reg()
+ r.menu('test_id', 'test menu', usage=u'objectview')
+ self.assertEqual(r.getMenuUsage('test_id'), u'objectview')
+ r.menu('test_id2', 'test menu')
+ self.assertEqual(r.getMenuUsage('test_id2'), u'')
+
def test_suite():
return makeSuite(Test)
=== Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservicedirectives.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservicedirectives.py:1.2 Wed Dec 25 09:13:10 2002
+++ Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservicedirectives.py Fri Apr 11 18:15:47 2003
@@ -25,6 +25,8 @@
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.browser import TestRequest
from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.publisher.browser.globalbrowsermenuservice \
+ import globalBrowserMenuService
import zope.configuration
import zope.app.publisher.browser
@@ -43,9 +45,6 @@
XMLConfig('meta.zcml', zope.app.publisher.browser)()
def test(self):
- from zope.app.publisher.browser.globalbrowsermenuservice \
- import globalBrowserMenuService
-
xmlconfig(StringIO(template % (
"""
<browser:menu id="test_id" title="test menu" />
@@ -106,6 +105,20 @@
'test_id', X(), TestRequest())
self.assertEqual(first, d(5))
+
+ def testUsage(self):
+
+ xmlconfig(StringIO(template % (
+ """
+ <browser:menu id="test_id" title="test menu" usage="objectview" />
+
+ <browser:menu id="test_id2" title="test menu" />
+
+ """)))
+
+ self.assertEqual(globalBrowserMenuService.getMenuUsage('test_id'), u'objectview')
+ self.assertEqual(globalBrowserMenuService.getMenuUsage('test_id2'), u'')
+
def test_suite():
return makeSuite(Test)