Widgets


  Testing TupleTextAreaWidget:

    Set one up::

      >>> class DummyRequest(dict):
      ...     def __init__(self):
      ...         self.form = {}
      ...     def get(self, key):
      ...         return self.form.get(key)
      >>> request = DummyRequest()
      >>> request.form['PREFIX.NAME'] = u'FOO \n BAR'

      >>> from Products.CMFDefault.formlib.widgets import TupleInputWidget
      >>> from zope.schema import Tuple
      >>> tuple_field = Tuple(__name__='NAME', title=u'FIELD TITLE',
      ...                     required=False)

      >>> widget = TupleInputWidget(tuple_field, request)

    IWidget::

      >>> widget.name
      'field.NAME'
      >>> widget.label
      u'FIELD TITLE'
      >>> widget.hint
      u''
      >>> widget.visible
      True
      >>> widget.setRenderedValue(('BAZ',))
      >>> widget.setRenderedValue(widget._data_marker)
      >>> widget.setPrefix('PREFIX')
      >>> widget.name
      'PREFIX.NAME'

    IInputWidget::

      >>> widget.required
      False
      >>> widget.getInputValue()
      (u'FOO', u'BAR')
      >>> #widget.applyChanges(content)
      >>> widget.hasInput()
      True
      >>> widget.hasValidInput()
      True

    IBrowserWidget::

      >>> print widget()
      <textarea cols="60" id="PREFIX.NAME" name="PREFIX.NAME" rows="15" >FOO
      BAR</textarea>
      >>> #print widget.hidden()
      >>> print widget.error()

    Missing input::

      >>> request.form['PREFIX.NAME'] = u' \n '
      >>> print widget.getInputValue()
      None


  Testing SubjectInputWidget:

    Set one up::

      >>> from zope.component import getSiteManager
      >>> from Products.CMFCore.interfaces import IMetadataTool
      >>> class DummyTool:
      ...     def listAllowedSubjects(self, context): return ('SPAM', 'EGGS')
      >>> class DummyView: pass
      >>> view = DummyView()
      >>> view.portal_metadata = DummyTool()
      >>> getSiteManager().registerUtility(view.portal_metadata, IMetadataTool)

      >>> request = DummyRequest()
      >>> request.form['PREFIX.NAME.1'] = ['EGGS']
      >>> request.form['PREFIX.NAME'] = u'FOO \n BAR \n SPAM'

      >>> from Products.CMFDefault.formlib.widgets import SubjectInputWidget
      >>> from zope.schema import Set
      >>> set_field = Set(__name__='NAME', title=u'FIELD TITLE').bind(view)

      >>> widget = SubjectInputWidget(set_field, request)

    IWidget::

      >>> widget.name
      'field.NAME'
      >>> widget.label
      u'FIELD TITLE'
      >>> widget.hint
      u''
      >>> widget.visible
      True
      >>> widget.setRenderedValue(('BAZ',))
      >>> widget.setRenderedValue(widget._data_marker)
      >>> widget.setPrefix('PREFIX')
      >>> widget.name
      'PREFIX.NAME'

    IInputWidget::

      >>> widget.required
      True
      >>> widget.getInputValue()
      set([u'EGGS', u'FOO', u'BAR', u'SPAM'])
      >>> #widget.applyChanges(content)
      >>> widget.hasInput()
      True
      >>> widget.hasValidInput()
      True

    IBrowserWidget::

      >>> print widget()
      <div>
      <div class="value">
      <select id="PREFIX.NAME.1" multiple="multiple" name="PREFIX.NAME.1:list"
      size="3" ><option selected="selected" value="SPAM">SPAM</option>
      <option selected="selected" value="EGGS">EGGS</option></select>
      </div>
      <input name="PREFIX.NAME.1-empty-marker" type="hidden" value="1" />
      </div>
      <textarea cols="60" id="PREFIX.NAME" name="PREFIX.NAME"
      rows="2" >FOO BAR</textarea>
