Make comments editable
This commit is contained in:
@@ -250,6 +250,77 @@ Check that the reply has been posted properly.
|
||||
True
|
||||
|
||||
|
||||
Edit an existing comment
|
||||
------------------------
|
||||
|
||||
Log in as admin
|
||||
|
||||
>>> browser.getLink('Log out').click()
|
||||
>>> browser.open(portal_url + '/login_form')
|
||||
>>> browser.getControl('Login Name').value = 'admin'
|
||||
>>> browser.getControl('Password').value = 'secret'
|
||||
>>> browser.getControl('Log in').click()
|
||||
|
||||
Use the Plone control panel to enable comment editing.
|
||||
|
||||
>>> browser.open(portal_url + '/plone_control_panel')
|
||||
>>> browser.getLink('Discussion').click()
|
||||
>>> browser.getControl('Enable editing of comments').selected = True
|
||||
>>> browser.getControl(name='form.buttons.save').click()
|
||||
|
||||
Extract the edit comment url from the first "edit comment" button
|
||||
|
||||
>>> browser.open(urldoc1)
|
||||
>>> form = browser.getForm(name='edit', index=0)
|
||||
>>> '@@edit-comment' in form.action
|
||||
True
|
||||
|
||||
Open the edit comment view
|
||||
|
||||
>>> browser.open(form.action)
|
||||
>>> ctrl = browser.getControl('Comment')
|
||||
>>> ctrl.value
|
||||
'Comment from admin'
|
||||
|
||||
Change and save the comment
|
||||
|
||||
>>> ctrl.value = 'Comment from admin / was edited'
|
||||
>>> browser.getControl('Edit comment').click()
|
||||
|
||||
This used to trigger permissions problems in some portlet configurations.
|
||||
Check it ain't so.
|
||||
|
||||
>>> 'require_login' in browser.url
|
||||
False
|
||||
>>> browser.url.startswith('http://nohost/plone/doc1')
|
||||
True
|
||||
>>> 'Comment from admin / was edited' in browser.contents
|
||||
True
|
||||
|
||||
Opening the edit comment view, then cancel, does nothing.
|
||||
|
||||
>>> form = browser.getForm(name='edit', index=0)
|
||||
>>> '@@edit-comment' in form.action
|
||||
True
|
||||
>>> browser.open(form.action)
|
||||
>>> browser.getControl('Cancel').click()
|
||||
>>> browser.url.startswith('http://nohost/plone/doc1')
|
||||
True
|
||||
|
||||
|
||||
Anon cannot edit comments.
|
||||
|
||||
>>> unprivileged_browser.open(urldoc1)
|
||||
>>> '@@edit-comments' in browser.contents
|
||||
False
|
||||
|
||||
But Anon can see the edited comment.
|
||||
|
||||
>>> 'Comment from admin / was edited' in unprivileged_browser.contents
|
||||
True
|
||||
|
||||
|
||||
|
||||
Post a comment with comment review workflow enabled
|
||||
---------------------------------------------------
|
||||
|
||||
|
||||
@@ -130,6 +130,16 @@ class CommentTest(unittest.TestCase):
|
||||
comment1.creator = "jim"
|
||||
self.assertEqual("jim", comment1.Creator())
|
||||
|
||||
def test_creator_author_name(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.author_name = "joey"
|
||||
self.assertEqual("joey", comment1.Creator())
|
||||
|
||||
def test_owner(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
self.assertEqual((['plone', 'acl_users'], TEST_USER_ID),
|
||||
comment1.getOwnerTuple())
|
||||
|
||||
def test_type(self):
|
||||
comment1 = createObject('plone.Comment')
|
||||
self.assertEqual(comment1.Type(), 'Comment')
|
||||
|
||||
@@ -33,12 +33,14 @@ from plone.app.testing import login
|
||||
|
||||
from plone.app.discussion.browser.comments import CommentsViewlet
|
||||
from plone.app.discussion.browser.comments import CommentForm
|
||||
from plone.app.discussion.browser.comment import EditCommentForm
|
||||
from plone.app.discussion import interfaces
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.testing import (
|
||||
PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||
)
|
||||
from plone.app.discussion.interfaces import IDiscussionSettings
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
|
||||
|
||||
class TestCommentForm(unittest.TestCase):
|
||||
@@ -125,6 +127,65 @@ class TestCommentForm(unittest.TestCase):
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertFalse(commentForm.handleComment(commentForm, "foo"))
|
||||
|
||||
def test_edit_comment(self):
|
||||
"""Edit a comment as logged-in user.
|
||||
"""
|
||||
|
||||
# Allow discussion
|
||||
self.discussionTool.overrideDiscussionFor(self.portal.doc1, True)
|
||||
self.viewlet = CommentsViewlet(self.context, self.request, None, None)
|
||||
|
||||
def make_request(form={}):
|
||||
request = TestRequest()
|
||||
request.form.update(form)
|
||||
alsoProvides(request, IFormLayer)
|
||||
alsoProvides(request, IAttributeAnnotatable)
|
||||
return request
|
||||
|
||||
provideAdapter(
|
||||
adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=CommentForm,
|
||||
name=u"comment-form"
|
||||
)
|
||||
|
||||
provideAdapter(
|
||||
adapts=(Interface, IBrowserRequest),
|
||||
provides=Interface,
|
||||
factory=EditCommentForm,
|
||||
name=u"edit-comment-form"
|
||||
)
|
||||
|
||||
# The form is submitted successfully, if the required text field is
|
||||
# filled out
|
||||
request = make_request(form={'form.widgets.text': u'bar'})
|
||||
|
||||
commentForm = getMultiAdapter(
|
||||
(self.context, request),
|
||||
name=u"comment-form"
|
||||
)
|
||||
commentForm.update()
|
||||
data, errors = commentForm.extractData() # pylint: disable-msg=W0612
|
||||
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertFalse(commentForm.handleComment(commentForm, "foo"))
|
||||
|
||||
# Edit the last comment
|
||||
conversation = IConversation(self.context)
|
||||
comment = [x for x in conversation.getComments()][-1]
|
||||
request = make_request(form={'form.widgets.text': u'foobar'})
|
||||
editForm = getMultiAdapter(
|
||||
(comment, request),
|
||||
name=u"edit-comment-form"
|
||||
)
|
||||
editForm.update()
|
||||
data, errors = editForm.extractData() # pylint: disable-msg=W0612
|
||||
|
||||
self.assertEqual(len(errors), 0)
|
||||
self.assertFalse(editForm.handleComment(editForm, "foo"))
|
||||
comment = [x for x in conversation.getComments()][-1]
|
||||
self.assertEquals(comment.text, u"foobar")
|
||||
|
||||
def test_add_anonymous_comment(self):
|
||||
self.discussionTool.overrideDiscussionFor(self.portal.doc1, True)
|
||||
|
||||
@@ -459,9 +520,11 @@ class TestCommentsViewlet(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_get_commenter_portrait_is_none(self):
|
||||
self.assertEqual(
|
||||
self.viewlet.get_commenter_portrait(),
|
||||
'defaultUser.gif'
|
||||
self.assertTrue(
|
||||
self.viewlet.get_commenter_portrait() in (
|
||||
'defaultUser.png',
|
||||
'defaultUser.gif',
|
||||
)
|
||||
)
|
||||
|
||||
def test_get_commenter_portrait_without_userimage(self):
|
||||
|
||||
@@ -81,6 +81,22 @@ class RegistryTest(unittest.TestCase):
|
||||
False
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
def test_text_transform(self):
|
||||
self.assertTrue('text_transform' in IDiscussionSettings)
|
||||
self.assertEqual(
|
||||
|
||||
Reference in New Issue
Block a user