get_commenter_portrait and get_commenter_home_url methods added to comments viewlet.

tests for get_commenter_portrait added.

svn path=/plone.app.discussion/trunk/; revision=27349
This commit is contained in:
Timo Stollenwerk
2009-06-07 20:58:41 +00:00
parent dada11c43c
commit 1af2b435fd
3 changed files with 69 additions and 10 deletions
@@ -7,9 +7,13 @@ from zope.component import createObject
from Acquisition import aq_base, aq_parent, aq_inner
from OFS.Image import Image
from plone.app.vocabularies.types import BAD_TYPES
from Products.CMFCore.FSImage import FSImage
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.tests import dummy
from Products.PloneTestCase.ptc import PloneTestCase
from plone.app.discussion.browser.comments import CommentsViewlet
@@ -22,11 +26,12 @@ class CommentsViewletTest(PloneTestCase):
layer = DiscussionLayer
def afterSetUp(self):
# First we need to create some content.
self.loginAsPortalOwner()
typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1')
self.portal_discussion = getToolByName(self.portal, 'portal_discussion', None)
self.membership_tool = getToolByName(self.folder, 'portal_membership')
self.memberdata = self.portal.portal_memberdata
request = self.app.REQUEST
context = getattr(self.portal, 'doc1')
self.viewlet = CommentsViewlet(context, request, None, None)
@@ -35,12 +40,53 @@ class CommentsViewletTest(PloneTestCase):
pass
def test_get_commenter_portrait(self):
# Add a user with a member image
self.membership_tool.addMember('jim', 'Jim', ['Member'], [])
self.memberdata._setPortrait(Image(id='jim', file=dummy.File(), title=''), 'jim')
self.assertEqual(self.memberdata._getPortrait('jim').getId(), 'jim')
self.assertEqual(self.memberdata._getPortrait('jim').meta_type, 'Image')
# Add a conversation with a comment
conversation = IConversation(self.portal.doc1)
conversation = conversation.__of__(self.portal.doc1)
comment = createObject('plone.Comment')
comment.title = 'Comment 1'
comment.text = 'Comment text'
comment.Creator = 'Jim'
comment.author_username = 'jim'
new_id = conversation.addComment(comment)
# Call get_commenter_portrait method of the viewlet
self.viewlet.update()
self.viewlet.get_commenter_portrait('Foo')
portrait = self.viewlet.get_commenter_portrait('jim')
# Check if the correct member image is returned
self.assert_(isinstance(portrait, Image))
self.assertEquals(portrait.absolute_url(), 'http://nohost/plone/portal_memberdata/portraits/jim')
def test_get_commenter_portrait_without_userimage(self):
# Create a user without a user image
pass
self.membership_tool.addMember('jim', 'Jim', ['Member'], [])
# Add a conversation with a comment
conversation = IConversation(self.portal.doc1)
conversation = conversation.__of__(self.portal.doc1)
comment = createObject('plone.Comment')
comment.title = 'Comment 1'
comment.text = 'Comment text'
comment.Creator = 'Jim'
comment.author_username = 'jim'
new_id = conversation.addComment(comment)
# Call get_commenter_portrait method of the viewlet
self.viewlet.update()
portrait = self.viewlet.get_commenter_portrait('jim')
# Check if the correct default member image is returned
self.assert_(isinstance(portrait, FSImage))
self.assertEquals(portrait.absolute_url(), 'http://nohost/plone/defaultUser.gif')
def test_get_commenter_home(self):
pass