Comment form test added.

svn path=/plone.app.discussion/trunk/; revision=39608
This commit is contained in:
Timo Stollenwerk 2010-09-02 20:00:43 +00:00
parent d0914c072e
commit 81cba38a74
2 changed files with 64 additions and 25 deletions

View File

@ -10,6 +10,7 @@ from plone.app.discussion.tests.layer import DiscussionLayer
from plone.app.discussion.interfaces import IComment, IConversation, IReplies from plone.app.discussion.interfaces import IComment, IConversation, IReplies
class CommentTest(PloneTestCase): class CommentTest(PloneTestCase):
layer = DiscussionLayer layer = DiscussionLayer
@ -127,6 +128,7 @@ class CommentTest(PloneTestCase):
# TODO: is this correct? Redirect ist 301 # TODO: is this correct? Redirect ist 301
self.assertEquals(200, self.app.REQUEST.response.getStatus()) self.assertEquals(200, self.app.REQUEST.response.getStatus())
class RepliesTest(PloneTestCase): class RepliesTest(PloneTestCase):
# test the IReplies adapter on a comment # test the IReplies adapter on a comment

View File

@ -2,10 +2,24 @@
import unittest import unittest
from datetime import datetime from datetime import datetime
from Acquisition import Implicit
from zope.component import createObject, queryUtility from zope.component import createObject, queryUtility
from OFS.Image import Image from OFS.Image import Image
from zope.interface import alsoProvides
from zope.publisher.browser import TestRequest
from zope.annotation.interfaces import IAttributeAnnotatable
from z3c.form.interfaces import IFormLayer
from zope.component import provideAdapter
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.interface import Interface, implements
from zope.interface import Interface, implements
from zope.component import getMultiAdapter
from plone.registry.interfaces import IRegistry from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
@ -15,6 +29,7 @@ from Products.PloneTestCase.ptc import PloneTestCase
from Products.PloneTestCase.ptc import FunctionalTestCase from Products.PloneTestCase.ptc import FunctionalTestCase
from plone.app.discussion.browser.comments import CommentsViewlet from plone.app.discussion.browser.comments import CommentsViewlet
from plone.app.discussion.browser.comments import CommentForm
from plone.app.discussion.interfaces import IConversation from plone.app.discussion.interfaces import IConversation
from plone.app.discussion.tests.layer import DiscussionLayer from plone.app.discussion.tests.layer import DiscussionLayer
@ -32,34 +47,56 @@ class TestCommentForm(PloneTestCase):
None) None)
self.membership_tool = getToolByName(self.folder, 'portal_membership') self.membership_tool = getToolByName(self.folder, 'portal_membership')
self.memberdata = self.portal.portal_memberdata self.memberdata = self.portal.portal_memberdata
request = self.app.REQUEST self.request = self.app.REQUEST
context = getattr(self.portal, 'doc1') self.context = getattr(self.portal, 'doc1')
self.viewlet = CommentsViewlet(context, request, None, None) self.viewlet = CommentsViewlet(self.context, self.request, None, None)
def test_add_comment(self): def test_add_comment(self):
#form = CommentForm(self.viewlet, self.app.REQUEST)
#self.viewlet.form.render(form) def make_request(form={}):
#self.viewlet.form.handleComment() request = TestRequest()
#from z3c.form.testing import TestRequest request.form.update(form)
#request = TestRequest(form={ alsoProvides(request, IFormLayer)
# 'form.widgets.title': u'bar', alsoProvides(request, IAttributeAnnotatable)
# 'form.widgets.text': u'foo',} return request
#)
#cf = CommentForm(self.viewlet, request)
#cf.handleComments()
# Zope publisher uses Python list to mark <select> values
#self.portal.REQUEST["form.widgets.title"] = u"foo"
#self.portal.REQUEST["form.widgets.title"] = u"Search"
#view = self.portal.doc1.restrictedTraverse("@@view")
# Call update() for form
#view.process_form()
#self.viewlet.form.handleComment()
#print self.viewlet.form.render()
# Always check form errors after update() provideAdapter(adapts=(Interface, IBrowserRequest),
#errors = view.errors provides=Interface,
#self.assertEqual(len(errors), 0, "Got errors:" + str(errors)) factory=CommentForm,
pass name=u"comment-form")
class Comment(Implicit):
__allow_access_to_unprotected_subobjects__ = 1
implements(Interface)
context = Comment()
request = make_request(form={})
commentForm = getMultiAdapter((self.context, request), name=u"comment-form")
commentForm.update()
data, errors = commentForm.extractData()
self.assertEquals(len(errors), 2)
context = Comment()
request = make_request(form={'form.widgets.text': 'foo'})
commentForm = getMultiAdapter((self.context, request), name=u"comment-form")
commentForm.update()
data, errors = commentForm.extractData()
self.assertEquals(len(errors), 1)
context = Comment()
request = make_request(form={'form.widgets.title': 'foo',
'form.widgets.text': 'bar'})
commentForm = getMultiAdapter((self.context, request), name=u"comment-form")
commentForm.update()
data, errors = commentForm.extractData()
self.assertEquals(len(errors), 0)
class TestCommentsViewletIntegration(FunctionalTestCase): class TestCommentsViewletIntegration(FunctionalTestCase):