def test_portlet_collection(self): query = [{ 'i': 'portal_type', 'o': 'plone.app.querystring.operation.selection.is', 'v': ['Document'] }] # add a few documents for i in range(6): self.folder.invokeFactory('Document', 'document_%s' % i) getattr(self.folder, 'document_%s' % i).reindexObject() collection = getattr(self.folder, 'collection') collection.setQuery(query) # the documents are returned by the collection collection_num_items = len(self.folder.collection.queryCatalog()) # We better have some documents - we should have 8 self.failUnless(collection_num_items >= 8) mapping = PortletAssignmentMapping() mapping['foo'] = carousel.Assignment( header=u"Test carousel", target_collection='/Members/test_user_1_/collection') r = self.renderer(context=None, request=None, view=None, manager=None, assignment=mapping['foo']) # sanity check self.assertEqual(r.collection().id, 'collection') # we want the portlet to return us the same results as the collection self.assertEquals(collection_num_items, len(r.results()))
def test_render(self): r = self.renderer( context=self.portal, assignment=carousel.Assignment( header=u"title", target_collection='/plone/Members/test_user_1_/collection')) r = r.__of__(self.folder) r.update() output = r.render() self.assertTrue('title' in output)
def testRenderer(self): context = self.folder request = self.folder.REQUEST view = self.folder.restrictedTraverse('@@plone') manager = getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal) assignment = carousel.Assignment(header=u"title") renderer = getMultiAdapter( (context, request, view, manager, assignment), IPortletRenderer) self.failUnless(isinstance(renderer, carousel.Renderer))
def test_edit_link(self): collection = getattr(self.folder, 'collection') collection.setQuery(query) mapping = PortletAssignmentMapping() mapping['foo'] = carousel.Assignment( header=u"Test carousel", target_collection='/Members/test_user_1_/collection') r = self.renderer(context=None, request=None, view=None, manager=None, assignment=mapping['foo']) self.assertTrue(r.editCarouselLink().endswith('/edit'))
def renderer(self, context=None, request=None, view=None, manager=None, assignment=None): context = context or self.folder request = request or self.folder.REQUEST view = view or self.folder.restrictedTraverse('@@plone') manager = manager or getUtility( IPortletManager, name='plone.rightcolumn', context=self.portal) assignment = assignment or carousel.Assignment(header=u"title") return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
def testInvokeEditView(self): mapping = PortletAssignmentMapping() request = self.folder.REQUEST mapping['foo'] = carousel.Assignment(header=u"title") editview = getMultiAdapter((mapping['foo'], request), name='edit') self.failUnless(isinstance(editview, carousel.EditForm))
def testInterfaces(self): portlet = carousel.Assignment(header=u"title") self.failUnless(IPortletAssignment.providedBy(portlet)) self.failUnless(IPortletDataProvider.providedBy(portlet.data))
def test_hideheader(self): r = self.renderer(context=self.portal, assignment=carousel.Assignment( header=u"Test carousel", hideheader=True)) output = r.render() self.failUnless('class="portletHeader hiddenStructure"' in output)
def test_css_class(self): r = self.renderer( context=self.portal, assignment=carousel.Assignment(header=u"Test carousel")) self.assertEquals('portlet-carousel-test-carousel', r.css_class())