2009-05-18 17:15:36 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from zope.component import createObject
|
|
|
|
|
|
|
|
from Products.PloneTestCase.ptc import PloneTestCase
|
|
|
|
from plone.app.discussion.tests.layer import DiscussionLayer
|
|
|
|
|
|
|
|
from plone.app.discussion.interfaces import IComment, IConversation
|
|
|
|
|
|
|
|
class CommentTest(PloneTestCase):
|
|
|
|
|
|
|
|
layer = DiscussionLayer
|
|
|
|
|
|
|
|
def afterSetUp(self):
|
|
|
|
# First we need to create some content.
|
|
|
|
self.loginAsPortalOwner()
|
|
|
|
typetool = self.portal.portal_types
|
|
|
|
typetool.constructContent('Document', self.portal, 'doc1')
|
|
|
|
|
|
|
|
def test_factory(self):
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
self.assert_(IComment.providedBy(comment1))
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_id(self):
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.comment_id = 123
|
|
|
|
self.assertEquals('123', comment1.id)
|
|
|
|
self.assertEquals('123', comment1.getId())
|
|
|
|
self.assertEquals(u'123', comment1.__name__)
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_title(self):
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.title = "New title"
|
|
|
|
self.assertEquals("New title", comment1.Title())
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_creator(self):
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.creator = "Jim"
|
|
|
|
self.assertEquals("Jim", comment1.Creator())
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_traversal(self):
|
|
|
|
# make sure comments are traversable, have an id, absolute_url and physical path
|
2009-05-23 06:55:06 +02:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
conversation = IConversation(self.portal.doc1).__of__(self.portal.doc1)
|
2009-05-23 06:55:06 +02:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.title = 'Comment 1'
|
|
|
|
comment1.text = 'Comment text'
|
|
|
|
|
|
|
|
new_comment1_id = conversation.addComment(comment1)
|
|
|
|
|
|
|
|
comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment1_id)
|
|
|
|
self.assert_(IComment.providedBy(comment))
|
|
|
|
self.assertEquals('Comment 1', comment.title)
|
|
|
|
|
|
|
|
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_comment1_id)), comment.getPhysicalPath())
|
|
|
|
self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault/' + str(new_comment1_id), comment.absolute_url())
|
2009-05-23 06:55:06 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_workflow(self):
|
2009-05-23 18:37:10 +02:00
|
|
|
self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('simple_publication_workflow,'))
|
|
|
|
|
|
|
|
conversation = IConversation(self.portal.doc1).__of__(self.portal.doc1)
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
new_comment1_id = conversation.addComment(comment1)
|
|
|
|
|
|
|
|
comment = conversation[new_comment1_id]
|
|
|
|
|
|
|
|
chain = self.portal.portal_workflow.getChainFor(comment)
|
|
|
|
self.assertEquals(('simple_publication_workflow',), chain)
|
|
|
|
|
|
|
|
# ensure the initial state was entered and recorded
|
|
|
|
self.assertEquals(1, len(comment.workflow_history['simple_publication_workflow']))
|
|
|
|
self.assertEquals(None, comment.workflow_history['simple_publication_workflow'][0]['action'])
|
|
|
|
|
|
|
|
self.assertEquals('private', self.portal.portal_workflow.getInfoFor(comment, 'review_state'))
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_fti(self):
|
|
|
|
# test that we can look up an FTI for Discussion Item
|
2009-05-23 18:12:45 +02:00
|
|
|
|
|
|
|
self.assert_("Discussion Item" in self.portal.portal_types.objectIds())
|
|
|
|
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
|
|
|
|
fti = self.portal.portal_types.getTypeInfo(comment1)
|
|
|
|
self.assertEquals('Discussion Item', fti.getTypeInfo(comment1).getId())
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
class RepliesTest(PloneTestCase):
|
|
|
|
|
|
|
|
# test the IReplies adapter on a comment
|
|
|
|
|
|
|
|
layer = DiscussionLayer
|
|
|
|
|
|
|
|
def afterSetUp(self):
|
|
|
|
# First we need to create some content.
|
|
|
|
self.loginAsPortalOwner()
|
|
|
|
typetool = self.portal.portal_types
|
|
|
|
typetool.constructContent('Document', self.portal, 'doc1')
|
|
|
|
|
|
|
|
def test_add_comment(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_delete_comment(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_dict_api(self):
|
|
|
|
# ensure all operations use only top-level comments
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_suite():
|
|
|
|
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|