plone.app.discussion/plone/app/discussion/tests/test_controlpanel.py

232 lines
7.9 KiB
Python
Raw Normal View History

from plone.app.discussion.interfaces import IDiscussionSettings
2022-05-01 23:14:00 +02:00
from plone.app.discussion.testing import ( # noqa
PLONE_APP_DISCUSSION_INTEGRATION_TESTING,
)
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.registry import Registry
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from zope.component import getMultiAdapter
from zope.component import queryUtility
import unittest
class RegistryTest(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
def setUp(self):
2022-05-01 23:14:09 +02:00
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.registry = Registry()
self.registry.registerInterface(IDiscussionSettings)
def test_registry_registered(self):
registry = queryUtility(IRegistry)
self.assertTrue(registry.forInterface(IDiscussionSettings))
def test_discussion_controlpanel_view(self):
2013-04-17 19:27:30 +02:00
view = getMultiAdapter(
(self.portal, self.portal.REQUEST),
2022-05-01 23:14:09 +02:00
name="discussion-controlpanel",
2013-04-17 19:27:30 +02:00
)
self.assertTrue(view())
def test_discussion_in_controlpanel(self):
# Check if discussion is in the control panel
2022-05-01 23:14:09 +02:00
self.controlpanel = getToolByName(self.portal, "portal_controlpanel")
2013-04-17 19:27:30 +02:00
self.assertTrue(
2022-05-01 23:14:09 +02:00
"discussion"
in [a.getAction(self)["id"] for a in self.controlpanel.listActions()],
2013-04-17 19:27:30 +02:00
)
def test_globally_enabled(self):
# Check globally_enabled record
2022-05-01 23:14:09 +02:00
self.assertTrue("globally_enabled" in IDiscussionSettings)
self.assertEqual(
2013-04-17 19:27:30 +02:00
self.registry[
2022-05-01 23:14:09 +02:00
"plone.app.discussion.interfaces."
+ "IDiscussionSettings.globally_enabled"
2013-04-17 19:27:30 +02:00
],
False,
2013-04-17 19:27:30 +02:00
)
def test_anonymous_comments(self):
# Check anonymous_comments record
2022-05-01 23:14:09 +02:00
self.assertTrue("anonymous_comments" in IDiscussionSettings)
2013-04-17 19:27:30 +02:00
self.assertEqual(
self.registry[
2022-05-01 23:14:09 +02:00
"plone.app.discussion.interfaces."
+ "IDiscussionSettings.anonymous_comments"
2013-04-17 19:27:30 +02:00
],
False,
2013-04-17 19:27:30 +02:00
)
def test_moderation_enabled(self):
# Check globally_enabled record
2022-05-01 23:14:09 +02:00
self.assertTrue("moderation_enabled" in IDiscussionSettings)
self.assertEqual(
2013-04-17 19:27:30 +02:00
self.registry[
2022-05-01 23:14:09 +02:00
"plone.app.discussion.interfaces."
+ "IDiscussionSettings.moderation_enabled"
2013-04-17 19:27:30 +02:00
],
False,
2013-04-17 19:27:30 +02:00
)
2013-09-17 14:03:46 +02:00
def test_edit_comment_enabled(self):
# Check edit_comment_enabled record
2022-05-01 23:14:09 +02:00
self.assertTrue("edit_comment_enabled" in IDiscussionSettings)
2013-09-17 14:03:46 +02:00
self.assertEqual(
2022-05-01 23:14:09 +02:00
self.registry[
"plone.app.discussion.interfaces."
+ "IDiscussionSettings.edit_comment_enabled"
],
False,
)
2013-09-17 14:03:46 +02:00
def test_delete_own_comment_enabled(self):
# Check delete_own_comment_enabled record
2022-05-01 23:14:09 +02:00
self.assertTrue("delete_own_comment_enabled" in IDiscussionSettings)
2013-09-17 14:03:46 +02:00
self.assertEqual(
2022-05-01 23:14:09 +02:00
self.registry[
"plone.app.discussion.interfaces."
+ "IDiscussionSettings.delete_own_comment_enabled"
],
False,
)
2013-09-17 14:03:46 +02:00
def test_text_transform(self):
2022-05-01 23:14:09 +02:00
self.assertTrue("text_transform" in IDiscussionSettings)
self.assertEqual(
2013-04-17 19:27:30 +02:00
self.registry[
2022-05-01 23:14:09 +02:00
"plone.app.discussion.interfaces."
+ "IDiscussionSettings.text_transform"
2013-04-17 19:27:30 +02:00
],
2022-05-01 23:14:09 +02:00
"text/plain",
2013-04-17 19:27:30 +02:00
)
def test_captcha(self):
# Check globally_enabled record
2022-05-01 23:14:09 +02:00
self.assertTrue("captcha" in IDiscussionSettings)
2013-04-17 19:27:30 +02:00
self.assertEqual(
self.registry[
2022-05-01 23:14:09 +02:00
"plone.app.discussion.interfaces." + "IDiscussionSettings.captcha"
2013-04-17 19:27:30 +02:00
],
2022-05-01 23:14:09 +02:00
"disabled",
2013-04-17 19:27:30 +02:00
)
def test_show_commenter_image(self):
# Check show_commenter_image record
2022-05-01 23:14:09 +02:00
self.assertTrue("show_commenter_image" in IDiscussionSettings)
2013-04-17 19:27:30 +02:00
self.assertEqual(
self.registry[
2022-05-01 23:14:09 +02:00
"plone.app.discussion.interfaces."
+ "IDiscussionSettings.show_commenter_image"
2013-04-17 19:27:30 +02:00
],
True,
2013-04-17 19:27:30 +02:00
)
def test_moderator_notification_enabled(self):
# Check show_commenter_image record
2013-04-17 19:27:30 +02:00
self.assertTrue(
2022-05-01 23:14:09 +02:00
"moderator_notification_enabled" in IDiscussionSettings,
2013-04-17 19:27:30 +02:00
)
self.assertEqual(
self.registry[
2022-05-01 23:14:09 +02:00
"plone.app.discussion.interfaces."
+ "IDiscussionSettings.moderator_notification_enabled"
2013-04-17 19:27:30 +02:00
],
False,
2013-04-17 19:27:30 +02:00
)
2015-05-13 14:03:11 +02:00
# def test_user_notification_enabled(self):
# # Check show_commenter_image record
# show_commenter_image = self.registry.records['plone.app.discussion.' +
# 'interfaces.IDiscussionSettings.user_notification_enabled']
#
# self.assertTrue('user_notification_enabled' in IDiscussionSettings)
# self.assertEqual(self.registry['plone.app.discussion.interfaces.' +
# 'IDiscussionSettings.user_notification_enabled'], False)
class ConfigurationChangedSubscriberTest(unittest.TestCase):
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
def setUp(self):
2022-05-01 23:14:09 +02:00
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
registry = queryUtility(IRegistry)
self.settings = registry.forInterface(IDiscussionSettings, check=False)
def test_moderation_enabled_in_discussion_control_panel_changed(self):
"""Make sure the 'Discussion Item' workflow is changed properly, when
2022-05-01 23:14:09 +02:00
the 'comment_moderation' setting in the discussion control panel
changes.
"""
2017-01-31 17:57:41 +01:00
# By default the comment_one_state_workflow without moderation is
2017-01-24 11:58:39 +01:00
# enabled
2013-04-17 19:27:30 +02:00
self.assertEqual(
2022-05-01 23:14:09 +02:00
("comment_one_state_workflow",),
2013-04-17 19:27:30 +02:00
self.portal.portal_workflow.getChainForPortalType(
2022-05-01 23:14:09 +02:00
"Discussion Item",
),
2013-04-17 19:27:30 +02:00
)
# Enable moderation in the discussion control panel
self.settings.moderation_enabled = True
# Make sure the comment_review_workflow with moderation enabled is
# enabled
2013-04-17 19:27:30 +02:00
self.assertEqual(
2022-05-01 23:14:09 +02:00
("comment_review_workflow",),
2013-04-17 19:27:30 +02:00
self.portal.portal_workflow.getChainForPortalType(
2022-05-01 23:14:09 +02:00
"Discussion Item",
),
2013-04-17 19:27:30 +02:00
)
# And back
self.settings.moderation_enabled = False
2013-04-17 19:27:30 +02:00
self.assertEqual(
2022-05-01 23:14:09 +02:00
("comment_one_state_workflow",),
2013-04-17 19:27:30 +02:00
self.portal.portal_workflow.getChainForPortalType(
2022-05-01 23:14:09 +02:00
"Discussion Item",
),
2013-04-17 19:27:30 +02:00
)
def test_change_workflow_in_types_control_panel(self):
"""Make sure the setting in the discussion control panel is changed
2022-05-01 23:14:09 +02:00
accordingly, when the workflow for the 'Discussion Item' changed in
the types control panel.
"""
# By default, moderation is disabled
self.settings.moderation_enabled = False
# Enable the 'comment_review_workflow' with moderation enabled
self.portal.portal_workflow.setChainForPortalTypes(
2022-05-01 23:14:09 +02:00
("Discussion Item",),
("comment_review_workflow",),
2013-04-17 19:27:30 +02: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(
2022-05-01 23:14:09 +02:00
("Discussion Item",),
("comment_one_state_workflow",),
2013-04-17 19:27:30 +02:00
)
self.settings.moderation_enabled = True
# Enable a 'custom' discussion workflow
self.portal.portal_workflow.setChainForPortalTypes(
2022-05-01 23:14:09 +02:00
("Discussion Item",),
("intranet_workflow",),
2013-04-17 19:27:30 +02:00
)
# Setting has not changed. A Custom workflow disables the
# enable_moderation checkbox in the discussion control panel. The
# setting itself remains unchanged.
self.settings.moderation_enabled = True