source: trunk/tests/testWYSIWYM.py @ 66

Revision 66, 3.4 KB checked in by tarmo, 14 years ago (diff)

Changed the svn:eol-style property to "native", since
people aren't using unix line feeds uniformally.

  • Property svn:eol-style set to native
Line 
1#
2# Test case for WYSIWYM content
3#
4
5import os, sys, re
6if __name__ == '__main__':
7    execfile(os.path.join(sys.path[0], 'framework.py'))
8
9from Testing import ZopeTestCase
10from ToolboxTestCase import ToolboxTestCase
11from Products.CMFCore.utils import getToolByName
12from Products.PloneTestCase.setup import portal_owner, default_password
13
14types = ('Module',)
15auth=':'.join((portal_owner, default_password))
16
17class TestWYSIWYM(ToolboxTestCase):
18
19    def afterSetUp(self):
20        self.ID='TestModule'
21        self.addUser('foobar','foobar')
22        self.ob=self.construct('Module',self.ID,self.folder)
23
24    #~ def testEditing(self):
25        #~ path='/'.join((self.folder.absolute_url_path(),self.ID, 'base_edit'))
26        #~ result=self.publish(path,basic=auth).getBody()
27        #~ #raise "FOO",str(result)
28        #~ self.failUnless(re.search('WYSIWYM Editor',result),"The comment 'WYSIWYM' is not found")
29   
30    translations = (('*bold*','<p><b>bold</b></p>'),
31                        #('1 < 2 or 3 > 4/5', '<p>1 &lt; 2 or 3 &gt; 4/5</p>')
32                        ('Bolding*or*italics only_work_on whole words','<p>Bolding*or*italics only_work_on whole words</p>'),
33                        ('No * bold * here','<p>No * bold * here</p>'),
34                        ('*Several words* can _be affected_','<p><b>Several words</b> can <i>be affected</i></p>'),
35                        ('_italic_','<p><i>italic</i></p>'),
36                        ('Line1\r\n\r\nLine2','<p>Line1</p><p>Line2</p>'),
37                        ('Line1\r\nLine2','<p>Line1<br/>Line2</p>'),
38                        ('Line with *bold* in it\r\n\r\nLine with _italic_ in it.',
39                         '<p>Line with <b>bold</b> in it</p><p>Line with <i>italic</i> in it.</p>'),
40                        ('* Item1\r\n* Item2\r\n* Third item',
41                         '<ul><li>Item1</li><li>Item2</li><li>Third item</li></ul>'),
42                        ('# Item1\r\n# Item2\r\n# Third item',
43                         '<ol><li>Item1</li><li>Item2</li><li>Third item</li></ol>'),
44                        ('This is a [http://foo.bar Link].','<p>This is a <a href="http://foo.bar">Link</a>.</p>'),
45                        ('Paragraph1\r\n\r\n* Item1\r\n* Item2\r\n\r\nParagraph2',
46                         '<p>Paragraph1</p><ul><li>Item1</li><li>Item2</li></ul><p>Paragraph2</p>'),
47                         ('*Hello*, (*This is a test*).', '<p><b>Hello</b>, (<b>This is a test</b>).</p>'),
48                         ('_Hello_, (_This is a test_).', '<p><i>Hello</i>, (<i>This is a test</i>).</p>')
49                        )
50
51    def testHTMLRendering(self):
52        errors=''
53        for (body,rbody) in self.translations:
54            self.ob.edit(body=body)
55            if self.ob.getBody()!=rbody:
56                errors = errors + 'Wrong rendering for "%s": "%s" (expected "%s")\n' % (body,self.ob.getBody(),rbody)
57        self.failIf(errors,errors)
58       
59    def testHTMLRenderingInPlone(self):
60        path=self.ob.absolute_url_path() + '/base_edit'
61        errors=''
62        for (body,rbody) in self.translations[:2]:
63            self.ob.edit(body=body)
64            result=self.publish(path,basic=auth).getBody()
65            self.failIf(body not in result, "Edit field doesn't contain raw data: %s" % result)
66
67def test_suite():
68    from unittest import TestSuite, makeSuite
69    suite = TestSuite()
70    suite.addTest(makeSuite(TestWYSIWYM))
71    return suite
72
73if __name__ == '__main__':
74    framework()
Note: See TracBrowser for help on using the repository browser.