Changeset 7852 for main


Ignore:
Timestamp:
12 Mar 2012, 16:49:10 (13 years ago)
Author:
uli
Message:

Enable new phone widget and remove the old one.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r7828 r7852  
    798798        self.browser.getControl(name="form.lastname").value = 'Tester'
    799799        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
    800         self.browser.getControl(name="form.phone.country").value = '234'
     800        self.browser.getControl(name="form.phone.country").value = ['+234']
    801801        self.browser.getControl(name="form.phone.area").value = '555'
    802         self.browser.getControl(name="form.phone.extension").value = '6666666'
     802        self.browser.getControl(name="form.phone.ext").value = '6666666'
    803803        self.browser.getControl("Get login credentials").click()
    804804        self.assertEqual(self.browser.url,
  • main/waeup.kofa/trunk/src/waeup/kofa/widgets/phonewidget.py

    r7848 r7852  
    4444from zope.schema.interfaces import RequiredMissing
    4545
    46 class IPhoneData(Interface):
    47     """A schema used to generate a Phone widget."""
    48 
    49     country = schema.TextLine(
    50         title=u'Country Code',
    51         description=u'The country code of the phone number.',
    52         min_length=1,
    53         constraint=re.compile(r'^[0-9]+$').search,
    54         default=u'234', # int. code for nigeria
    55         required=True)
    56 
    57     area = schema.TextLine(
    58         title=u'Area Code',
    59         description=u'The area code of the phone number.',
    60         min_length=1,
    61         constraint=re.compile(r'^[0-9]+$').search,
    62         required=True)
    63 
    64     extension = schema.TextLine(
    65         title=u'Direct Line',
    66         description=u'The direct line of the phone number.',
    67         min_length=3,
    68         constraint=re.compile(r'^[0-9]{3,}$').search,
    69         required=True)
    70 
    71 class PhoneWidgetData(object):
    72     """Phone number data"""
    73     implements(IPhoneData)
    74 
    75     country = None
    76     area = None
    77     extension = None
    78 
    79     def __init__(self, context=None, number=None):
    80         """Set countrycode, areacode, and extension line from number.
    81         """
    82         self.context = context
    83         if number is None:
    84             return
    85         # handle other types than strings.
    86         if not isinstance(number, basestring):
    87             number = str(number)
    88         parts = number.split('-', 2)
    89         if len(parts) == 2:
    90             parts = [None,] + parts
    91         elif len(parts) == 0:
    92             return
    93         elif len(parts) == 1:
    94             parts = [None, None] + parts
    95         self.country, self.area, self.extension = parts
    96         return
    97 
    98     @property
    99     def number(self):
    100         """Return a valid phone number string of format ``<IC>-<AC>-<EL>``.
    101 
    102         where <IC> is the country code (digits only), <AC> is the area
    103         code and <EL> is the extension line.
    104         """
    105         return u'-'.join(
    106             (self.country or '', self.area or '', self.extension))
    107 
    108 
    109 class PhoneWidget(SimpleInputWidget):
    110     """Phone Number Widget"""
    111     implements(IBrowserWidget, IInputWidget)
    112 
    113     template = ViewPageTemplateFile('phonewidget.pt')
    114     _prefix = 'field.'
    115     _error = None
    116     widgets = {}
    117 
    118     # See zope.formlib.interfaces.IWidget
    119     name = None
    120     visible = True
    121 
    122     def __init__(self, field, request):
    123         super(PhoneWidget, self).__init__(field, request)
    124         value = field.query(field.context)
    125         self._generateSubWidgets()
    126         return
    127 
    128     def _generateSubWidgets(self):
    129         """Create the three subwidgets.
    130         """
    131         value = self.context.query(self.context.context)
    132         # We have to modify the adapter according to our own
    133         # 'required' state. Some ugly workaround
    134         adapter = copy.deepcopy(IPhoneData)
    135         for name in 'country', 'area', 'extension':
    136             adapter[name].required = self.required
    137         adapters = {adapter: PhoneWidgetData(self, value)}
    138         self.widgets = form.setUpEditWidgets(
    139             form.FormFields(IPhoneData),
    140             self.name, value, self.request, adapters=adapters)
    141         # The displayWidth cant'be set
    142         # because it is overridden by Bootstrap css classes
    143         #self.widgets['country'].displayWidth = 3
    144         #self.widgets['area'].displayWidth = 5
    145         #self.widgets['extension'].displayWidth = 10
    146         # We have to set the cssClass attributes
    147         self.widgets['country'].cssClass = 'span2'
    148         self.widgets['area'].cssClass = 'span2'
    149         self.widgets['extension'].cssClass = 'span3'
    150 
    151         return
    152 
    153     def setRenderedValue(self, value):
    154         """See zope.formlib.interfaces.IWidget"""
    155         if isinstance(value, unicode) and '-' in value:
    156             country, area, extension = value.split('-', 2)
    157             self.widgets['country'].setRenderedValue(country)
    158             self.widgets['area'].setRenderedValue(area)
    159             self.widgets['extension'].setRenderedValue(extension)
    160             return
    161         return
    162 
    163     def setPrefix(self, prefix):
    164         """See zope.formlib.interfaces.IWidget"""
    165         # Set the prefix locally
    166         if not prefix.endswith("."):
    167             prefix += '.'
    168         self._prefix = prefix
    169         self.name = prefix + self.context.__name__
    170         # Now distribute it to the sub-widgets
    171         self._generateSubWidgets()
    172         return
    173 
    174     def getInputValue(self):
    175         """See zope.formlib.interfaces.IInputWidget"""
    176         self._error = None
    177         try:
    178             result = u'-'.join((
    179                 self.widgets['country'].getInputValue(),
    180                 self.widgets['area'].getInputValue(),
    181                 self.widgets['extension'].getInputValue() ))
    182             return result
    183         except TypeError:
    184             if self.required:
    185                 return self._missing
    186             return None
    187         except ValueError, v:
    188             self._error = WidgetInputError(
    189                 self.context.__name__, self.label, _(v))
    190             raise self._error
    191         except WidgetInputError, e:
    192             self._error = e
    193             raise e
    194 
    195     def applyChanges(self, content):
    196         """See zope.formlib.interfaces.IInputWidget"""
    197         field = self.context
    198         new_value = self.getInputValue()
    199         old_value = field.query(content, self)
    200         # The selection has not changed
    201         if new_value == old_value:
    202             return False
    203         field.set(content, new_value)
    204         return True
    205 
    206     def hasInput(self):
    207         """See zope.formlib.interfaces.IInputWidget"""
    208         return (self.widgets['country'].hasInput() and
    209                 (self.widgets['area'].hasInput() and
    210                  self.widgets['extension'].hasInput()))
    211 
    212 
    213     def hasValidInput(self):
    214         """See zope.formlib.interfaces.IInputWidget"""
    215         return (self.widgets['country'].hasValidInput() and
    216             self.widgets['area'].hasValidInput() and
    217             self.widgets['extension'].hasValidInput())
    218 
    219 
    220     def hidden(self):
    221         """See zope.formlib.interfaces.IBrowserWidget"""
    222         output = []
    223         output.append(self.widgets['country'].hidden())
    224         output.append(self.widgets['area'].hidden())
    225         output.append(self.widgets['extension'].hidden())
    226         return '\n'.join(output)
    227 
    228 
    229     def error(self):
    230         """See zope.formlib.interfaces.IBrowserWidget"""
    231         if self._error:
    232             return getMultiAdapter(
    233                 (self._error, self.request),
    234                 IWidgetInputErrorView).snippet()
    235         country_error = self.widgets['country'].error()
    236         if country_error:
    237             return country_error
    238         area_error = self.widgets['area'].error()
    239         if area_error:
    240             return area_error
    241         extension_error = self.widgets['extension'].error()
    242         if extension_error:
    243             return extension_error
    244         return ""
    245 
    246     def __call__(self):
    247         """See zope.formlib.interfaces.IBrowserWidget"""
    248         return self.template()
    24946
    25047from zc.sourcefactory.contextual import BasicContextualSourceFactory
     
    28279RE_NUMBERS_AND_HYPHENS = re.compile('^[\d\-]+$')
    28380
    284 class PhoneWidget2(TextWidget):
     81class PhoneWidget(TextWidget):
    28582
    28683    subwidget_names = ('country', 'area', 'ext')
     
    358155        For the extension line we silently allow slashes as well.
    359156        """
    360         result = super(PhoneWidget2, self)._toFieldValue(input)
     157        result = super(PhoneWidget, self)._toFieldValue(input)
    361158        parts = input.split('-', 2)
    362159        if '' in parts and self.context.required:
  • main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_phonewidget.py

    r7849 r7852  
    3939from waeup.kofa.widgets.phonewidget import PhoneWidget
    4040
     41import zope.formlib
     42from zope import schema
     43from zope.formlib.tests.test_functional_objectwidget import (
     44    Test, PlacelessSetup, VerifyResults, traversingSetUp, xmlconfig,
     45    PageTemplate, os, DefaultTraversable
     46    )
     47from zope.formlib.tests.test_functional_textwidget import(
     48    FunctionalWidgetTestCase, patternExists)
     49from zope.formlib.widgets import TextWidget
     50from zope.component import adapts
     51from zope.interface import implements
     52from zope.traversing.interfaces import ITraversable
     53from waeup.kofa.widgets.phonewidget import PhoneWidget, PhonePrefixes
     54
    4155# Dummy content
    4256class ISampleContent(Interface):
     
    6882        self.baz = None
    6983
    70 class PhoneWidgetTests(unittest.TestCase):
    71     # Tests for phone widget
    7284
    73     def setUp(self):
    74         placefulSetUp()
    75 
    76         # register TextLine views (so that subwidgets can be rendered)
    77         provideAdapter(
    78             TextWidget, (ITextLine, IDefaultBrowserLayer), IInputWidget)
    79         # errors in forms
    80         provideAdapter(
    81             WidgetInputErrorView, (IWidgetInputError, IDefaultBrowserLayer),
    82             IWidgetInputErrorView)
    83 
    84         # setup some sample content to bind to (only neccessary for
    85         # some of the tests)
    86         self.content = SampleContent()
    87         self.field = ISampleContent['foo']
    88         self.field = self.field.bind(self.content)
    89         self.field_nonreq = ISampleContent['bar']
    90         self.field_nonreq = self.field_nonreq.bind(self.content)
    91         self.field_w_default = ISampleContent['baz']
    92         self.field_w_default = self.field_w_default.bind(self.content)
    93 
    94         # create an empty request. We need one to create a widget
    95         self.request = TestRequest()
    96         self.widget = PhoneWidget(self.field, self.request)
    97         self.widget_nonreq = PhoneWidget(self.field_nonreq, self.request)
    98         return
    99 
    100     def tearDown(self):
    101         placefulTearDown()
    102         return
    103 
    104     def test_ifaces(self):
    105         # make sure we fullfill interface contracts
    106         verify.verifyClass(IBrowserWidget, PhoneWidget)
    107         verify.verifyClass(IInputWidget, PhoneWidget)
    108         verify.verifyObject(IBrowserWidget, self.widget)
    109         verify.verifyObject(IInputWidget, self.widget)
    110         return
    111 
    112     def test_attribs_set(self):
    113         # make sure the public attributes are set correctly
    114         self.assertEqual(self.widget.name, 'field.foo')
    115         self.assertEqual(self.widget.label, u'Phone')
    116         self.assertEqual(self.widget.hint, u'Phone number')
    117         self.assertEqual(self.widget.visible, True)
    118         self.assertEqual(self.widget.required, True)
    119         self.assertEqual(self.widget_nonreq.required, False)
    120         return
    121 
    122     def test_subwidgets_exist(self):
    123         # make sure we have three sub widgets
    124         sub_widget1 = self.widget.widgets['country']
    125         sub_widget2 = self.widget.widgets['area']
    126         sub_widget3 = self.widget.widgets['extension']
    127         self.assertTrue(isinstance(sub_widget1, TextWidget))
    128         self.assertTrue(isinstance(sub_widget2, TextWidget))
    129         self.assertTrue(isinstance(sub_widget3, TextWidget))
    130         return
    131 
    132     def test_set_rendered_value(self):
    133         # make sure we render values correctly
    134         self.widget.setRenderedValue(u'123-456-1234567')
    135         self.assertEqual(
    136             self.widget(),
    137             (u'+&nbsp;<input class="span2 textType" id="field.foo.country"'
    138              u' name="field.foo.country" size="20" type="text" value="123" '
    139              u' />'
    140              u'&nbsp;-\n'
    141              u'<input class="span2 textType" id="field.foo.area"'
    142              u' name="field.foo.area" size="20" type="text" value="456" '
    143              u' />'
    144              u'&nbsp;-\n'
    145              u'<input class="span3 textType" id="field.foo.extension"'
    146              u' name="field.foo.extension" size="20" type="text"'
    147              u' value="1234567"  />\n'))
    148         return
    149 
    150     def test_set_prefix_default(self):
    151         # prefix determines the name of widget and its subwidgets.
    152         self.assertEqual(self.widget.name, 'field.foo')
    153         self.assertEqual(self.widget.widgets['country'].name,
    154                          'field.foo.country')
    155         self.assertEqual(self.widget.widgets['area'].name,
    156                          'field.foo.area')
    157         self.assertEqual(self.widget.widgets['extension'].name,
    158                          'field.foo.extension')
    159         return
    160 
    161     def test_set_prefix_changed(self):
    162         # when we set the prefix, widget names change
    163         self.widget.setPrefix('test.')
    164         self.assertEqual(self.widget.name, 'test.foo')
    165         self.assertEqual(self.widget.widgets['country'].name,
    166                          'test.foo.country')
    167         self.assertEqual(self.widget.widgets['area'].name,
    168                          'test.foo.area')
    169         self.assertEqual(self.widget.widgets['extension'].name,
    170                          'test.foo.extension')
    171         return
    172 
    173     def test_set_prefix_changed_no_dot(self):
    174         # when we try to set a name without trailing dot, one will be
    175         # inserted automatically
    176         self.widget.setPrefix('test')
    177         self.assertEqual(self.widget.name, 'test.foo')
    178         self.assertEqual(self.widget.widgets['country'].name,
    179                          'test.foo.country')
    180         self.assertEqual(self.widget.widgets['area'].name,
    181                          'test.foo.area')
    182         self.assertEqual(self.widget.widgets['extension'].name,
    183                          'test.foo.extension')
    184         return
    185 
    186     def test_get_input_value(self):
    187         # we get a string when we want the input value
    188         request = TestRequest(
    189             form={
    190                 'field.foo.country': '123',
    191                 'field.foo.area': '456',
    192                 'field.foo.extension': '12345'
    193                 })
    194         widget = PhoneWidget(self.field, request)
    195         value = widget.getInputValue()
    196         self.assertEqual(value, '123-456-12345')
    197         return
    198 
    199     def test_get_input_value_invalid(self):
    200         # we get errors when valid data is sent
    201         request = TestRequest(
    202             form={
    203                 'field.foo.country': 'not-a-number',
    204                 'field.foo.area': '456',
    205                 'field.foo.extension': '12345',
    206                 })
    207         widget = PhoneWidget(self.field, request)
    208         self.assertRaises(
    209             WidgetInputError,
    210             widget.getInputValue)
    211         return
    212 
    213     def test_apply_changes(self):
    214         # we can apply passed-in numbers to content objects. The
    215         # widget is smart enough to detect whether the values really
    216         # changed.
    217         class Content(object):
    218             field = None
    219         content = Content()
    220         request = TestRequest(form={
    221                 'field.foo.country': '123',
    222                 'field.foo.area': '456',
    223                 'field.foo.extension': '7890'})
    224         widget = PhoneWidget(self.field, request)
    225         result1 = widget.applyChanges(content)
    226         result2 = widget.applyChanges(content)
    227         self.assertEqual(result1, True)
    228         self.assertEqual(content.foo, u'123-456-7890')
    229         self.assertEqual(result2, False)
    230         return
    231 
    232     def test_has_input(self):
    233         # we can check whether there is input without actually validating.
    234         request = TestRequest(form={
    235                 'field.foo.country': '123'})
    236         widget = PhoneWidget(self.field, request)
    237         result = widget.hasInput()
    238         self.assertEqual(result, False)
    239 
    240         request = TestRequest(form={
    241                 'field.foo.area': '123'})
    242         widget = PhoneWidget(self.field, request)
    243         result = widget.hasInput()
    244         self.assertEqual(result, False)
    245 
    246         request = TestRequest(form={
    247                 'field.foo.extension': '123567'})
    248         widget = PhoneWidget(self.field, request)
    249         result = widget.hasInput()
    250         self.assertEqual(result, False)
    251 
    252         request = TestRequest(form={
    253                 'field.foo.country': '123',
    254                 'field.foo.area': '456',
    255                 'field.foo.extension': '7890'})
    256         widget = PhoneWidget(self.field, request)
    257         result = widget.hasInput()
    258         self.assertEqual(result, True)
    259 
    260         self.assertEqual(self.widget.hasInput(), False)
    261         return
    262 
    263     def test_has_valid_input(self):
    264         # we can check for input also including validation
    265         request = TestRequest(form={
    266                 'field.foo.country': '123'})
    267         widget = PhoneWidget(self.field, request)
    268         result = widget.hasValidInput()
    269         self.assertEqual(result, False)
    270 
    271         request = TestRequest(form={
    272                 'field.foo.area': '123'})
    273         widget = PhoneWidget(self.field, request)
    274         result = widget.hasValidInput()
    275         self.assertEqual(result, False)
    276 
    277         request = TestRequest(form={
    278                 'field.foo.extension': '123567'})
    279         widget = PhoneWidget(self.field, request)
    280         result = widget.hasValidInput()
    281         self.assertEqual(result, False)
    282 
    283         request = TestRequest(form={
    284                 'field.foo.country': '123',
    285                 'field.foo.area': '456',
    286                 'field.foo.extension': '7890'})
    287         widget = PhoneWidget(self.field, request)
    288         result = widget.hasValidInput()
    289         self.assertEqual(result, True)
    290 
    291         self.assertEqual(self.widget.hasValidInput(), False)
    292         return
    293 
    294     def test_hidden(self):
    295         # we can render output as hidden field(s)
    296         self.widget.setRenderedValue(u'123-456-1234567')
    297         self.assertEqual(
    298             self.widget.hidden(),
    299             (u'<input class="span2 hiddenType" id="field.foo.country"'
    300              u' name="field.foo.country" type="hidden" value="123" '
    301              u' />'
    302              u'\n'
    303              u'<input class="span2 hiddenType" id="field.foo.area"'
    304              u' name="field.foo.area" type="hidden" value="456" '
    305              u' />'
    306              u'\n'
    307              u'<input class="span3 hiddenType" id="field.foo.extension"'
    308              u' name="field.foo.extension" type="hidden"'
    309              u' value="1234567"  />'))
    310         return
    311 
    312     def test_error_extension(self):
    313         # the widget can handle input errors in extension subwidget
    314 
    315         # extension field too short
    316         request = TestRequest(form={
    317                 'field.foo.country': '123',
    318                 'field.foo.area': '456',
    319                 'field.foo.extension': '0'})
    320         widget = PhoneWidget(self.field, request)
    321         try:
    322             widget.getInputValue()
    323             self.fail('No error raised')
    324         except WidgetInputError, e:
    325             pass
    326         self.assertEqual(
    327             e.__repr__(),
    328             ("WidgetInputError("
    329              "'extension', u'Direct Line', ConstraintNotSatisfied(u'0'))"))
    330         self.assertEqual(
    331             widget.error(),
    332             u'<span class="error">Constraint not satisfied</span>')
    333         return
    334 
    335 
    336     def test_error_area(self):
    337         # the widget can handle input errors in area code subwidget
    338 
    339         # area code contains illegal chars
    340         request = TestRequest(form={
    341                 'field.foo.country': '123',
    342                 'field.foo.area': 'no-number',
    343                 'field.foo.extension': '12345'})
    344         widget = PhoneWidget(self.field, request)
    345         try:
    346             widget.getInputValue()
    347             self.fail('No error raised')
    348         except WidgetInputError, e:
    349             pass
    350         self.assertEqual(
    351             e.__repr__(),
    352             ("WidgetInputError("
    353              "'area', u'Area Code', ConstraintNotSatisfied(u'no-number'))"))
    354         self.assertEqual(
    355             widget.error(),
    356             u'<span class="error">Constraint not satisfied</span>')
    357         return
    358 
    359     def test_error_country(self):
    360         # the widget can handle input errors in country code subwidget
    361 
    362         # invalid country code
    363         request = TestRequest(form={
    364                 'field.foo.country': 'XXX',
    365                 'field.foo.area': '456',
    366                 'field.foo.extension': '12345'})
    367         widget = PhoneWidget(self.field, request)
    368         try:
    369             widget.getInputValue()
    370             self.fail('No error raised')
    371         except WidgetInputError, e:
    372             pass
    373         self.assertEqual(
    374             e.__repr__(),
    375             ("WidgetInputError("
    376              "'country', u'Country Code', ConstraintNotSatisfied(u'XXX'))"))
    377         self.assertEqual(
    378             widget.error(),
    379             u'<span class="error">Constraint not satisfied</span>')
    380         return
    381 
    382     def test_render_wo_data(self):
    383         # when no data was submitted, the content data will be displayed
    384         request = TestRequest(form={})
    385         self.content.foo = u'11-222-3333'
    386         widget = PhoneWidget(self.field, request)
    387         self.assertEqual(
    388             widget(),
    389             (u'+&nbsp;<input class="span2 textType" id="field.foo.country"'
    390              u' name="field.foo.country" size="20" type="text" value="11" '
    391              u' />'
    392              u'&nbsp;-\n'
    393              u'<input class="span2 textType" id="field.foo.area"'
    394              u' name="field.foo.area" size="20" type="text" value="222" '
    395              u' />'
    396              u'&nbsp;-\n'
    397              u'<input class="span3 textType" id="field.foo.extension"'
    398              u' name="field.foo.extension" size="20" type="text"'
    399              u' value="3333"  />\n'))
    400         return
    401 
    402     def test_render_with_data(self):
    403         # when data was in the request, it will override any content value
    404         request = TestRequest(form={
    405                 'field.foo.country': '11',
    406                 'field.foo.area': '222',
    407                 'field.foo.extension': '3333'})
    408         self.content.foo = u'22-333-4444'
    409         widget = PhoneWidget(self.field, request)
    410         self.assertEqual(
    411             widget(),
    412             (u'+&nbsp;<input class="span2 textType" id="field.foo.country"'
    413              u' name="field.foo.country" size="20" type="text" value="11" '
    414              u' />'
    415              u'&nbsp;-\n'
    416              u'<input class="span2 textType" id="field.foo.area"'
    417              u' name="field.foo.area" size="20" type="text" value="222" '
    418              u' />'
    419              u'&nbsp;-\n'
    420              u'<input class="span3 textType" id="field.foo.extension"'
    421              u' name="field.foo.extension" size="20" type="text"'
    422              u' value="3333"  />\n'))
    423         return
    424 
    425     def test_render_changed_prefix(self):
    426         # when the prefix is changed, the subwidgets will reflect that
    427         # properly. This tests a regression: if setPrefix was called
    428         # on the phone widget, the subwidgets were already assuming
    429         # that there is no data in the request
    430         request = TestRequest(form={
    431                 'field.foo.country': '11',
    432                 'field.foo.area': '222',
    433                 'field.foo.extension': '3333'})
    434         self.content.foo = u'22-333-4444'
    435         widget = PhoneWidget(self.field, request)
    436         # when setting a wrong prefix (not in the form), subwidgets
    437         # will display the content values assuming (correctly) there
    438         # is no data sent for them in the request.
    439         widget.setPrefix('not-existent.')
    440         self.assertTrue('value="4444"' in widget())
    441         # when setting the right prefix, subwidgets will display the
    442         # sent form values and not the content values.
    443         widget.setPrefix('field.')
    444         self.assertTrue('value="3333"' in widget())
    445         return
    446 
    447     def test_render_changed_prefix(self):
    448         # when the prefix is changed, the subwidgets will reflect that
    449         # properly. This tests a regression: if setPrefix was called
    450         # on the phone widget, the subwidgets were already assuming
    451         # that there is no data in the request
    452         request = TestRequest(form={
    453                 'field.foo.country': '11',
    454                 'field.foo.area': '222',
    455                 'field.foo.extension': '3333'})
    456         self.content.foo = u'22-333-4444'
    457         widget = PhoneWidget(self.field, request)
    458         # when setting a wrong prefix (not in the form), subwidgets
    459         # will display the content values assuming (correctly) there
    460         # is no data sent for them in the request.
    461         widget.setPrefix('not-existent.')
    462         self.assertTrue('value="4444"' in widget())
    463         # when setting the right prefix, subwidgets will display the
    464         # sent form values and not the content values.
    465         widget.setPrefix('field.')
    466         self.assertTrue('value="3333"' in widget())
    467         return
    468 
    469     def test_non_required_no_input(self):
    470         # if the bound field requires no input phone widget will cope
    471         # with that.
    472         class Content(object):
    473             field = None
    474 
    475         content = Content()
    476         request = TestRequest(form={
    477                 'field.bar.country': '',
    478                 'field.bar.area': '',
    479                 'field.bar.extension': '',
    480                 })
    481         widget = PhoneWidget(self.field_nonreq, request)
    482         result1 = widget.applyChanges(content)
    483         result2 = widget.getInputValue()
    484         self.assertEqual(result1, True)
    485         # without input we get None
    486         self.assertTrue(content.bar is None)
    487         self.assertTrue(result2 is None)
    488         return
    489 
    490     def test_set_rendered_with_empty_context_value(self):
    491         # if we set empty string as rendered value, empty fields are
    492         # displayed.
    493         self.widget.setRenderedValue(u'')
    494         self.assertEqual(
    495             self.widget(),
    496             (u'+&nbsp;<input class="span2 textType" id="field.foo.country"'
    497              u' name="field.foo.country" size="20" type="text" value="" '
    498              u' />'
    499              u'&nbsp;-\n'
    500              u'<input class="span2 textType" id="field.foo.area"'
    501              u' name="field.foo.area" size="20" type="text" value="" '
    502              u' />'
    503              u'&nbsp;-\n'
    504              u'<input class="span3 textType" id="field.foo.extension"'
    505              u' name="field.foo.extension" size="20" type="text"'
    506              u' value=""  />\n'))
    507         return
    508 
    509 import zope.formlib
    510 from zope import schema
    511 from zope.formlib.tests.test_functional_objectwidget import (
    512     Test, PlacelessSetup, VerifyResults, traversingSetUp, xmlconfig,
    513     PageTemplate, os, DefaultTraversable
    514     )
    515 from zope.formlib.tests.test_functional_textwidget import(
    516     FunctionalWidgetTestCase, patternExists)
    517 from zope.formlib.widgets import TextWidget
    518 from zope.component import adapts
    519 from zope.interface import implements
    520 from zope.traversing.interfaces import ITraversable
    521 from waeup.kofa.widgets.phonewidget import PhoneWidget2, PhonePrefixes
    52285
    52386class SampleForm(form.EditForm):
    52487    form_fields = form.fields(ISampleContent)
    525     form_fields['foo'].custom_widget = PhoneWidget2
    526     form_fields['bar'].custom_widget = PhoneWidget2
    527     form_fields['baz'].custom_widget = PhoneWidget2
     88    form_fields['foo'].custom_widget = PhoneWidget
     89    form_fields['bar'].custom_widget = PhoneWidget
     90    form_fields['baz'].custom_widget = PhoneWidget
    52891
    529 class PhoneWidget2Tests(FunctionalWidgetTestCase):
     92class PhoneWidgetTests(FunctionalWidgetTestCase):
    53093
    53194    widgets = [
     
    53699
    537100    def setUp(self):
    538         super(PhoneWidget2Tests, self).setUp()
     101        super(PhoneWidgetTests, self).setUp()
    539102        # register the phone prefixes utility
    540103        self.gsm = getGlobalSiteManager()
Note: See TracChangeset for help on using the changeset viewer.