web/test/unittest_formwidgets.py
changeset 8029 805d4e121b65
parent 6781 5062d86d6ffe
child 8665 e65af61bde7d
--- a/web/test/unittest_formwidgets.py	Thu Oct 27 10:38:03 2011 +0200
+++ b/web/test/unittest_formwidgets.py	Thu Oct 27 10:38:16 2011 +0200
@@ -32,7 +32,7 @@
 
 class WidgetsTC(TestCase):
 
-    def test_state_fields(self):
+    def test_editableurl_widget(self):
         field = formfields.guess_field(schema['Bookmark'], schema['path'])
         widget = formwidgets.EditableURLWidget()
         req = fake.FakeRequest(form={'path-subjectfqs:A': 'param=value&vid=view'})
@@ -40,5 +40,21 @@
         self.assertEqual(widget.process_field_data(form, field),
                          '?param=value%26vid%3Dview')
 
+    def test_bitselect_widget(self):
+        field = formfields.guess_field(schema['CWAttribute'], schema['ordernum'])
+        field.choices = [('un', '1',), ('deux', '2',)]
+        widget = formwidgets.BitSelect(settabindex=False)
+        req = fake.FakeRequest(form={'ordernum-subject:A': ['1', '2']})
+        form = mock(_cw=req, formvalues={}, edited_entity=mock(eid='A'),
+                    form_previous_values=())
+        self.assertMultiLineEqual(widget._render(form, field, None),
+                             '''\
+<select id="ordernum-subject:A" multiple="multiple" name="ordernum-subject:A" size="2">
+<option selected="selected" value="2">deux</option>
+<option selected="selected" value="1">un</option>
+</select>''')
+        self.assertEqual(widget.process_field_data(form, field),
+                         3)
+
 if __name__ == '__main__':
     unittest_main()