This commit is contained in:
Timo Stollenwerk 2013-01-10 18:40:04 +01:00
parent 69b628c386
commit a6afdf265c

View File

@ -114,9 +114,11 @@ class CommentTest(unittest.TestCase):
self.assertEqual("Anonymous on Document 1", comment1.Title()) self.assertEqual("Anonymous on Document 1", comment1.Title())
def test_title_special_characters(self): def test_title_special_characters(self):
self.portal.invokeFactory(id='doc_sp_chars', self.portal.invokeFactory(
title=u'Document äüö', id='doc_sp_chars',
type_name='Document') title=u'Document äüö',
type_name='Document'
)
conversation = IConversation(self.portal.doc_sp_chars) conversation = IConversation(self.portal.doc_sp_chars)
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.author_name = u"Tarek Ziadé" comment1.author_name = u"Tarek Ziadé"
@ -141,41 +143,53 @@ class CommentTest(unittest.TestCase):
comment1.text = """First paragraph comment1.text = """First paragraph
Second paragraph""" Second paragraph"""
self.assertEqual(comment1.getText(), self.assertEqual(
"<p>First paragraph<br /><br /> Second paragraph</p>") comment1.getText(),
"<p>First paragraph<br /><br /> Second paragraph</p>"
)
def test_getText_escapes_HTML(self): def test_getText_escapes_HTML(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.text = """<b>Got HTML?</b>""" comment1.text = """<b>Got HTML?</b>"""
self.assertEqual(comment1.getText(), self.assertEqual(
"<p>&lt;b&gt;Got HTML?&lt;/b&gt;</p>") comment1.getText(),
"<p>&lt;b&gt;Got HTML?&lt;/b&gt;</p>"
)
def test_getText_with_non_ascii_characters(self): def test_getText_with_non_ascii_characters(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.text = u"""Umlaute sind ä, ö und ü.""" comment1.text = u"""Umlaute sind ä, ö und ü."""
self.assertEqual(comment1.getText(), self.assertEqual(
'<p>Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.</p>') comment1.getText(),
'<p>Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.</p>'
)
def test_getText_doesnt_link(self): def test_getText_doesnt_link(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.text = "Go to http://www.plone.org" comment1.text = "Go to http://www.plone.org"
self.assertEqual(comment1.getText(), self.assertEqual(
"<p>Go to http://www.plone.org</p>") comment1.getText(),
"<p>Go to http://www.plone.org</p>"
)
def test_getText_uses_comment_mime_type(self): def test_getText_uses_comment_mime_type(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.text = "Go to http://www.plone.org" comment1.text = "Go to http://www.plone.org"
comment1.mime_type = 'text/x-web-intelligent' comment1.mime_type = 'text/x-web-intelligent'
self.assertEqual(comment1.getText(), self.assertEqual(
comment1.getText(),
'Go to <a href="http://www.plone.org" ' + 'Go to <a href="http://www.plone.org" ' +
'rel="nofollow">http://www.plone.org</a>') 'rel="nofollow">http://www.plone.org</a>'
)
def test_getText_uses_comment_mime_type_html(self): def test_getText_uses_comment_mime_type_html(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.text = 'Go to <a href="http://www.plone.org">plone.org</a>' comment1.text = 'Go to <a href="http://www.plone.org">plone.org</a>'
comment1.mime_type = 'text/html' comment1.mime_type = 'text/html'
self.assertEqual(comment1.getText(), self.assertEqual(
'Go to <a href="http://www.plone.org">plone.org</a>') comment1.getText(),
'Go to <a href="http://www.plone.org">plone.org</a>'
)
def test_getText_w_custom_targetMimetype(self): def test_getText_w_custom_targetMimetype(self):
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
@ -207,19 +221,28 @@ class CommentTest(unittest.TestCase):
'++conversation++default/%s' % new_comment1_id) '++conversation++default/%s' % new_comment1_id)
self.assertTrue(IComment.providedBy(comment)) self.assertTrue(IComment.providedBy(comment))
self.assertEqual(('', 'plone', 'doc1', '++conversation++default', self.assertEqual(
str(new_comment1_id)), comment.getPhysicalPath()) (
self.assertEqual('http://nohost/plone/doc1/++conversation++default/' + '', 'plone', 'doc1', '++conversation++default',
str(new_comment1_id), comment.absolute_url()) str(new_comment1_id)
),
comment.getPhysicalPath()
)
self.assertEqual(
'http://nohost/plone/doc1/++conversation++default/' +
str(new_comment1_id), comment.absolute_url()
)
def test_view_blob_types(self): def test_view_blob_types(self):
""" """
Make sure that traversal to images/files redirects to the Make sure that traversal to images/files redirects to the
version of the url with a /view in it. version of the url with a /view in it.
""" """
self.portal.invokeFactory(id='image1', self.portal.invokeFactory(
title='Image', id='image1',
type_name='Image') title='Image',
type_name='Image'
)
conversation = IConversation(self.portal.image1) conversation = IConversation(self.portal.image1)
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
@ -251,18 +274,26 @@ class CommentTest(unittest.TestCase):
self.assertEqual(('comment_review_workflow',), chain) self.assertEqual(('comment_review_workflow',), chain)
# Ensure the initial state was entered and recorded # Ensure the initial state was entered and recorded
self.assertEqual(1, self.assertEqual(
len(comment.workflow_history['comment_review_workflow'])) 1,
self.assertEqual(None, len(comment.workflow_history['comment_review_workflow'])
comment.workflow_history['comment_review_workflow'][0]['action']) )
self.assertEqual('pending', self.assertEqual(
self.portal.portal_workflow.getInfoFor(comment, 'review_state')) None,
comment.workflow_history['comment_review_workflow'][0]['action']
)
self.assertEqual(
'pending',
self.portal.portal_workflow.getInfoFor(comment, 'review_state')
)
def test_fti(self): def test_fti(self):
# test that we can look up an FTI for Discussion Item # test that we can look up an FTI for Discussion Item
self.assertTrue("Discussion Item" in self.assertTrue(
self.portal.portal_types.objectIds()) "Discussion Item" in
self.portal.portal_types.objectIds()
)
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
@ -307,9 +338,11 @@ class RepliesTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.portal = self.layer['portal'] self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager']) setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.portal.invokeFactory(id='doc1', self.portal.invokeFactory(
title='Document 1', id='doc1',
type_name='Document') title='Document 1',
type_name='Document'
)
def test_add_comment(self): def test_add_comment(self):
# Add comments to a CommentReplies adapter # Add comments to a CommentReplies adapter
@ -404,7 +437,8 @@ class RepliesTest(unittest.TestCase):
replies = IReplies(comment) replies = IReplies(comment)
new_re_id = replies.addComment(re_comment) new_re_id = replies.addComment(re_comment)
re_comment = self.portal.doc1.restrictedTraverse( re_comment = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_re_id) '++conversation++default/%s' % new_re_id
)
# Add a reply to the reply # Add a reply to the reply
re_re_comment = createObject('plone.Comment') re_re_comment = createObject('plone.Comment')
@ -412,7 +446,8 @@ class RepliesTest(unittest.TestCase):
replies = IReplies(re_comment) replies = IReplies(re_comment)
new_re_re_id = replies.addComment(re_re_comment) new_re_re_id = replies.addComment(re_re_comment)
re_re_comment = self.portal.doc1.restrictedTraverse( re_re_comment = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_re_re_id) '++conversation++default/%s' % new_re_re_id
)
# Add a reply to the replies reply # Add a reply to the replies reply
re_re_re_comment = createObject('plone.Comment') re_re_re_comment = createObject('plone.Comment')
@ -422,24 +457,47 @@ class RepliesTest(unittest.TestCase):
re_re_re_comment = self.portal.doc1.restrictedTraverse( re_re_re_comment = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_re_re_re_id) '++conversation++default/%s' % new_re_re_re_id)
self.assertEqual(('', 'plone', 'doc1', '++conversation++default', self.assertEqual(
str(new_id)), comment.getPhysicalPath()) ('', 'plone', 'doc1', '++conversation++default', str(new_id)),
self.assertEqual('http://nohost/plone/doc1/++conversation++default/' + comment.getPhysicalPath()
str(new_id), comment.absolute_url()) )
self.assertEqual(('', 'plone', 'doc1', '++conversation++default', self.assertEqual(
str(new_re_id)), re_comment.getPhysicalPath()) 'http://nohost/plone/doc1/++conversation++default/' +
self.assertEqual('http://nohost/plone/doc1/++conversation++default/' + str(new_id), comment.absolute_url()
str(new_re_id), re_comment.absolute_url()) )
self.assertEqual(('', 'plone', 'doc1', '++conversation++default', self.assertEqual(
str(new_re_re_id)), re_re_comment.getPhysicalPath()) ('', 'plone', 'doc1', '++conversation++default', str(new_re_id)),
self.assertEqual('http://nohost/plone/doc1/++conversation++default/' + re_comment.getPhysicalPath()
str(new_re_re_id), re_re_comment.absolute_url()) )
self.assertEqual(('', 'plone', 'doc1', '++conversation++default', self.assertEqual(
str(new_re_re_re_id)), 'http://nohost/plone/doc1/++conversation++default/' +
re_re_re_comment.getPhysicalPath()) str(new_re_id),
self.assertEqual('http://nohost/plone/doc1/++conversation++default/' + re_comment.absolute_url()
str(new_re_re_re_id), )
re_re_re_comment.absolute_url()) self.assertEqual(
(
'', 'plone', 'doc1', '++conversation++default',
str(new_re_re_id)
),
re_re_comment.getPhysicalPath()
)
self.assertEqual(
'http://nohost/plone/doc1/++conversation++default/' +
str(new_re_re_id),
re_re_comment.absolute_url()
)
self.assertEqual(
(
'', 'plone', 'doc1', '++conversation++default',
str(new_re_re_re_id)
),
re_re_re_comment.getPhysicalPath()
)
self.assertEqual(
'http://nohost/plone/doc1/++conversation++default/' +
str(new_re_re_re_id),
re_re_re_comment.absolute_url()
)
def test_suite(): def test_suite():