Ejemplo n.º 1
0
    def testMenuOverride(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='test'),
            None)

        xmlconfig(StringIO(template % (
            '''
            <browser:menu
                id="test_menu" title="Test menu" />
            <browser:menuItem
                action="@@test"
                for="zope.component.testfiles.views.IC"
                permission="zope.Public"
                menu="test_menu"
                title="Test View"
                />
            '''
            )))
        menu1 = component.getUtility(IBrowserMenu, 'test_menu')
        menuItem1 = getFirstMenuItem('test_menu', ob, TestRequest())
        xmlconfig(StringIO(template % (
            '''
            <browser:menu
                id="test_menu" title="Test menu"
                class="zope.browsermenu.tests.test_directives.M1" />
            '''
            )))
        menu2 = component.getUtility(IBrowserMenu, 'test_menu')
        menuItem2 = getFirstMenuItem('test_menu', ob, TestRequest())
        self.assertNotEqual(menu1, menu2)
        self.assertEqual(menuItem1, menuItem2)
Ejemplo n.º 2
0
    def testMenuOverride(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='test'), None)

        xmlconfig(
            StringIO(template % ('''
            <browser:menu
                id="test_menu" title="Test menu" />
            <browser:menuItem
                action="@@test"
                for="zope.component.testfiles.views.IC"
                permission="zope.Public"
                menu="test_menu"
                title="Test View"
                />
            ''')))
        menu1 = component.getUtility(IBrowserMenu, 'test_menu')
        menuItem1 = getFirstMenuItem('test_menu', ob, TestRequest())
        xmlconfig(
            StringIO(template % ('''
            <browser:menu
                id="test_menu" title="Test menu"
                class="zope.browsermenu.tests.test_directives.M1" />
            ''')))
        menu2 = component.getUtility(IBrowserMenu, 'test_menu')
        menuItem2 = getFirstMenuItem('test_menu', ob, TestRequest())
        self.assertNotEqual(menu1, menu2)
        self.assertEqual(menuItem1, menuItem2)
Ejemplo n.º 3
0
    def testPageInPagesWithClassWithMenu(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, self.request), name='test'), None)
        testtemplate = os.path.join(tests_path, 'testfiles', 'test.pt')

        xmlconfig(
            StringIO(template % ('''
            <browser:menu
                id="test_menu" title="Test menu" />
            <browser:pages
                for="zope.browserpage.tests.test_page.IC"
                class="zope.browserpage.tests.test_page.V1"
                permission="zope.Public">
              <browser:page
                  name="test"
                  template="%s"
                  menu="test_menu"
                  title="Test View"
                  />
            </browser:pages>
            ''' % testtemplate)))

        menuItem = getFirstMenuItem('test_menu', ob, TestRequest())
        self.assertEqual(menuItem["title"], "Test View")
        self.assertEqual(menuItem["action"], "@@test")
        v = component.queryMultiAdapter((ob, self.request), name='test')
        self.assertEqual(v().replace('\r\n', '\n'),
                         "<html><body><p>test</p></body></html>\n")
Ejemplo n.º 4
0
    def testPageInPagesWithClassWithMenu(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, self.request), name='test'),
            None)
        testtemplate = os.path.join(tests_path, 'testfiles', 'test.pt')

        xmlconfig(StringIO(template % (
            '''
            <browser:menu
                id="test_menu" title="Test menu" />
            <browser:pages
                for="zope.browserpage.tests.test_page.IC"
                class="zope.browserpage.tests.test_page.V1"
                permission="zope.Public">
              <browser:page
                  name="test"
                  template="%s"
                  menu="test_menu"
                  title="Test View"
                  />
            </browser:pages>
            ''' % testtemplate
            )))

        menuItem = getFirstMenuItem('test_menu', ob, TestRequest())
        self.assertEqual(menuItem["title"], "Test View")
        self.assertEqual(menuItem["action"], "@@test")
        v = component.queryMultiAdapter((ob, self.request), name='test')
        self.assertEqual(v().replace('\r\n', '\n'),
                         "<html><body><p>test</p></body></html>\n")
Ejemplo n.º 5
0
 def __call__(self):
     item = getFirstMenuItem('zmi_views', self.context, self.request)
     assert item
     redirect_url = item['action']
     if not redirect_url.lower().startswith(('../', 'javascript:', '++')):
         self.request.response.redirect(redirect_url)
         return u''
     raise AssertionError("Should not get here") # pragma: no cover
    def __call__(self):
        item = getFirstMenuItem('zmi_views', self.context, self.request)

        if item:
            redirect_url = item['action']
            if not (redirect_url.startswith('../') or \
                    redirect_url.lower().startswith('javascript:') or \
                    redirect_url.lower().startswith('++')):
                self.request.response.redirect(redirect_url)
                return u''

        self.request.response.redirect('.') # Redirect to content/
        return u''
Ejemplo n.º 7
0
    def __call__(self):
        item = getFirstMenuItem('zmi_views', self.context, self.request)

        if item:
            redirect_url = item['action']
            if not (redirect_url.startswith('../') or \
                    redirect_url.lower().startswith('javascript:') or \
                    redirect_url.lower().startswith('++')):
                self.request.response.redirect(redirect_url)
                return u''

        self.request.response.redirect('.')  # Redirect to content/
        return u''