Back to index

plone3  3.1.7
test_wysiwygwidget.py
Go to the documentation of this file.
00001 from Products.PloneTestCase import PloneTestCase as ptc
00002 from Products.CMFCore.utils import getToolByName
00003 
00004 from zope.publisher.browser import TestRequest
00005 from zope.app.component.hooks import getSite
00006 
00007 from plone.app.form.widgets.wysiwygwidget import WYSIWYGWidget
00008 
00009 ptc.setupPloneSite()
00010 
00011 
00012 class WYSIWYGWidgetTestCase(ptc.PloneTestCase):
00013     """Base class used for test cases
00014     """
00015 
00016     def test_right_macro(self):
00017         # fixes #8016
00018         class MyField:
00019             __name__ = 'the field'
00020             required = True
00021             default = u'the value'
00022             missing_value = None
00023 
00024         # the wysiwyg widget depends on the used editor
00025         pm = getToolByName(self.portal, 'portal_membership')
00026         member = pm.getAuthenticatedMember()
00027         editor = member.getProperty('wysiwyg_editor', '').lower()
00028 
00029         # we have kupu by default
00030         self.assertEquals(editor, 'kupu')
00031 
00032         # so it means the widget should use the macro
00033         # provided by kupu (default skin with .css includes)
00034         w = WYSIWYGWidget(MyField(), TestRequest())
00035         kupu = w()
00036 
00037         # let's add a custom editor
00038         # with a fake skin that should be catched
00039         # to provide a custom macro
00040         site = getSite()
00041         class  MyMacros(object):
00042             def wysiwygEditorBox(self):
00043                 return (('version', '1.6'), ('mode', 'html'))
00044         class MySkin(object):
00045             macros = MyMacros()
00046         site.cool_editor_wysiwyg_support = MySkin()
00047 
00048         # let's change it to `cool_editor`
00049         member.setMemberProperties({'wysiwyg_editor': 'cool_editor'})
00050 
00051         w = WYSIWYGWidget(MyField(), TestRequest())
00052         cool_editor = w()
00053 
00054         # the macro used by wysiwygwidget should differ
00055         self.assertNotEquals(kupu, cool_editor)
00056 
00057 def test_suite():
00058     from unittest import TestSuite, makeSuite
00059     suite = TestSuite()
00060     suite.addTest(makeSuite(WYSIWYGWidgetTestCase))
00061     return suite