2010-08-25 16:03:29 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-05-03 08:16:39 +02:00
|
|
|
from plone.app.discussion.interfaces import IDiscussionSettings
|
2015-05-03 08:41:56 +02:00
|
|
|
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING # noqa
|
2015-05-03 08:16:39 +02:00
|
|
|
from plone.app.testing import setRoles
|
|
|
|
from plone.app.testing import TEST_USER_ID
|
2009-06-06 10:14:10 +02:00
|
|
|
from plone.registry import Registry
|
2010-08-29 00:58:23 +02:00
|
|
|
from plone.registry.interfaces import IRegistry
|
2009-06-06 10:14:10 +02:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
2015-05-03 08:16:39 +02:00
|
|
|
from zope.component import getMultiAdapter
|
|
|
|
from zope.component import queryUtility
|
2011-04-16 11:26:20 +02:00
|
|
|
|
2015-05-03 08:16:39 +02:00
|
|
|
import unittest2 as unittest
|
2009-06-06 10:14:10 +02:00
|
|
|
|
|
|
|
|
2011-04-16 11:26:20 +02:00
|
|
|
class RegistryTest(unittest.TestCase):
|
2009-06-06 10:14:10 +02:00
|
|
|
|
2011-04-16 11:26:20 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2009-06-06 10:14:10 +02:00
|
|
|
|
2011-04-16 11:26:20 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2009-06-06 10:14:10 +02:00
|
|
|
self.registry = Registry()
|
2009-07-13 12:22:45 +02:00
|
|
|
self.registry.registerInterface(IDiscussionSettings)
|
2009-06-06 10:14:10 +02:00
|
|
|
|
2010-08-29 00:58:23 +02:00
|
|
|
def test_registry_registered(self):
|
|
|
|
registry = queryUtility(IRegistry)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(registry.forInterface(IDiscussionSettings))
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-01-23 10:02:09 +01:00
|
|
|
def test_discussion_controlpanel_view(self):
|
2013-04-17 19:27:30 +02:00
|
|
|
view = getMultiAdapter(
|
|
|
|
(self.portal, self.portal.REQUEST),
|
2016-02-05 01:39:53 +01:00
|
|
|
name='discussion-controlpanel'
|
2013-04-17 19:27:30 +02:00
|
|
|
)
|
2010-01-23 10:02:09 +01:00
|
|
|
view = view.__of__(self.portal)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(view())
|
2010-01-23 10:02:09 +01:00
|
|
|
|
2009-06-06 10:14:10 +02:00
|
|
|
def test_discussion_in_controlpanel(self):
|
|
|
|
# Check if discussion is in the control panel
|
2016-02-05 01:39:53 +01:00
|
|
|
self.controlpanel = getToolByName(self.portal, 'portal_controlpanel')
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertTrue(
|
|
|
|
'discussion' in [
|
|
|
|
a.getAction(self)['id']
|
|
|
|
for a in self.controlpanel.listActions()
|
|
|
|
]
|
|
|
|
)
|
2009-06-06 10:14:10 +02:00
|
|
|
|
|
|
|
def test_globally_enabled(self):
|
|
|
|
# Check globally_enabled record
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('globally_enabled' in IDiscussionSettings)
|
|
|
|
self.assertEqual(
|
2013-04-17 19:27:30 +02:00
|
|
|
self.registry[
|
|
|
|
'plone.app.discussion.interfaces.' +
|
|
|
|
'IDiscussionSettings.globally_enabled'
|
|
|
|
],
|
|
|
|
False
|
|
|
|
)
|
2010-08-25 16:03:29 +02:00
|
|
|
|
2010-12-12 14:56:06 +01:00
|
|
|
def test_anonymous_comments(self):
|
|
|
|
# Check anonymous_comments record
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('anonymous_comments' in IDiscussionSettings)
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.registry[
|
|
|
|
'plone.app.discussion.interfaces.' +
|
|
|
|
'IDiscussionSettings.anonymous_comments'
|
|
|
|
],
|
|
|
|
False
|
|
|
|
)
|
2010-12-12 14:56:06 +01:00
|
|
|
|
|
|
|
def test_moderation_enabled(self):
|
|
|
|
# Check globally_enabled record
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('moderation_enabled' in IDiscussionSettings)
|
|
|
|
self.assertEqual(
|
2013-04-17 19:27:30 +02:00
|
|
|
self.registry[
|
|
|
|
'plone.app.discussion.interfaces.' +
|
|
|
|
'IDiscussionSettings.moderation_enabled'
|
|
|
|
],
|
|
|
|
False
|
|
|
|
)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2013-09-17 14:03:46 +02:00
|
|
|
def test_edit_comment_enabled(self):
|
|
|
|
# Check edit_comment_enabled record
|
|
|
|
self.assertTrue('edit_comment_enabled' in IDiscussionSettings)
|
|
|
|
self.assertEqual(
|
|
|
|
self.registry['plone.app.discussion.interfaces.' +
|
|
|
|
'IDiscussionSettings.edit_comment_enabled'],
|
|
|
|
False)
|
|
|
|
|
2014-09-20 16:02:48 +02:00
|
|
|
def test_delete_own_comment_enabled(self):
|
|
|
|
# Check delete_own_comment_enabled record
|
|
|
|
self.assertTrue('delete_own_comment_enabled' in IDiscussionSettings)
|
2013-09-17 14:03:46 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.registry['plone.app.discussion.interfaces.' +
|
2014-09-20 16:02:48 +02:00
|
|
|
'IDiscussionSettings.delete_own_comment_enabled'],
|
2013-09-17 14:03:46 +02:00
|
|
|
False)
|
|
|
|
|
2010-08-25 16:03:29 +02:00
|
|
|
def test_text_transform(self):
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('text_transform' in IDiscussionSettings)
|
|
|
|
self.assertEqual(
|
2013-04-17 19:27:30 +02:00
|
|
|
self.registry[
|
|
|
|
'plone.app.discussion.interfaces.' +
|
|
|
|
'IDiscussionSettings.text_transform'
|
|
|
|
],
|
|
|
|
'text/plain'
|
|
|
|
)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-08-11 11:45:34 +02:00
|
|
|
def test_captcha(self):
|
|
|
|
# Check globally_enabled record
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('captcha' in IDiscussionSettings)
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.registry[
|
|
|
|
'plone.app.discussion.interfaces.' +
|
|
|
|
'IDiscussionSettings.captcha'
|
|
|
|
],
|
|
|
|
'disabled'
|
|
|
|
)
|
2009-08-11 11:45:34 +02:00
|
|
|
|
2009-06-07 10:47:14 +02:00
|
|
|
def test_show_commenter_image(self):
|
|
|
|
# Check show_commenter_image record
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue('show_commenter_image' in IDiscussionSettings)
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.registry[
|
|
|
|
'plone.app.discussion.interfaces.' +
|
|
|
|
'IDiscussionSettings.show_commenter_image'
|
|
|
|
],
|
|
|
|
True
|
|
|
|
)
|
2009-06-07 10:47:14 +02:00
|
|
|
|
2010-02-12 11:11:01 +01:00
|
|
|
def test_moderator_notification_enabled(self):
|
|
|
|
# Check show_commenter_image record
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertTrue(
|
|
|
|
'moderator_notification_enabled' in IDiscussionSettings
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
self.registry[
|
|
|
|
'plone.app.discussion.interfaces.' +
|
|
|
|
'IDiscussionSettings.moderator_notification_enabled'
|
|
|
|
],
|
|
|
|
False
|
|
|
|
)
|
2010-02-12 11:11:01 +01:00
|
|
|
|
2015-05-13 14:03:11 +02:00
|
|
|
# def test_user_notification_enabled(self):
|
2010-03-11 20:23:26 +01:00
|
|
|
# # Check show_commenter_image record
|
2010-08-28 19:06:53 +02:00
|
|
|
# show_commenter_image = self.registry.records['plone.app.discussion.' +
|
|
|
|
# 'interfaces.IDiscussionSettings.user_notification_enabled']
|
2010-03-11 20:23:26 +01:00
|
|
|
#
|
2011-04-15 18:23:38 +02:00
|
|
|
# self.assertTrue('user_notification_enabled' in IDiscussionSettings)
|
|
|
|
# self.assertEqual(self.registry['plone.app.discussion.interfaces.' +
|
2010-08-28 19:06:53 +02:00
|
|
|
# 'IDiscussionSettings.user_notification_enabled'], False)
|
2010-02-08 19:28:03 +01:00
|
|
|
|
2010-12-11 18:18:14 +01:00
|
|
|
|
2011-04-16 11:26:20 +02:00
|
|
|
class ConfigurationChangedSubscriberTest(unittest.TestCase):
|
2010-12-11 18:18:14 +01:00
|
|
|
|
2011-04-16 11:26:20 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2010-12-11 18:18:14 +01:00
|
|
|
|
2011-04-16 11:26:20 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2010-12-12 14:56:06 +01:00
|
|
|
registry = queryUtility(IRegistry)
|
|
|
|
self.settings = registry.forInterface(IDiscussionSettings, check=False)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-12 14:56:06 +01:00
|
|
|
def test_moderation_enabled_in_discussion_control_panel_changed(self):
|
2010-12-16 00:52:56 +01:00
|
|
|
"""Make sure the 'Discussion Item' workflow is changed properly, when
|
|
|
|
the 'comment_moderation' setting in the discussion control panel
|
2010-12-12 14:56:06 +01:00
|
|
|
changes.
|
|
|
|
"""
|
|
|
|
# By default the one_state_workflow without moderation is enabled
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertEqual(
|
|
|
|
('one_state_workflow',),
|
|
|
|
self.portal.portal_workflow.getChainForPortalType(
|
|
|
|
'Discussion Item'
|
|
|
|
)
|
|
|
|
)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-12 14:56:06 +01:00
|
|
|
# Enable moderation in the discussion control panel
|
2010-12-16 00:52:56 +01:00
|
|
|
self.settings.moderation_enabled = True
|
|
|
|
|
2010-12-12 14:56:06 +01:00
|
|
|
# Make sure the comment_review_workflow with moderation enabled is
|
|
|
|
# enabled
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertEqual(
|
|
|
|
('comment_review_workflow',),
|
|
|
|
self.portal.portal_workflow.getChainForPortalType(
|
|
|
|
'Discussion Item'
|
|
|
|
)
|
|
|
|
)
|
2010-12-12 14:56:06 +01:00
|
|
|
# And back
|
|
|
|
self.settings.moderation_enabled = False
|
2013-04-17 19:27:30 +02:00
|
|
|
self.assertEqual(
|
|
|
|
('one_state_workflow',),
|
|
|
|
self.portal.portal_workflow.getChainForPortalType(
|
|
|
|
'Discussion Item'
|
|
|
|
)
|
|
|
|
)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-12 14:56:06 +01:00
|
|
|
def test_change_workflow_in_types_control_panel(self):
|
|
|
|
"""Make sure the setting in the discussion control panel is changed
|
2010-12-16 00:52:56 +01:00
|
|
|
accordingly, when the workflow for the 'Discussion Item' changed in
|
|
|
|
the types control panel.
|
2010-12-12 14:56:06 +01:00
|
|
|
"""
|
|
|
|
# By default, moderation is disabled
|
|
|
|
self.settings.moderation_enabled = False
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-12-12 14:56:06 +01:00
|
|
|
# Enable the 'comment_review_workflow' with moderation enabled
|
|
|
|
self.portal.portal_workflow.setChainForPortalTypes(
|
|
|
|
('Discussion Item',),
|
2013-04-17 19:27:30 +02:00
|
|
|
('comment_review_workflow',)
|
|
|
|
)
|
2010-12-12 14:56:06 +01:00
|
|
|
|
|
|
|
# Make sure the moderation_enabled settings has changed
|
|
|
|
self.settings.moderation_enabled = True
|
|
|
|
|
|
|
|
# Enable the 'comment_review_workflow' with moderation enabled
|
|
|
|
self.portal.portal_workflow.setChainForPortalTypes(
|
|
|
|
('Discussion Item',),
|
2013-04-17 19:27:30 +02:00
|
|
|
('one_state_workflow',)
|
|
|
|
)
|
2010-12-12 14:56:06 +01:00
|
|
|
self.settings.moderation_enabled = True
|
|
|
|
|
|
|
|
# Enable a 'custom' discussion workflow
|
|
|
|
self.portal.portal_workflow.setChainForPortalTypes(
|
|
|
|
('Discussion Item',),
|
2013-04-17 19:27:30 +02:00
|
|
|
('intranet_workflow',)
|
|
|
|
)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
|
|
|
# Setting has not changed. A Custom workflow disables the
|
2010-12-12 14:56:06 +01:00
|
|
|
# enable_moderation checkbox in the discussion control panel. The
|
|
|
|
# setting itself remains unchanged.
|
|
|
|
self.settings.moderation_enabled = True
|