Back to index

plone3  3.1.7
test_portlet_static.py
Go to the documentation of this file.
00001 from zope.component import getUtility, getMultiAdapter
00002 
00003 from plone.portlets.interfaces import IPortletType
00004 from plone.portlets.interfaces import IPortletManager
00005 from plone.portlets.interfaces import IPortletAssignment
00006 from plone.portlets.interfaces import IPortletDataProvider
00007 from plone.portlets.interfaces import IPortletRenderer
00008 
00009 from plone.app.portlets.storage import PortletAssignmentMapping
00010 
00011 from plone.portlet.static import static
00012 
00013 from plone.portlet.static.tests.base import TestCase
00014 
00015 class TestPortlet(TestCase):
00016 
00017     def afterSetUp(self):
00018         self.setRoles(('Manager',))
00019 
00020     def testPortletTypeRegistered(self):
00021         portlet = getUtility(IPortletType, name='plone.portlet.static.Static')
00022         self.assertEquals(portlet.addview, 'plone.portlet.static.Static')
00023 
00024     def testInterfaces(self):
00025         portlet = static.Assignment(header=u"title", text="text")
00026         self.failUnless(IPortletAssignment.providedBy(portlet))
00027         self.failUnless(IPortletDataProvider.providedBy(portlet.data))
00028 
00029     def testInvokeAddview(self):
00030         portlet = getUtility(IPortletType, name='plone.portlet.static.Static')
00031         mapping = self.portal.restrictedTraverse('++contextportlets++plone.leftcolumn')
00032         for m in mapping.keys():
00033             del mapping[m]
00034         addview = mapping.restrictedTraverse('+/' + portlet.addview)
00035 
00036         addview.createAndAdd(data={'header' : u"test title", 'text' : u"test text"})
00037 
00038         self.assertEquals(len(mapping), 1)
00039         self.failUnless(isinstance(mapping.values()[0], static.Assignment))
00040 
00041     def testInvokeEditView(self):
00042         mapping = PortletAssignmentMapping()
00043         request = self.folder.REQUEST
00044 
00045         mapping['foo'] = static.Assignment(header=u"title", text="text")
00046         editview = getMultiAdapter((mapping['foo'], request), name='edit')
00047         self.failUnless(isinstance(editview, static.EditForm))
00048 
00049     def testRenderer(self):
00050         context = self.folder
00051         request = self.folder.REQUEST
00052         view = self.folder.restrictedTraverse('@@plone')
00053         manager = getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00054         assignment = static.Assignment(header=u"title", text="text")
00055 
00056         renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00057         self.failUnless(isinstance(renderer, static.Renderer))
00058 
00059         self.failUnless(renderer.available,
00060                         "Renderer should be available by default.")
00061         assignment = static.Assignment(header=u"title", text="text", hide=True)
00062         renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00063         self.failIf(renderer.available, "Renderer should not be available.")
00064 
00065 
00066 class TestRenderer(TestCase):
00067     
00068     def afterSetUp(self):
00069         self.setRoles(('Manager',))
00070 
00071     def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
00072         context = context or self.folder
00073         request = request or self.folder.REQUEST
00074         view = view or self.folder.restrictedTraverse('@@plone')
00075         manager = manager or getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00076         assignment = assignment or static.Assignment(header=u"title", text="text")
00077 
00078         return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00079 
00080     def test_render(self):
00081         r = self.renderer(context=self.portal, assignment=static.Assignment(header=u"title", text="<b>text</b>"))
00082         r = r.__of__(self.folder)
00083         r.update()
00084         output = r.render()
00085         self.failUnless('title' in output)
00086         self.failUnless('<b>text</b>' in output)
00087 
00088     def test_available(self):
00089         r = self.renderer(
00090             context=self.portal,
00091             assignment=static.Assignment(header=u"title", text="<b>text</b>",
00092                                          hide=True))
00093         r = r.__of__(self.folder)
00094         r.update()
00095         self.failIf(r.available, "Renderer should not be available.")
00096         
00097     def test_css_class(self):
00098         r = self.renderer(context=self.portal, 
00099                           assignment=static.Assignment(header=u"Welcome text", text="<b>text</b>"))
00100         self.assertEquals('portlet-static-welcome-text', r.css_class())
00101         
00102 def test_suite():
00103     from unittest import TestSuite, makeSuite
00104     suite = TestSuite()
00105     suite.addTest(makeSuite(TestPortlet))
00106     suite.addTest(makeSuite(TestRenderer))
00107     return suite