Index: main/waeup.sirp/branches/ulif-fasttables/src/waeup/sirp/widgets/tests/test_objectwidget.py
===================================================================
--- main/waeup.sirp/branches/ulif-fasttables/src/waeup/sirp/widgets/tests/test_objectwidget.py	(revision 5310)
+++ main/waeup.sirp/branches/ulif-fasttables/src/waeup/sirp/widgets/tests/test_objectwidget.py	(revision 5311)
@@ -1,12 +1,15 @@
 """Tests for objectwidget.
 """
+import doctest
 import unittest
 import sys
 from zope.component import testing
 from zope.interface import Interface, implements
+from zope.interface.verify import verifyClass
 from zope.publisher.browser import TestRequest
 from zope.schema import Object, TextLine
 from zope.schema.interfaces import ITextLine
-import doctest
+from zope.traversing.adapters import DefaultTraversable
+from zope.traversing.interfaces import ITraversable
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from zope.component import provideAdapter
@@ -14,5 +17,5 @@
 from zope.formlib.interfaces import (
     IInputWidget, IDisplayWidget,MissingInputError)
-from zope.formlib.widgets import TextWidget
+from zope.formlib.widgets import TextWidget, DisplayWidget
 from zope.formlib.tests.test_browserwidget import BrowserWidgetTest
 from zope.formlib.interfaces import IWidgetInputErrorView
@@ -128,4 +131,19 @@
         self.assertEqual(self.content.foo.email, u'foo@foo.test')
 
+    def test_respect_custom_widgets(self):
+        # We can use our own subwidgets when creating ObjectWidgets
+        class CustomTextWidget(TextWidget):
+            pass
+
+        # We create a custom widget for the `name` field of ITestContact
+        name_widget = CustomTextWidget(ITestContact['name'], self.request)
+
+        # Custom widgets are passed by <fieldname>_widget keyword:
+        widget = self._WidgetFactory(self.field, self.request,
+                                     name_widget=name_widget)
+        widget1, widget2 = widget.subwidgets()
+        self.assertTrue(widget1 is name_widget)
+        
+        
 class ObjectDisplayWidgetTest(BrowserWidgetTest):
     """Documents and tests the display variant of object widget.
@@ -134,6 +152,60 @@
         >>> verifyClass(IDisplayWidget, ObjectDisplayWidget)
         True
-    """
-
+
+   """
+    _FieldFactory = Object
+    def _WidgetFactory(self, context, request, **kw):
+        kw.update({'factory': TestContact})
+        return ObjectDisplayWidget(context, request, **kw)
+
+    def setUpContent(self, desc=u'', title=u'Foo Title'):
+        provideAdapter(TextWidget, (ITextLine, IDefaultBrowserLayer),
+                       IInputWidget)
+        provideAdapter(DisplayWidget, (ITextLine, IDefaultBrowserLayer),
+                       IDisplayWidget)
+        # The widget must be traversable. We register the default
+        # adapter that can turn nearly any object into an ITraversable.
+        provideAdapter(DefaultTraversable, (None,), ITraversable)
+        
+        class TestObject(object):
+            implements(ITestContent)
+
+        self.content = TestObject()
+        self.content.name = u'Foo Name'
+        self.content.email = u'foo@foo.test'
+        self.field = ITestContent['foo']
+        self.request = TestRequest(HTTP_ACCEPT_LANGUAGE='pl')
+        self.request.form['field.foo'] = u'Foo Value'
+        self._widget = self._WidgetFactory(self.field, self.request)
+
+    def setUp(self):
+        super(ObjectDisplayWidgetTest, self).setUp()
+        self.field = Object(ITestContact, __name__=u'foo')
+        provideAdapter(TextWidget,
+                       (ITextLine, IDefaultBrowserLayer),
+                       IInputWidget)
+        provideAdapter(DisplayWidget,
+                       (ITextLine, IDefaultBrowserLayer),
+                       IDisplayWidget)
+
+        
+    def test_interfaces(self):
+        from zope.interface.verify import DoesNotImplement
+        self.assertTrue(IDisplayWidget.providedBy(self._widget))
+        self.assertFalse(IInputWidget.providedBy(self._widget))
+        self.assertTrue(verifyClass(IDisplayWidget, ObjectDisplayWidget))
+
+    def test_render(self):
+        widget = ObjectDisplayWidget(
+            self.field, self.request, TestContact)
+        widget.setRenderedValue(self.content)
+
+        check_list = [
+            '<td', 'class=', 'row',
+            'Foo Name',
+            '</td>', '<td', 'class=', 'row',
+            'foo@foo.test',
+            '</td>']
+        self.verifyResult(widget(), check_list, inorder=True)    
 
 def test_suite():
@@ -141,7 +213,4 @@
         unittest.makeSuite(ObjectWidgetTest),
         unittest.makeSuite(ObjectDisplayWidgetTest),
-        #doctest.DocFileSuite('../objectwidget.txt',
-        #                     setUp=testing.setUp,
-        #                     tearDown=testing.tearDown),
         doctest.DocTestSuite(),
         ))
