Index: main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_phonewidget.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_phonewidget.py	(revision 7819)
+++ main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_phonewidget.py	(revision 7840)
@@ -26,5 +26,6 @@
 # XXX: could we possibly get rid of zope.app.testing?
 from zope.app.testing.setup import placefulSetUp, placefulTearDown
-from zope.component import provideAdapter
+from zope.component import provideAdapter, getGlobalSiteManager
+from zope.formlib import form
 from zope.formlib.exception import WidgetInputErrorView
 from zope.formlib.interfaces import (
@@ -48,5 +49,6 @@
         title = u'Phone',
         description = u'Phone number (not required)',
-        required = False,)
+        required = False,
+        missing_value = u'')
 
     baz = schema.TextLine(
@@ -54,8 +56,13 @@
         description = u'Required phone with a default',
         required = True,
-        default=u'234--')
+        #default=u'234--'
+        )
 
 class SampleContent:
     implements(ISampleContent)
+
+    foo = None
+    bar = 'bar'
+    baz = None
 
 class PhoneWidgetTests(unittest.TestCase):
@@ -497,2 +504,107 @@
              u' value=""  />\n'))
         return
+
+import zope.formlib
+from zope import schema
+from zope.formlib.tests.test_functional_objectwidget import (
+    Test, PlacelessSetup, VerifyResults, traversingSetUp, xmlconfig,
+    PageTemplate, os, DefaultTraversable
+    )
+from zope.formlib.tests.test_functional_textwidget import(
+    FunctionalWidgetTestCase, patternExists)
+from zope.formlib.widgets import TextWidget
+from zope.component import adapts
+from zope.interface import implements
+from zope.traversing.interfaces import ITraversable
+from waeup.kofa.widgets.phonewidget import PhoneWidget2, PhonePrefixes
+
+class SampleForm(form.EditForm):
+    form_fields = form.fields(ISampleContent)
+    form_fields['foo'].custom_widget = PhoneWidget2
+    form_fields['bar'].custom_widget = PhoneWidget2
+    form_fields['baz'].custom_widget = PhoneWidget2
+
+class PhoneWidget2Tests(FunctionalWidgetTestCase):
+
+    widgets = [
+        (ITextLine, TextWidget),
+        ]
+
+    def setUp(self):
+        super(PhoneWidget2Tests, self).setUp()
+        self.gsm = getGlobalSiteManager()
+        self.reg_prefixes = PhonePrefixes()
+        self.gsm.registerUtility(self.reg_prefixes)
+        return
+
+    def tearDown(self):
+        self.gsm.unregisterUtility(self.reg_prefixes)
+        return
+
+    def test_display_editform(self):
+        content = SampleContent()
+        request = TestRequest()
+        html = SampleForm(content, request)()
+        # foo.country, foo.area and foo.ext exist
+        self.assert_(patternExists(
+            '<select .* name="form.foo.country".*>', html))
+        self.assert_(patternExists(
+            '<input .* name="form.foo.area".* value="".*>', html))
+        self.assert_(patternExists(
+            '<input .* name="form.foo.ext".* value="".*>', html))
+        return
+
+    def test_submit_editform(self):
+        # we can submit an edit form
+        content = SampleContent()
+        request = TestRequest()
+
+        # submit edit view
+        request.form['form.foo.country'] = u'123'
+        request.form['form.foo.area'] = u'456'
+        request.form['form.foo.ext'] = u'7890'
+        request.form['form.actions.apply'] = u''
+        SampleForm(content, request)()
+
+        # check new values in object
+        self.assertEqual(content.foo, u'123-456-7890')
+        return
+
+    def test_invalid_type(self):
+        # there is no invalid type for textline-based input
+        content = SampleContent()
+        request = TestRequest()
+
+        # submit invalid type for text line
+        request.form['form.foo.country'] = '123'
+        request.form['form.foo.area'] = '456'
+        request.form['form.foo.ext'] = '7890'
+        request.form['form.actions.apply'] = u''
+        html = SampleForm(content, request)()
+
+        # We don't have a invalid field value
+        # since we convert the value to unicode
+        self.assert_('Object is of wrong type.' not in html)
+        return
+
+    def test_missing_value(self):
+        content = SampleContent()
+        request = TestRequest()
+
+        request.form['form.foo.country'] = u'123'
+        request.form['form.foo.area'] = u'456'
+        request.form['form.foo.ext'] = u'7890'
+        request.form['form.bar.country'] = u''
+        request.form['form.bar.area'] = u''
+        request.form['form.bar.ext'] = u''
+        request.form['form.baz.country'] = u''
+        request.form['form.baz.area'] = u''
+        request.form['form.baz.ext'] = u''
+        request.form['form.actions.apply'] = u''
+        SampleForm(content, request)()
+
+        # check new values in object
+        self.assertEqual(content.foo, u'123-456-7890')
+        self.assertEqual(content.bar, u'--') # default missing value
+        self.assertEqual(content.baz, u'--')
+        return
