plone.app.discussion/plone/app/discussion/tests/functional_test_comments.txt

309 lines
9.3 KiB
Plaintext
Raw Normal View History

======================
plone.app.discussion
======================
2012-01-09 16:43:54 +01:00
This is a functional test for the plone.app.discussion comments viewlet.
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
------------------------
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']
>>> 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
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)
>>> browser_member = Browser(app)
>>> browser_user = Browser(app)
Make sure we have a test user from the layer and it uses fancy characters:
>>> from Products.CMFCore.utils import getToolByName
>>> mtool = getToolByName(portal, 'portal_membership', None)
>>> jim_fullname = mtool.getMemberById('jim').getProperty('fullname')
>>> jim_fullname
'Jim Fult\xc3\xb8rn'
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
>>> import transaction
2012-01-09 16:43:54 +01:00
>>> transaction.commit()
Create a public page with comments allowed.
>>> browser.open(portal_url)
>>> browser.getLink(id='document').click()
>>> browser.getControl(name='form.widgets.IDublinCore.title').value = "Doc1"
>>> browser.getControl(name='form.widgets.IAllowDiscussion.allow_discussion:list').value = ['True']
>>> browser.getControl('Save').click()
>>> urldoc1 = browser.url
2012-01-09 16:43:54 +01:00
Make sure the document is published:
>>> browser.getLink("Publish").click()
>>> 'Published' in browser.contents
True
Check that the form has been properly submitted
>>> browser.url
'http://nohost/plone/doc1'
Comment Viewlet
---------------
2012-01-09 16:43:54 +01:00
Check that the old comments viewlet does not show up
2012-01-09 16:43:54 +01:00
>>> 'discussion_reply_form' in browser.contents
False
2012-01-09 16:43:54 +01: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
>>> 'formfield-form-widgets-comment-text' in browser.contents
True
Post a comment as admin
-----------------------
Login as admin.
>>> from plone.app.testing import setRoles
>>> from plone.app.testing import TEST_USER_NAME
>>> setRoles(portal, 'manager', ['Manager'])
Post a comment as admin.
2012-01-09 16:43:54 +01:00
>>> browser.getControl(name='form.widgets.text').value = "Comment from admin"
>>> submit = browser.getControl(name='form.buttons.comment')
2012-01-09 16:43:54 +01:00
>>> submit.click()
Check if comment has been added properly.
2012-01-09 16:43:54 +01:00
>>> '<a href="http://nohost/plone/author/admin">admin</a>' in browser.contents
True
2012-01-09 16:43:54 +01:00
>>> browser.contents
'...<a href="http://nohost/plone/author/admin">admin</a>...says:...'
2012-01-09 16:43:54 +01:00
>>> "Comment from admin" in browser.contents
True
Post a comment as user
----------------------
Login as user (without the 'Member' role).
>>> browser_user.open(portal_url + '/login_form')
>>> browser_user.getControl(name='__ac_name').value = 'johndoe'
>>> browser_user.getControl(name='__ac_password').value = 'secret'
>>> browser_user.getControl(name='submit').click()
2012-01-09 16:43:54 +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.
>>> 'form.widgets.text' in browser_user.contents
False
2012-01-09 16:43:54 +01:00
>>> 'form.buttons.comment' in browser_user.contents
False
Post a comment as member
------------------------
2012-01-09 16:43:54 +01:00
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'
>>> browser_member.getControl(name='submit').click()
Post a comment as user jim.
>>> 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()
Check if the comment has been added properly.
>>> browser_member.contents
'...<a href="http://nohost/plone/author/jim">Jim Fult\xc3\xb8rn</a>...says:...'
>>> "Comment from Jim" in browser_member.contents
True
Post a comment as anonymous user
--------------------------------
2012-01-09 16:43:54 +01:00
Login and post comment as Anonymous
>>> unprivileged_browser.open(urldoc1)
2012-01-09 16:43:54 +01:00
>>> 'Log in to add comments' in unprivileged_browser.contents
True
2012-01-09 16:43:54 +01:00
Enable anonymous comment
>>> 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'
>>> browser.getControl(name='submit').click()
2012-01-09 16:43:54 +01:00
>>> browser.open(portal_url+'/@@discussion-settings')
>>> browser.getControl(name='form.widgets.anonymous_comments:list').value = [True]
>>> browser.getControl(name='form.buttons.save').click()
>>> 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
>>> '<span>Anonymous</span>' in unprivileged_browser.contents
True
2012-01-09 16:43:54 +01:00
>>> 'says' in unprivileged_browser.contents
True
2012-01-09 16:43:54 +01:00
>>> 'This is an anonymous comment' in unprivileged_browser.contents
True
Make sure special characters work as well.
>>> unprivileged_browser.open(urldoc1)
>>> tarek_fullname = "Tarek Ziadé"
>>> unprivileged_browser.getControl(name='form.widgets.author_name').value = tarek_fullname
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an äüö comment"
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
>>> tarek_fullname in unprivileged_browser.contents
True
2012-01-09 16:43:54 +01:00
>>> 'says' in unprivileged_browser.contents
True
2012-01-09 16:43:54 +01: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]
Post a reply to an existing comment.
2012-01-09 16:43:54 +01: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
>>> 'replyTreeLevel1' in browser.contents
True
Post a comment with comment review workflow enabled
---------------------------------------------------
Enable the 'comment review workflow' for comments.
2012-01-09 16:43:54 +01: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.
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
True
Edit the content object after a comment has been posted
-------------------------------------------------------
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
(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'
>>> browser.getControl(name='submit').click()
2012-01-09 16:43:54 +01:00
Edit the content object.
>>> browser.open("http://nohost/plone/doc1/edit")
>>> browser.getControl(name='form.widgets.text').value = "Lorem ipsum"
>>> browser.getControl('Save').click()
Make sure the edit was successful.
2012-01-09 16:43:54 +01:00
>>> 'Lorem ipsum' in browser.contents
True