[Zope3-checkins] CVS: Products3/demo/messageboard/step5/browser/tests - __init__.py:1.1 test_widgets.py:1.1

Stephan Richter srichter@cosmos.phy.tufts.edu
Tue, 10 Jun 2003 17:49:51 -0400


Update of /cvs-repository/Products3/demo/messageboard/step5/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv20196/step5/browser/tests

Added Files:
	__init__.py test_widgets.py 
Log Message:
This is step 6 of the message board which implements a new ISized adapter 
for the Message object.


=== Added File Products3/demo/messageboard/step5/browser/tests/__init__.py ===
# Package Maker


=== Added File Products3/demo/messageboard/step5/browser/tests/test_widgets.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""HTMLSourceWidget Tests

$Id: test_widgets.py,v 1.1 2003/06/10 21:49:50 srichter Exp $
"""
import unittest
from zope.app.browser.form.tests.test_textareawidget import \
     TextAreaWidgetTest
from zopeproducts.messageboard.browser.widgets import HTMLSourceWidget
from zopeproducts.messageboard.fields import HTML

class HTMLSourceWidgetTest(TextAreaWidgetTest):

    _FieldFactory = HTML
    _WidgetFactory = HTMLSourceWidget


    def test_AllowedTagsConvert(self):
        widget = self._widget
        widget.context.allowed_tags=('h1','pre')
        self.assertEqual(u'<h1>Blah</h1>',
                         widget._convert(u'<h1>Blah</h1>')) 
        self.assertEqual(u'<pre>Blah</pre>',
                         widget._convert(u'<pre>Blah</pre>') )
        self.assertEqual(u'<h1><pre>Blah</pre></h1>',
                         widget._convert(u'<h1><pre>Blah</pre></h1>')) 
        self.assertEqual(u'<h1 attr=".">Blah</h1>',
                         widget._convert(u'<h1 attr=".">Blah</h1>')) 

        self.assertEqual(u'Blah',
                         widget._convert(u'<h2>Blah</h2>')) 
        self.assertEqual(u'<pre>Blah</pre>',
                         widget._convert(u'<h2><pre>Blah</pre></h2>')) 
        self.assertEqual(u'Blah',
                         widget._convert(u'<h2 a="b">Blah</h2>')) 


    def test_ForbiddenTagsConvert(self):
        widget = self._widget
        widget.context.forbidden_tags=('h2','pre')

        self.assertEqual(u'<h1>Blah</h1>',
                         widget._convert(u'<h1>Blah</h1>')) 
        self.assertEqual(u'<h1 a="b">Blah</h1>',
                         widget._convert(u'<h1 a="b">Blah</h1>')) 

        self.assertEqual(u'Blah',
                         widget._convert(u'<h2>Blah</h2>')) 
        self.assertEqual(u'Blah',
                         widget._convert(u'<pre>Blah</pre>')) 
        self.assertEqual(u'Blah',
                         widget._convert(u'<h2><pre>Blah</pre></h2>')) 
        self.assertEqual(u'Blah',
                         widget._convert(u'<h2><pre>Blah</pre></h2>')) 
        self.assertEqual(u'<h1>Blah</h1>',
                         widget._convert(u'<h1><pre>Blah</pre></h1>')) 


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(HTMLSourceWidgetTest),
        ))

if __name__ == '__main__':
    unittest.main()