more tests for comments viewlet.

svn path=/plone.app.discussion/trunk/; revision=33217
This commit is contained in:
Timo Stollenwerk 2010-01-18 11:38:57 +00:00
parent ca0aecd170
commit 1bfff5255a
2 changed files with 34 additions and 6 deletions

View File

@ -293,13 +293,13 @@ class CommentsViewlet(ViewletBase, layout.FormWrapper):
else: else:
return published_replies() return published_replies()
def get_commenter_home_url(self, username): def get_commenter_home_url(self, username=None):
if username is None: if username is None:
return None return None
else: else:
return "%s/author/%s" % (self.context.portal_url(), username) return "%s/author/%s" % (self.context.portal_url(), username)
def get_commenter_portrait(self, username): def get_commenter_portrait(self, username=None):
if username is None: if username is None:
# return the default user image if no username is given # return the default user image if no username is given

View File

@ -61,7 +61,7 @@ class TestCommentsViewlet(PloneTestCase):
# Test if discussion has been enabled # Test if discussion has been enabled
self.failUnless(self.viewlet.is_discussion_allowed()) self.failUnless(self.viewlet.is_discussion_allowed())
def test_has_replies(self, workflow_actions=False): def test_has_replies(self):
self.failIf(self.viewlet.has_replies()) self.failIf(self.viewlet.has_replies())
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.title = 'Comment 1' comment.title = 'Comment 1'
@ -70,7 +70,7 @@ class TestCommentsViewlet(PloneTestCase):
conversation.addComment(comment) conversation.addComment(comment)
self.failUnless(self.viewlet.has_replies()) self.failUnless(self.viewlet.has_replies())
def test_get_replies(self, workflow_actions=False): def test_get_replies(self):
self.failIf(self.viewlet.get_replies()) self.failIf(self.viewlet.get_replies())
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.title = 'Comment 1' comment.title = 'Comment 1'
@ -80,6 +80,26 @@ class TestCommentsViewlet(PloneTestCase):
conversation.addComment(comment) conversation.addComment(comment)
self.assertEquals(sum(1 for w in self.viewlet.get_replies()), 2) self.assertEquals(sum(1 for w in self.viewlet.get_replies()), 2)
def test_get_replies_with_workflow_actions(self):
self.failIf(self.viewlet.get_replies(workflow_actions=True))
comment = createObject('plone.Comment')
comment.title = 'Comment 1'
comment.text = 'Comment text'
conversation = IConversation(self.portal.doc1)
c1 = conversation.addComment(comment)
self.assertEquals(sum(1 for w in self.viewlet.get_replies(workflow_actions=True)), 1)
# Enable moderation workflow
self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',),
('simple_publication_workflow,'))
# Check if workflow actions are available
reply = self.viewlet.get_replies(workflow_actions=True).next()
self.failUnless(reply.has_key('actions'))
self.assertEquals(reply['actions'][0]['id'],
'publish')
self.assertEquals(reply['actions'][0]['url'],
'http://nohost/plone/doc1/++conversation++default/%s' % int(c1) +
'/content_status_modify?workflow_action=publish')
def test_get_commenter_home_url(self): def test_get_commenter_home_url(self):
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.title = 'Comment 1' comment.title = 'Comment 1'
@ -90,6 +110,9 @@ class TestCommentsViewlet(PloneTestCase):
self.assertEquals(self.viewlet.get_commenter_home_url(m.getUserName()), self.assertEquals(self.viewlet.get_commenter_home_url(m.getUserName()),
'http://nohost/plone/author/portal_owner') 'http://nohost/plone/author/portal_owner')
def test_get_commenter_home_url_is_none(self):
self.failIf(self.viewlet.get_commenter_home_url())
def test_get_commenter_portrait(self): def test_get_commenter_portrait(self):
# Add a user with a member image # Add a user with a member image
@ -112,7 +135,12 @@ class TestCommentsViewlet(PloneTestCase):
portrait_url = self.viewlet.get_commenter_portrait('jim') portrait_url = self.viewlet.get_commenter_portrait('jim')
# Check if the correct member image URL is returned # Check if the correct member image URL is returned
self.assertEquals(portrait_url, 'http://nohost/plone/portal_memberdata/portraits/jim') self.assertEquals(portrait_url,
'http://nohost/plone/portal_memberdata/portraits/jim')
def test_get_commenter_portrait_is_none(self):
self.assertEquals(self.viewlet.get_commenter_portrait(),
'defaultUser.gif')
def test_get_commenter_portrait_without_userimage(self): def test_get_commenter_portrait_without_userimage(self):