2010-10-06 15:52:11 +02:00
|
|
|
======================
|
|
|
|
plone.app.discussion
|
|
|
|
======================
|
|
|
|
|
2012-01-09 16:43:54 +01:00
|
|
|
This is a functional test for the plone.app.discussion comments viewlet.
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
We use zope.testbrowser to simulate browser interaction in order to show how
|
|
|
|
the plone.app.discussion commenting works.
|
|
|
|
|
|
|
|
|
2011-10-30 08:11:06 +01:00
|
|
|
Setting up and loggin in
|
|
|
|
------------------------
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
First we have to set up some things and login.
|
|
|
|
|
|
|
|
>>> app = layer['app']
|
|
|
|
>>> from plone.testing.z2 import Browser
|
|
|
|
>>> browser = Browser(app)
|
|
|
|
>>> browser.handleErrors = False
|
|
|
|
>>> browser.addHeader('Authorization', 'Basic admin:secret')
|
2012-01-09 16:43:54 +01:00
|
|
|
>>> portal = layer['portal']
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> portal_url = 'http://nohost/plone'
|
|
|
|
|
2012-01-09 16:43:54 +01:00
|
|
|
By default, only HTTP error codes (e.g. 500 Server Side Error) are shown when an
|
2010-10-06 15:52:11 +02:00
|
|
|
error occurs on the server. To see more details, set handleErrors to False:
|
|
|
|
|
|
|
|
>>> browser.handleErrors = False
|
|
|
|
|
|
|
|
We also keep another testbrowser handy for testing how tiles are rendered if
|
|
|
|
you're not logged in::
|
|
|
|
|
|
|
|
>>> unprivileged_browser = Browser(app)
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> browser_member = Browser(app)
|
|
|
|
>>> browser_user = Browser(app)
|
2014-03-03 15:12:16 +01:00
|
|
|
>>> browser_reviewer = Browser(app)
|
2010-10-22 12:14:07 +02:00
|
|
|
|
|
|
|
Make sure we have a test user from the layer and it uses fancy characters:
|
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> from Products.CMFCore.utils import getToolByName
|
2010-10-22 12:14:07 +02:00
|
|
|
>>> mtool = getToolByName(portal, 'portal_membership', None)
|
2011-04-14 23:30:32 +02:00
|
|
|
>>> jim_fullname = mtool.getMemberById('jim').getProperty('fullname')
|
|
|
|
>>> jim_fullname
|
2010-10-22 12:14:07 +02:00
|
|
|
'Jim Fult\xc3\xb8rn'
|
2010-10-06 15:52:11 +02:00
|
|
|
|
2010-12-14 18:58:46 +01:00
|
|
|
Enable commenting.
|
|
|
|
|
|
|
|
>>> from zope.component import queryUtility
|
|
|
|
>>> from plone.registry.interfaces import IRegistry
|
|
|
|
>>> from plone.app.discussion.interfaces import IDiscussionSettings
|
|
|
|
>>> registry = queryUtility(IRegistry)
|
|
|
|
>>> settings = registry.forInterface(IDiscussionSettings)
|
|
|
|
>>> settings.globally_enabled = True
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-12-14 18:58:46 +01:00
|
|
|
>>> import transaction
|
2012-01-09 16:43:54 +01:00
|
|
|
>>> transaction.commit()
|
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
Create a public page with comments allowed.
|
|
|
|
|
2015-03-10 05:51:45 +01:00
|
|
|
>>> browser.open(portal['doc1'].absolute_url() + '/edit')
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> browser.getControl(name='form.widgets.IDublinCore.title').value = "Doc1"
|
|
|
|
>>> browser.getControl(name='form.widgets.IAllowDiscussion.allow_discussion:list').value = ['True']
|
|
|
|
>>> browser.getControl('Save').click()
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> urldoc1 = browser.url
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2013-08-29 22:20:47 +02:00
|
|
|
Make sure the document is published:
|
|
|
|
|
|
|
|
>>> browser.getLink("Publish").click()
|
|
|
|
>>> 'Published' in browser.contents
|
|
|
|
True
|
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
Check that the form has been properly submitted
|
|
|
|
|
|
|
|
>>> browser.url
|
|
|
|
'http://nohost/plone/doc1'
|
|
|
|
|
|
|
|
|
|
|
|
Comment Viewlet
|
|
|
|
---------------
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
Check that the old comments viewlet does not show up
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> 'discussion_reply_form' in browser.contents
|
|
|
|
False
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
Check that the comment form/viewlet shows up
|
|
|
|
|
|
|
|
>>> 'formfield-form-widgets-in_reply_to' in browser.contents
|
|
|
|
True
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2012-07-12 17:28:12 +02:00
|
|
|
>>> 'formfield-form-widgets-comment-text' in browser.contents
|
2010-10-06 15:52:11 +02:00
|
|
|
True
|
|
|
|
|
|
|
|
|
|
|
|
Post a comment as admin
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
Login as admin.
|
|
|
|
|
|
|
|
>>> from plone.app.testing import setRoles
|
|
|
|
>>> from plone.app.testing import TEST_USER_NAME
|
2010-12-14 22:30:40 +01:00
|
|
|
>>> setRoles(portal, 'manager', ['Manager'])
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
Post a comment as admin.
|
|
|
|
|
2012-01-09 16:43:54 +01:00
|
|
|
>>> browser.getControl(name='form.widgets.text').value = "Comment from admin"
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> submit = browser.getControl(name='form.buttons.comment')
|
2012-01-09 16:43:54 +01:00
|
|
|
>>> submit.click()
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
Check if comment has been added properly.
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> '<a href="http://nohost/plone/author/admin">admin</a>' in browser.contents
|
|
|
|
True
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> browser.contents
|
|
|
|
'...<a href="http://nohost/plone/author/admin">admin</a>...says:...'
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> "Comment from admin" in browser.contents
|
|
|
|
True
|
2010-12-09 11:58:32 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
Post a comment as user
|
|
|
|
----------------------
|
|
|
|
|
2010-12-09 11:58:32 +01:00
|
|
|
Login as user (without the 'Member' role).
|
|
|
|
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> browser_user.open(portal_url + '/login_form')
|
|
|
|
>>> browser_user.getControl(name='__ac_name').value = 'johndoe'
|
|
|
|
>>> browser_user.getControl(name='__ac_password').value = 'secret'
|
2018-06-13 01:04:15 +02:00
|
|
|
>>> browser_user.getControl('Log in').click()
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-12-09 11:58:32 +01:00
|
|
|
Users without the 'Reply to item' permission will not see the comment form,
|
|
|
|
because they don't have the 'Reply to item' permission. By default, this
|
|
|
|
permission is only granted to the 'Member' role.
|
|
|
|
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> 'form.widgets.text' in browser_user.contents
|
2010-12-09 11:58:32 +01:00
|
|
|
False
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> 'form.buttons.comment' in browser_user.contents
|
2010-12-09 11:58:32 +01:00
|
|
|
False
|
|
|
|
|
|
|
|
|
|
|
|
Post a comment as member
|
|
|
|
------------------------
|
|
|
|
|
2012-01-09 16:43:54 +01:00
|
|
|
Login as user 'jim'.
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> browser_member.open(portal_url + '/login_form')
|
|
|
|
>>> browser_member.getControl(name='__ac_name').value = 'jim'
|
|
|
|
>>> browser_member.getControl(name='__ac_password').value = 'secret'
|
2018-06-13 01:04:15 +02:00
|
|
|
>>> browser_member.getControl('Log in').click()
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
Post a comment as user jim.
|
|
|
|
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> browser_member.open(urldoc1)
|
|
|
|
>>> browser_member.getControl(name='form.widgets.text').value = "Comment from Jim"
|
|
|
|
>>> submit = browser_member.getControl(name='form.buttons.comment')
|
2012-01-09 16:43:54 +01:00
|
|
|
>>> submit.click()
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
Check if the comment has been added properly.
|
|
|
|
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> browser_member.contents
|
2010-10-22 12:14:07 +02:00
|
|
|
'...<a href="http://nohost/plone/author/jim">Jim Fult\xc3\xb8rn</a>...says:...'
|
2010-10-06 15:52:11 +02:00
|
|
|
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> "Comment from Jim" in browser_member.contents
|
2010-10-06 15:52:11 +02:00
|
|
|
True
|
|
|
|
|
|
|
|
|
|
|
|
Post a comment as anonymous user
|
|
|
|
--------------------------------
|
2012-01-09 16:43:54 +01:00
|
|
|
|
|
|
|
Login and post comment as Anonymous
|
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> unprivileged_browser.open(urldoc1)
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> 'Log in to add comments' in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
|
2012-01-09 16:43:54 +01:00
|
|
|
Enable anonymous comment
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
>>> browser.open(portal_url + '/logout')
|
|
|
|
>>> browser.open(portal_url + '/login_form')
|
|
|
|
>>> browser.getControl(name='__ac_name').value = 'admin'
|
|
|
|
>>> browser.getControl(name='__ac_password').value = 'secret'
|
2018-06-13 01:04:15 +02:00
|
|
|
>>> browser.getControl('Log in').click()
|
2013-11-12 10:45:59 +01:00
|
|
|
>>> browser.open(portal_url+'/@@discussion-controlpanel')
|
2017-02-02 20:56:57 +01:00
|
|
|
>>> browser.getControl(name='form.widgets.anonymous_comments:list').value = 'selected'
|
2012-01-09 16:43:54 +01:00
|
|
|
>>> browser.getControl(name='form.buttons.save').click()
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> browser.open(portal_url + '/logout')
|
|
|
|
|
|
|
|
Now we can post an anonymous comment.
|
|
|
|
|
|
|
|
>>> unprivileged_browser.open(urldoc1)
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an anonymous comment"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> '<span>Anonymous</span>' in unprivileged_browser.contents
|
|
|
|
True
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> 'says' in unprivileged_browser.contents
|
|
|
|
True
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> 'This is an anonymous comment' in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
|
|
|
|
Make sure special characters work as well.
|
|
|
|
|
|
|
|
>>> unprivileged_browser.open(urldoc1)
|
2011-04-14 23:30:32 +02:00
|
|
|
>>> tarek_fullname = "Tarek Ziadé"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.author_name').value = tarek_fullname
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an äüö comment"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
|
|
|
|
|
2011-04-14 23:30:32 +02:00
|
|
|
>>> tarek_fullname in unprivileged_browser.contents
|
2010-10-06 15:52:11 +02:00
|
|
|
True
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> 'says' in unprivileged_browser.contents
|
|
|
|
True
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> 'This is an äüö comment' in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
|
|
|
|
|
|
|
|
Reply to an existing comment
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
Check that there is no existing direct reply to a comment.
|
|
|
|
|
|
|
|
>>> 'replyTreeLevel1' in browser.contents
|
|
|
|
False
|
|
|
|
|
|
|
|
Find a comment id to reply to.
|
|
|
|
|
|
|
|
>>> browser.open(urldoc1)
|
|
|
|
>>> import re
|
|
|
|
>>> comment_div = re.findall('<div.*?.class="comment.*?>', browser.contents)[0]
|
2012-11-04 17:18:46 +01:00
|
|
|
>>> id = re.findall('"([^"]*)"', comment_div)[1]
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
Post a reply to an existing comment.
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> browser.getControl(name='form.widgets.in_reply_to').value = id
|
|
|
|
>>> browser.getControl(name='form.widgets.text').value = "Reply comment"
|
|
|
|
>>> browser.getControl(name='form.buttons.comment').click()
|
|
|
|
|
|
|
|
Check that the reply has been posted properly.
|
|
|
|
|
|
|
|
>>> 'Reply comment' in browser.contents
|
|
|
|
True
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> 'replyTreeLevel1' in browser.contents
|
|
|
|
True
|
|
|
|
|
|
|
|
|
2013-09-17 14:03:46 +02:00
|
|
|
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.
|
|
|
|
|
2015-11-23 01:05:21 +01:00
|
|
|
>>> browser.open(portal_url + '/@@overview-controlpanel')
|
2013-09-17 14:03:46 +02:00
|
|
|
>>> 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)
|
2020-02-11 18:49:57 +01:00
|
|
|
>>> url = browser.getLink(url='@@edit-comment').url
|
2015-05-31 02:28:22 +02:00
|
|
|
>>> '@@edit-comment' in url
|
2013-09-17 14:03:46 +02:00
|
|
|
True
|
|
|
|
|
|
|
|
Open the edit comment view
|
|
|
|
|
2015-05-31 02:28:22 +02:00
|
|
|
>>> browser.open(url)
|
2013-09-17 14:03:46 +02:00
|
|
|
>>> ctrl = browser.getControl('Comment')
|
|
|
|
>>> ctrl.value
|
|
|
|
'Comment from admin'
|
|
|
|
|
|
|
|
Change and save the comment
|
|
|
|
|
|
|
|
>>> ctrl.value = 'Comment from admin / was edited'
|
2020-01-16 15:32:46 +01:00
|
|
|
>>> browser.getControl('Save').click()
|
2013-09-17 14:03:46 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2020-02-11 18:49:57 +01:00
|
|
|
>>> url = browser.getLink(url='@@edit-comment').url
|
2015-05-31 02:28:22 +02:00
|
|
|
>>> '@@edit-comment' in url
|
2013-09-17 14:03:46 +02:00
|
|
|
True
|
2015-05-31 02:28:22 +02:00
|
|
|
>>> browser.open(url)
|
2013-09-17 14:03:46 +02:00
|
|
|
>>> 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
|
|
|
|
|
|
|
|
|
2014-03-03 15:12:16 +01:00
|
|
|
Deleting existing comments | 'Delete comments' permission
|
|
|
|
----------------------------------------------------------
|
2013-09-19 10:39:52 +02:00
|
|
|
|
|
|
|
Anonymous cannot delete comments
|
|
|
|
|
|
|
|
>>> unprivileged_browser.open(urldoc1)
|
2019-12-05 21:55:23 +01:00
|
|
|
>>> 'form.button.DeleteComment' in unprivileged_browser.contents
|
2013-09-19 10:39:52 +02:00
|
|
|
False
|
|
|
|
|
2014-03-03 15:12:16 +01:00
|
|
|
A member cannot delete his own comments if he can't review or he isn't a Site Administrator
|
2013-09-19 10:39:52 +02:00
|
|
|
|
|
|
|
>>> browser_member.open(urldoc1)
|
2019-12-05 21:55:23 +01:00
|
|
|
>>> 'form.button.DeleteComment' in browser_member.contents
|
2013-09-19 10:39:52 +02:00
|
|
|
False
|
|
|
|
|
|
|
|
Admin can delete comments
|
|
|
|
|
|
|
|
>>> browser.open(urldoc1)
|
2019-12-05 21:55:23 +01:00
|
|
|
>>> 'form.button.DeleteComment' in browser.contents
|
2013-09-19 10:39:52 +02:00
|
|
|
True
|
|
|
|
|
|
|
|
Extract the delete comment url from the first "delete comment" button
|
|
|
|
|
|
|
|
>>> browser.open(urldoc1)
|
|
|
|
>>> form = browser.getForm(name='delete', index=0)
|
|
|
|
>>> delete_url = form.action
|
|
|
|
>>> '@@moderate-delete-comment' in delete_url
|
|
|
|
True
|
|
|
|
>>> comment_id = delete_url.split('/')[-2]
|
|
|
|
|
|
|
|
Anonymous cannot delete a comment by hitting the delete url directly.
|
|
|
|
|
|
|
|
>>> unprivileged_browser.open(delete_url)
|
|
|
|
|
|
|
|
The comment is still there
|
|
|
|
|
|
|
|
>>> unprivileged_browser.open(urldoc1)
|
|
|
|
>>> comment_id in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
|
|
|
|
A Member cannot delete even his own comment by hitting the delete url directly.
|
|
|
|
|
|
|
|
Extract the member comment id from the admin browser
|
|
|
|
|
|
|
|
>>> form = browser.getForm(name='delete', index=2)
|
|
|
|
>>> delete_url = form.action
|
|
|
|
>>> '@@moderate-delete-comment' in delete_url
|
|
|
|
True
|
|
|
|
>>> comment_id = delete_url.split('/')[-2]
|
|
|
|
|
|
|
|
Now try to hit that url as the member owning that comment.
|
|
|
|
Work around some possible testbrowser breakage and check the result later.
|
|
|
|
|
|
|
|
>>> try:
|
|
|
|
... browser_member.open(delete_url)
|
|
|
|
... except:
|
|
|
|
... pass
|
|
|
|
|
|
|
|
The comment is still there
|
|
|
|
|
|
|
|
>>> browser_member.open(urldoc1)
|
|
|
|
>>> comment_id in browser_member.contents
|
|
|
|
True
|
|
|
|
>>> 'Comment from Jim' in browser_member.contents
|
|
|
|
True
|
|
|
|
|
2014-03-03 15:12:16 +01:00
|
|
|
Now login as user 'reviewer'
|
2013-09-19 10:39:52 +02:00
|
|
|
|
2014-03-03 15:12:16 +01:00
|
|
|
>>> browser_reviewer.open(portal_url + '/login_form')
|
|
|
|
>>> browser_reviewer.getControl(name='__ac_name').value = 'reviewer'
|
|
|
|
>>> browser_reviewer.getControl(name='__ac_password').value = 'secret'
|
2018-06-13 01:04:15 +02:00
|
|
|
>>> browser_reviewer.getControl('Log in').click()
|
2013-09-19 10:39:52 +02:00
|
|
|
|
2014-03-03 15:12:16 +01:00
|
|
|
Admin and who have 'Delete comments' permission (reviewers for example), can delete comments
|
2013-09-19 10:39:52 +02:00
|
|
|
|
2014-03-03 15:12:16 +01:00
|
|
|
>>> browser_reviewer.open(urldoc1)
|
|
|
|
>>> form = browser_reviewer.getForm(name='delete', index=0)
|
2013-09-19 10:39:52 +02:00
|
|
|
>>> '@@moderate-delete-comment' in form.action
|
|
|
|
True
|
|
|
|
|
|
|
|
>>> comment_id = form.action.split('/')[-2]
|
|
|
|
|
|
|
|
Submitting the form runs into a testbrowser notFoundException.
|
|
|
|
We'll just catch that and check the result later.
|
|
|
|
|
|
|
|
>>> try:
|
2014-08-23 00:31:28 +02:00
|
|
|
... form.submit()
|
2013-09-19 10:39:52 +02:00
|
|
|
... except:
|
|
|
|
... pass
|
|
|
|
|
|
|
|
Returning to the document we find the deleted comment is indeed gone
|
|
|
|
|
2014-03-03 15:12:16 +01:00
|
|
|
>>> browser_reviewer.open(urldoc1)
|
|
|
|
>>> comment_id in browser_reviewer.contents
|
2013-09-19 10:39:52 +02:00
|
|
|
False
|
|
|
|
|
2013-09-17 14:03:46 +02:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
Post a comment with comment review workflow enabled
|
|
|
|
---------------------------------------------------
|
|
|
|
|
|
|
|
Enable the 'comment review workflow' for comments.
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('comment_review_workflow'),)
|
|
|
|
>>> portal.portal_workflow.getChainForPortalType('Discussion Item')
|
|
|
|
('comment_review_workflow',)
|
|
|
|
|
|
|
|
We need to commit the transaction, otherwise setting the workflow will not work.
|
|
|
|
|
|
|
|
>>> import transaction
|
|
|
|
>>> transaction.commit()
|
|
|
|
|
|
|
|
Post comment as anonymous user.
|
|
|
|
|
|
|
|
>>> unprivileged_browser.open(urldoc1)
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "Comment review workflow comment"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
|
|
|
|
|
|
|
|
Make sure the comment has not been published.
|
|
|
|
|
|
|
|
>>> 'Comment review workflow comment' not in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
|
2012-01-09 16:43:54 +01:00
|
|
|
Make sure the user gets a notification that the comment awaits moderator
|
|
|
|
approval.
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
|
|
|
|
|
2011-04-14 18:41:11 +02:00
|
|
|
Edit the content object after a comment has been posted
|
|
|
|
-------------------------------------------------------
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
Make sure we still can edit the content object after a comment has been posted.
|
2012-01-09 16:43:54 +01:00
|
|
|
This is a regression test for http://dev.plone.org/plone/ticket/11157
|
2010-10-06 15:52:11 +02:00
|
|
|
(TypeError: Can't pickle objects in acquisition wrappers).
|
|
|
|
|
|
|
|
Login as admin.
|
|
|
|
|
|
|
|
>>> browser.open(portal_url + '/login_form')
|
|
|
|
>>> browser.getControl(name='__ac_name').value = 'admin'
|
|
|
|
>>> browser.getControl(name='__ac_password').value = 'secret'
|
2018-06-13 01:04:15 +02:00
|
|
|
>>> browser.getControl('Log in').click()
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
Edit the content object.
|
|
|
|
|
2015-05-08 19:06:29 +02:00
|
|
|
>>> from plone.protect.authenticator import _getKeyring
|
|
|
|
>>> import hmac
|
|
|
|
>>> from hashlib import sha1 as sha
|
|
|
|
>>> ring = _getKeyring('foo')
|
|
|
|
>>> secret = ring.random()
|
2018-06-12 14:25:01 +02:00
|
|
|
>>> token = hmac.new(secret.encode('utf8'), b'admin', sha).hexdigest()
|
2015-05-08 19:06:29 +02:00
|
|
|
>>> browser.open("http://nohost/plone/doc1/edit?_authenticator=" + token)
|
2018-06-18 17:04:41 +02:00
|
|
|
>>> browser.getControl(name='form.widgets.IRichTextBehavior.text').value = "Lorem ipsum"
|
2013-08-29 22:20:47 +02:00
|
|
|
>>> browser.getControl('Save').click()
|
2010-10-06 15:52:11 +02:00
|
|
|
|
|
|
|
Make sure the edit was successful.
|
2012-01-09 16:43:54 +01:00
|
|
|
|
2010-10-06 15:52:11 +02:00
|
|
|
>>> 'Lorem ipsum' in browser.contents
|
|
|
|
True
|
2016-06-09 19:26:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
Require anonymous email
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
Edit the control panel.
|
|
|
|
|
|
|
|
>>> browser.open(portal_url + '/logout')
|
|
|
|
>>> browser.open(portal_url + '/login_form')
|
|
|
|
>>> browser.getControl(name='__ac_name').value = 'admin'
|
|
|
|
>>> browser.getControl(name='__ac_password').value = 'secret'
|
2018-06-13 01:04:15 +02:00
|
|
|
>>> browser.getControl('Log in').click()
|
2016-06-09 19:26:06 +02:00
|
|
|
>>> browser.open(portal_url+'/@@discussion-controlpanel')
|
2017-02-02 20:56:57 +01:00
|
|
|
>>> browser.getControl(name='form.widgets.anonymous_email_enabled:list').value = 'selected'
|
2016-06-09 19:26:06 +02:00
|
|
|
>>> browser.getControl(name='form.buttons.save').click()
|
|
|
|
>>> browser.open(portal_url + '/logout')
|
|
|
|
|
|
|
|
Post an anonymous comment without setting the email.
|
|
|
|
|
|
|
|
>>> unprivileged_browser.open(urldoc1)
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an anonymous comment without email"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
|
|
|
|
>>> 'Required input is missing' in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
|
|
|
|
Try again.
|
|
|
|
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an anonymous comment with email"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.author_email').value = "email@example.org"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
|
|
|
|
>>> 'Required input missing' in unprivileged_browser.contents
|
|
|
|
False
|
|
|
|
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
|
2017-06-20 15:16:19 +02:00
|
|
|
Email is being validated.
|
|
|
|
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an anonymous comment with email"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.author_email').value = "abc"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
|
|
|
|
>>> 'Invalid email address.' in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
|
|
|
|
False
|
|
|
|
|
|
|
|
Check again with valid email.
|
|
|
|
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an anonymous comment with email"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.widgets.author_email').value = "email@example.org"
|
|
|
|
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
|
|
|
|
>>> 'Invalid email address.' in unprivileged_browser.contents
|
|
|
|
False
|
|
|
|
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
|
|
|
|
True
|
|
|
|
|
|
|
|
|
2016-06-09 19:26:06 +02:00
|
|
|
Posting as member should still work. Especially it should not
|
|
|
|
complain about missing input for an invisible author_email field.
|
|
|
|
Login as user 'jim'.
|
|
|
|
|
|
|
|
>>> browser_member.open(portal_url + '/login_form')
|
|
|
|
>>> browser_member.getControl(name='__ac_name').value = 'jim'
|
|
|
|
>>> browser_member.getControl(name='__ac_password').value = 'secret'
|
2018-06-13 01:04:15 +02:00
|
|
|
>>> browser_member.getControl('Log in').click()
|
2016-06-09 19:26:06 +02:00
|
|
|
|
|
|
|
Post a comment as user jim.
|
|
|
|
|
|
|
|
>>> browser_member.open(urldoc1)
|
|
|
|
>>> browser_member.getControl(name='form.widgets.text').value = "Use the ZODB, Luke!"
|
|
|
|
>>> submit = browser_member.getControl(name='form.buttons.comment')
|
|
|
|
>>> submit.click()
|
|
|
|
|
|
|
|
Check if there are no validation errors.
|
|
|
|
|
|
|
|
>>> 'Required input missing' in browser_member.contents
|
|
|
|
False
|
|
|
|
>>> 'Your comment awaits moderator approval' in browser_member.contents
|
|
|
|
True
|