2010-09-24 15:33:21 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-06-08 23:16:51 +02:00
|
|
|
import unittest
|
|
|
|
|
2009-06-18 22:57:47 +02:00
|
|
|
from zope.component import createObject
|
|
|
|
|
2009-06-10 22:17:36 +02:00
|
|
|
from zope.interface import alsoProvides
|
|
|
|
|
2009-10-17 15:50:55 +02:00
|
|
|
from AccessControl import Unauthorized
|
|
|
|
|
2010-09-24 15:33:21 +02:00
|
|
|
from Products.CMFCore.utils import _checkPermission as checkPerm
|
|
|
|
from Products.CMFCore.permissions import View
|
|
|
|
|
2009-06-08 23:16:51 +02:00
|
|
|
from Products.PloneTestCase.ptc import PloneTestCase
|
2009-06-10 22:17:36 +02:00
|
|
|
|
2009-06-08 23:16:51 +02:00
|
|
|
from plone.app.discussion.tests.layer import DiscussionLayer
|
2009-06-18 22:57:47 +02:00
|
|
|
from plone.app.discussion.interfaces import IConversation, IDiscussionLayer
|
2009-06-08 23:16:51 +02:00
|
|
|
|
|
|
|
|
2010-09-24 15:33:21 +02:00
|
|
|
class WorkflowSetupTest(PloneTestCase):
|
|
|
|
"""Make sure workflow and permissions are set up properly.
|
|
|
|
"""
|
2009-06-08 23:16:51 +02:00
|
|
|
|
2010-09-24 15:33:21 +02:00
|
|
|
layer = DiscussionLayer
|
|
|
|
|
2009-06-10 22:17:36 +02:00
|
|
|
def afterSetUp(self):
|
2010-09-24 15:33:21 +02:00
|
|
|
"""Create a document and allow discussion.
|
|
|
|
"""
|
2009-06-10 22:17:36 +02:00
|
|
|
self.portal.portal_types['Document'].allow_discussion = True
|
|
|
|
self.portal_discussion = self.portal.portal_discussion
|
|
|
|
self.folder.invokeFactory('Document', 'doc1')
|
2010-09-24 15:33:21 +02:00
|
|
|
self.doc = self.folder.doc1
|
|
|
|
|
|
|
|
def test_workflows_installed(self):
|
|
|
|
"""Make sure both comment workflows have been installed properly.
|
|
|
|
"""
|
|
|
|
self.failUnless('one_state_workflow' in
|
|
|
|
self.portal.portal_workflow.objectIds())
|
|
|
|
self.failUnless('comment_review_workflow' in
|
|
|
|
self.portal.portal_workflow.objectIds())
|
2009-06-10 22:17:36 +02:00
|
|
|
|
2010-09-24 15:33:21 +02:00
|
|
|
def test_default_workflow(self):
|
|
|
|
"""Make sure one_state_workflow is the default workflow.
|
|
|
|
"""
|
|
|
|
self.assertEquals(('one_state_workflow',),
|
|
|
|
self.portal.portal_workflow.getChainForPortalType(
|
|
|
|
'Discussion Item'))
|
|
|
|
|
|
|
|
def test_review_comments_permission(self):
|
|
|
|
#'Review comments' in self.portal.permissionsOfRole('Admin')
|
2009-06-10 22:17:36 +02:00
|
|
|
|
2009-06-08 23:16:51 +02:00
|
|
|
self.setRoles(('Reviewer',))
|
2010-08-28 19:06:53 +02:00
|
|
|
self.failUnless(self.portal.portal_membership.checkPermission(
|
|
|
|
'Review comments', self.folder), self.folder)
|
2009-06-08 23:16:51 +02:00
|
|
|
self.setRoles(('Member',))
|
2010-08-28 19:06:53 +02:00
|
|
|
self.failIf(self.portal.portal_membership.checkPermission(
|
|
|
|
'Review comments', self.folder), self.folder)
|
2009-06-08 23:16:51 +02:00
|
|
|
|
2010-09-24 15:33:21 +02:00
|
|
|
def test_reply_to_item_permission(self):
|
|
|
|
pass
|
2009-06-08 23:16:51 +02:00
|
|
|
|
2010-09-24 15:33:21 +02:00
|
|
|
|
|
|
|
class CommentOneStateWorkflowTest(PloneTestCase):
|
|
|
|
"""Test the one_state_workflow that ships with plone.app.discussion.
|
|
|
|
"""
|
2009-06-18 22:57:47 +02:00
|
|
|
|
2010-03-17 16:09:23 +01:00
|
|
|
layer = DiscussionLayer
|
|
|
|
|
2009-06-18 22:57:47 +02:00
|
|
|
def afterSetUp(self):
|
2010-09-24 15:33:21 +02:00
|
|
|
"""Create a document with comments and enable the one.
|
|
|
|
"""
|
|
|
|
self.catalog = self.portal.portal_catalog
|
|
|
|
self.workflow = self.portal.portal_workflow
|
|
|
|
self.workflow.setChainForPortalTypes(['Document'],
|
|
|
|
'one_state_workflow')
|
|
|
|
self.folder.invokeFactory('Document', 'doc1')
|
|
|
|
self.doc = self.folder.doc1
|
|
|
|
|
|
|
|
# Add a comment
|
|
|
|
conversation = IConversation(self.folder.doc1)
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.title = 'Comment 1'
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
cid = conversation.addComment(comment)
|
|
|
|
|
|
|
|
self.comment = self.folder.doc1.restrictedTraverse(\
|
|
|
|
'++conversation++default/%s' % cid)
|
|
|
|
|
|
|
|
self.portal.acl_users._doAddUser('member', 'secret', ['Member'], [])
|
|
|
|
self.portal.acl_users._doAddUser('reviewer', 'secret', ['Reviewer'], [])
|
|
|
|
self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], [])
|
|
|
|
self.portal.acl_users._doAddUser('editor' , ' secret', ['Editor'],[])
|
|
|
|
self.portal.acl_users._doAddUser('reader', 'secret', ['Reader'], [])
|
|
|
|
|
|
|
|
def test_initial_workflow_state(self):
|
|
|
|
"""Make sure the initial workflow state of a comment is 'published'.
|
|
|
|
"""
|
|
|
|
self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'),
|
|
|
|
'published')
|
|
|
|
|
|
|
|
def test_view_comments(self):
|
|
|
|
"""Make sure published comments can be viewed by everyone.
|
|
|
|
"""
|
|
|
|
# Owner is allowed
|
|
|
|
#self.login(default_user)
|
|
|
|
#self.failUnless(checkPerm(View, self.doc))
|
|
|
|
# Member is allowed
|
|
|
|
self.login('member')
|
|
|
|
self.failUnless(checkPerm(View, self.comment))
|
|
|
|
# Reviewer is allowed
|
|
|
|
self.login('reviewer')
|
|
|
|
self.failUnless(checkPerm(View, self.comment))
|
|
|
|
# Anonymous is allowed
|
|
|
|
self.logout()
|
|
|
|
self.failUnless(checkPerm(View, self.comment))
|
|
|
|
# Editor is allowed
|
|
|
|
self.login('editor')
|
|
|
|
self.failUnless(checkPerm(View, self.comment))
|
|
|
|
# Reader is allowed
|
|
|
|
self.login('reader')
|
|
|
|
self.failUnless(checkPerm(View, self.comment))
|
|
|
|
|
|
|
|
|
|
|
|
class CommentReviewWorkflowTest(PloneTestCase):
|
|
|
|
"""Test the comment_review_workflow that ships with plone.app.discussion.
|
|
|
|
"""
|
2009-06-18 22:57:47 +02:00
|
|
|
|
2010-09-24 15:33:21 +02:00
|
|
|
layer = DiscussionLayer
|
|
|
|
|
|
|
|
def afterSetUp(self):
|
|
|
|
# Allow discussion and
|
2009-06-18 22:57:47 +02:00
|
|
|
self.loginAsPortalOwner()
|
|
|
|
|
|
|
|
# Allow discussion on the Document content type
|
|
|
|
self.portal.portal_types['Document'].allow_discussion = True
|
|
|
|
# Set workflow for Discussion item to review workflow
|
2010-08-28 19:06:53 +02:00
|
|
|
self.portal.portal_workflow.setChainForPortalTypes(
|
|
|
|
('Discussion Item',),
|
|
|
|
('comment_review_workflow',))
|
2009-06-18 22:57:47 +02:00
|
|
|
|
|
|
|
# Create a Document
|
|
|
|
self.portal.invokeFactory('Document', 'doc1')
|
|
|
|
self.portal_discussion = self.portal.portal_discussion
|
|
|
|
|
|
|
|
# Create a conversation for this Document
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
|
|
|
|
# Add a comment.
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.title = 'Comment 1'
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
comment_id = conversation.addComment(comment)
|
2010-08-28 19:06:53 +02:00
|
|
|
comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % comment_id)
|
2009-06-18 22:57:47 +02:00
|
|
|
|
|
|
|
self.conversation = conversation
|
|
|
|
self.comment_id = comment_id
|
|
|
|
self.comment = comment
|
|
|
|
|
|
|
|
self.setRoles(('Reviewer',))
|
|
|
|
alsoProvides(self.portal.REQUEST, IDiscussionLayer)
|
|
|
|
|
|
|
|
def test_delete(self):
|
2009-10-17 15:50:55 +02:00
|
|
|
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
|
|
|
view = self.comment.restrictedTraverse('@@moderate-delete-comment')
|
|
|
|
view()
|
|
|
|
self.failIf(self.comment_id in self.conversation.objectIds())
|
|
|
|
|
|
|
|
def test_delete_as_anonymous(self):
|
|
|
|
# Make sure that anonymous users can not delete comments
|
|
|
|
self.logout()
|
|
|
|
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
|
|
|
self.assertRaises(Unauthorized,
|
|
|
|
self.comment.restrictedTraverse,
|
|
|
|
'@@moderate-delete-comment')
|
|
|
|
self.failUnless(self.comment_id in self.conversation.objectIds())
|
|
|
|
|
|
|
|
def test_delete_as_user(self):
|
|
|
|
# Make sure that members can not delete comments
|
|
|
|
self.logout()
|
|
|
|
self.setRoles(('Member',))
|
|
|
|
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
|
|
|
self.assertRaises(Unauthorized,
|
|
|
|
self.comment.restrictedTraverse,
|
|
|
|
'@@moderate-delete-comment')
|
|
|
|
self.failUnless(self.comment_id in self.conversation.objectIds())
|
2009-06-18 22:57:47 +02:00
|
|
|
|
|
|
|
def test_publish(self):
|
2009-10-17 15:50:55 +02:00
|
|
|
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
2009-10-17 18:14:44 +02:00
|
|
|
self.portal.REQUEST.form['workflow_action'] = 'publish'
|
2010-08-28 19:06:53 +02:00
|
|
|
self.assertEquals('pending',
|
|
|
|
self.portal.portal_workflow.getInfoFor(
|
|
|
|
self.comment, 'review_state'))
|
2009-10-17 15:50:55 +02:00
|
|
|
view = self.comment.restrictedTraverse('@@moderate-publish-comment')
|
|
|
|
view()
|
2010-08-28 19:06:53 +02:00
|
|
|
self.assertEquals('published', self.portal.portal_workflow.\
|
|
|
|
getInfoFor(self.comment, 'review_state'))
|
2009-10-17 15:50:55 +02:00
|
|
|
|
|
|
|
def test_publish_as_anonymous(self):
|
|
|
|
self.logout()
|
|
|
|
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
2009-10-17 18:14:44 +02:00
|
|
|
self.portal.REQUEST.form['workflow_action'] = 'publish'
|
2010-08-28 19:06:53 +02:00
|
|
|
self.assertEquals('pending', self.portal.portal_workflow.\
|
|
|
|
getInfoFor(self.comment, 'review_state'))
|
2009-10-17 15:50:55 +02:00
|
|
|
self.assertRaises(Unauthorized,
|
|
|
|
self.comment.restrictedTraverse,
|
|
|
|
'@@moderate-publish-comment')
|
2010-08-28 19:06:53 +02:00
|
|
|
self.assertEquals('pending', self.portal.portal_workflow.\
|
|
|
|
getInfoFor(self.comment, 'review_state'))
|
2009-06-18 22:57:47 +02:00
|
|
|
|
2009-06-08 23:16:51 +02:00
|
|
|
def test_suite():
|
2010-08-28 19:06:53 +02:00
|
|
|
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|