Back to index

plone3  3.1.7
test_browserdefault.py
Go to the documentation of this file.
00001 from Products.CMFDynamicViewFTI.tests import CMFDVFTITestCase
00002 
00003 import zope.component 
00004 import zope.publisher.browser
00005 
00006 from Products.CMFCore.utils import getToolByName
00007 
00008 from Products.CMFDynamicViewFTI.interfaces import ISelectableBrowserDefault
00009 from Products.CMFDynamicViewFTI.interfaces import IBrowserDefault
00010 from Products.CMFDynamicViewFTI.browserdefault import BrowserDefaultMixin
00011 
00012 from Interface.Verify import verifyClass
00013 
00014 class DummyFolder(BrowserDefaultMixin):
00015 
00016     def getTypeInfo(self):
00017         return self.fti
00018 
00019 class IDummy(zope.interface.Interface):
00020     """ marker interface for a zope 3 view """
00021 
00022 class BrowserView(zope.publisher.browser.BrowserView):
00023 
00024     def __init__(self, context, request):
00025         self.context = context
00026         self.request = request   
00027 
00028 class TestBrowserDefault(CMFDVFTITestCase.CMFDVFTITestCase):
00029 
00030     def test_doesImplementISelectableBrowserDefault(self):
00031         iface = ISelectableBrowserDefault
00032         self.failUnless(iface.isImplementedByInstancesOf(BrowserDefaultMixin))
00033         self.failUnless(verifyClass(iface, BrowserDefaultMixin))
00034 
00035     def test_extendsInterface(self):
00036         self.failUnless(ISelectableBrowserDefault.extends(IBrowserDefault))
00037 
00038 class TestAvailableLayouts(CMFDVFTITestCase.CMFDVFTITestCase):
00039 
00040     def afterSetUp(self):
00041         self.types = getToolByName(self.portal, 'portal_types')
00042 
00043         self.dfolder = DummyFolder()
00044         self.dfolder.fti = self.types['DynFolder']
00045 
00046         from Products.Five import zcml
00047         import plone.app.contentmenu
00048         import Products.CMFDynamicViewFTI.tests
00049         zcml.load_config('configure.zcml', plone.app.contentmenu)
00050         zcml.load_config('browserdefault.zcml', 
00051                          Products.CMFDynamicViewFTI.tests)
00052         
00053     def test_Zope3View(self):
00054         dfolder = self.dfolder
00055         dfolder.layout = 'zope3_view'
00056         dfolder.REQUEST = zope.publisher.browser.TestRequest()
00057         view_methods = dfolder.getAvailableLayouts()
00058         view_ids = [ view_id for view_id, foo in view_methods ]
00059         self.failIf(dfolder.layout in view_ids)
00060         
00061         # Mark the object with interface connected to the zope 3 view
00062         zope.interface.directlyProvides(dfolder, IDummy)
00063         view_methods = dfolder.getAvailableLayouts()
00064         view_ids = [ view_id for view_id, foo in view_methods ]
00065         self.failIf(dfolder.layout not in view_ids)
00066         
00067     def test_Zope3ViewTitle(self):
00068         dfolder = self.dfolder
00069         dfolder.layout = 'zope3_view'
00070         dfolder.REQUEST = zope.publisher.browser.TestRequest()
00071         zope.interface.directlyProvides(dfolder, IDummy)
00072         view_methods = dfolder.getAvailableLayouts()
00073         
00074         for id, title in view_methods:
00075             if id == dfolder.layout:
00076                 self.assertEqual(title, 'Zope3 Test View')
00077         
00078 def test_suite():
00079     from unittest import TestSuite, makeSuite
00080     suite = TestSuite()
00081     suite.addTest(makeSuite(TestBrowserDefault))
00082     suite.addTest(makeSuite(TestAvailableLayouts))    
00083     return suite