[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_vocabularywidget.py:1.1.2.7

Fred L. Drake, Jr. fred@zope.com
Tue, 6 May 2003 12:17:54 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv28688

Modified Files:
      Tag: schema-vocabulary-branch
	test_vocabularywidget.py 
Log Message:
added tests for:
- display widget for multi-selection vocabulary fields
- hidden() support for single- and multi-select edit fields for vocabularies


=== Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py 1.1.2.6 => 1.1.2.7 ===
--- Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py:1.1.2.6	Mon May  5 16:12:25 2003
+++ Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py	Tue May  6 12:17:53 2003
@@ -125,6 +125,10 @@
                     IBrowserPresentation,
                     widget.VocabularyEditWidget)
         provideView(vocabulary.IVocabulary,
+                    "field-display-multi-widget",
+                    IBrowserPresentation,
+                    widget.VocabularyMultiDisplayWidget)
+        provideView(vocabulary.IVocabulary,
                     "field-edit-multi-widget",
                     IBrowserPresentation,
                     widget.VocabularyMultiEditWidget)
@@ -217,6 +221,74 @@
         w = getView(bound, "edit", request)
         self.assert_(w.haveData())
         self.assertEqual(w._showData(), "foobar")
+        self.assert_(isinstance(w, widget.VocabularyEditWidget))
+        self._verifyResult(w.hidden(), [
+            '<input',
+            'id="field.myfield"',
+            'name="field.myfield"',
+            'value="foobar"',
+            ])
+
+    def test_multi_display_without_value(self):
+        field, bound = self.makeFields(vocabulary.VocabularyMultiField,
+                                       BasicVocabulary(["splat", "foobar",
+                                                        "frob"]),
+                                       None)
+        w = getView(bound, "display", TestRequest())
+        self.assert_(not w.haveData())
+        self._verifyResult(w(), [
+            '<span',
+            'id="field.myfield"',
+            'name="field.myfield"',
+            'class="vocabularyType"',
+            '</span>',
+            ])
+
+    def test_multi_display_with_value(self):
+        field, bound = self.makeFields(vocabulary.VocabularyMultiField,
+                                       BasicVocabulary(["splat", "foobar",
+                                                        "frob"]),
+                                       ["foobar", "frob"])
+        w = getView(bound, "display", TestRequest())
+        self.assert_(not w.haveData())
+        self._verifyResult(w(), [
+            '<ol',
+            'id="field.myfield"',
+            'name="field.myfield"',
+            'class="vocabularyType"',
+            '</ol>',
+            ])
+        w.cssClass = 'test'
+        s = w.renderItems(['foobar'])[0]
+        self._verifyResult(s, [
+            '<li',
+            'class="test-item"',
+            '>foobar<',
+            '</li>',
+            ])
+
+    def test_multi_display_with_form_data(self):
+        field, bound = self.makeFields(vocabulary.VocabularyMultiField,
+                                       BasicVocabulary(["splat", "foobar",
+                                                        "frob"]),
+                                       ["foobar", "frob"])
+        request = TestRequest(QUERY_STRING='field.myfield:list=splat')
+        request.processInputs()
+        w = getView(bound, "display", request)
+        self.assert_(w.haveData())
+        s = w()
+        self._verifyResult(s, [
+            '<ol',
+            'id="field.myfield"',
+            'name="field.myfield"',
+            'class="vocabularyType"',
+            '<li',
+            '>splat<',
+            '</li>',
+            '</ol>',
+            ])
+        self.assert_(s.find("foobar") < 0)
+        self.assert_(s.find("frob") < 0)
 
     def test_multi_edit(self):
         field, bound = self.makeFields(vocabulary.VocabularyMultiField,
@@ -263,6 +335,13 @@
         L = w._showData()
         L.sort()
         self.assertEqual(L, ["foobar", "splat"])
+        self._verifyResult(w.hidden(), [
+            '<input',
+            'type="hidden"',
+            'name="field.myfield:list"',
+            'value="foobar"',
+            'value="splat"',
+            ])
 
 
 def test_suite():