[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - __init__.py:1.1.2.1 test_add.py:1.1.2.1 test_browserwidget.py:1.1.2.1 test_checkboxwidget.py:1.1.2.1 test_editview.py:1.1.2.1 test_filewidget.py:1.1.2.1 test_listwidget.py:1.1.2.1 test_multicheckboxwidget.py:1.1.2.1 test_multilistwidget.py:1.1.2.1 test_passwordwidget.py:1.1.2.1 test_radiowidget.py:1.1.2.1 test_setprefix.py:1.1.2.1 test_textareawidget.py:1.1.2.1 test_textwidget.py:1.1.2.1 testconfigure.zcml:1.1.2.1 testeditform.pt:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:31:10 -0500


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

Added Files:
      Tag: NameGeddon-branch
	__init__.py test_add.py test_browserwidget.py 
	test_checkboxwidget.py test_editview.py test_filewidget.py 
	test_listwidget.py test_multicheckboxwidget.py 
	test_multilistwidget.py test_passwordwidget.py 
	test_radiowidget.py test_setprefix.py test_textareawidget.py 
	test_textwidget.py testconfigure.zcml testeditform.pt 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/browser/form/tests/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/browser/form/tests/test_add.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""

$Id: test_add.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.add import add, AddViewFactory, AddView
from zope.interface import Interface
from zope.schema import TextLine
from zope.app.interfaces.container import IAdding
from zope.app.form.widget import CustomWidget
from zope.app.browser.form.widget import TextWidget as Text
from zope.publisher.browser import TestRequest
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.component import getView

class Context:

    def resolve(self, name):
        return globals()[name]

class I(Interface):
    
    name = TextLine()
    first = TextLine()
    last = TextLine()
    email = TextLine()
    address = TextLine()
    foo = TextLine()
    extra1 = TextLine()
    extra2 = TextLine()

class C:

    def __init__(self, *args, **kw):
        self.args = args
        self.kw = kw

class V:
    name = CustomWidget(Text)
    first = CustomWidget(Text)
    last = CustomWidget(Text)
    email = CustomWidget(Text)
    address = CustomWidget(Text)
    foo = CustomWidget(Text)
    extra1 = CustomWidget(Text)
    extra2 = CustomWidget(Text)

    
class SampleData:

    name = "foo"
    first = "bar"
    last = "baz"
    email = "baz@dot.com"
    address = "aa"
    foo = "foo"
    extra1 = "extra1"
    extra2 = "extra2"

class Test(PlacelessSetup, TestCase):

    def test_add_no_fields(self):

        result1 = add(
            Context(),
            schema="I",
            name="addthis",
            permission="Zope.Public",
            label="Add this",
            content_factory="C",
            arguments="first last",
            keyword_arguments="email",
            set_before_add="foo",
            set_after_add="extra1",
            )

        result2 = add(
            Context(),
            schema="I",
            name="addthis",
            permission="Zope.Public",
            label="Add this",
            content_factory="C",
            arguments="first last",
            keyword_arguments="email",
            set_before_add="foo",
            set_after_add="extra1",
            fields="name first last email address foo extra1 extra2",
            )

        self.assertEqual(result1, result2)

    def test_add(self):

        [(descriminator, callable, args, kw)] = add(
            Context(),
            schema="I",
            name="addthis",
            permission="Zope.Public",
            label="Add this",
            content_factory="C",
            class_="V",
            arguments="first last",
            keyword_arguments="email",
            set_before_add="foo",
            set_after_add="extra1",
            )


        self.assertEqual(descriminator,
                         ('http://namespaces.zope.org/form/add',
                          "addthis", "default"))
        self.assertEqual(callable, AddViewFactory)

        (name, schema, label, permission, layer, template,
         default_template, bases, for_, fields, content_factory,
         arguments, keyword_arguments, set_before_add,
         set_after_add)  = args

        self.assertEqual(name, 'addthis')
        self.assertEqual(schema, I)
        self.assertEqual(label, 'Add this')
        self.assertEqual(permission, 'Zope.Public')
        self.assertEqual(layer, 'default')
        self.assertEqual(template, 'edit.pt')
        self.assertEqual(default_template, 'edit.pt')
        self.assertEqual(bases, (V, AddView, ))
        self.assertEqual(for_, IAdding)
        self.assertEqual(" ".join(fields),
                         "name first last email address foo extra1 extra2")
        self.assertEqual(content_factory, C)
        self.assertEqual(" ".join(arguments), 
                         "first last")
        self.assertEqual(" ".join(keyword_arguments), 
                         "email")
        self.assertEqual(" ".join(set_before_add), 
                         "foo")
        self.assertEqual(" ".join(set_after_add), 
                         "extra1 name address extra2")
        self.failIf(kw)

        return args

    def test_apply_update(self):

        class Adding:

            __implements__ = IAdding

            def __init__(self, test):
                self.test = test
            
            def add(self, ob):
                self.ob = ob
                self.test.assertEqual(
                    ob.__dict__,
                    {'args': ("bar", "baz"),
                     'kw': {'email': 'baz@dot.com'},
                     'foo': 'foo',
                    })
                return ob
            def nextURL(self):
                return "."
            
        adding = Adding(self)
        args = self.test_add()
        factory = AddViewFactory(*args)
        request = TestRequest()
        request.form.update(SampleData.__dict__)
        view = getView(adding, 'addthis', request)
        view.apply_update(SampleData.__dict__)

        self.assertEqual(adding.ob.extra1, "extra1")
        self.assertEqual(adding.ob.extra2, "extra2")
        self.assertEqual(adding.ob.name, "foo")
        self.assertEqual(adding.ob.address, "aa")

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_browserwidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: test_browserwidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
import unittest
from zope.app.browser.form.widget import BrowserWidget
from zope.publisher.browser import TestRequest
from zope.schema import Text

class BrowserWidgetTest(unittest.TestCase):

    _WidgetFactory = BrowserWidget

    def setUp(self):
        field = Text(__name__ = 'foo', title = u"Foo Title")
        request = TestRequest()
        request.form['field.foo'] = u'Foo Value'
        self._widget = self._WidgetFactory(field, request)

    def _verifyResult(self, result, check_list):
        for check in check_list:
            self.assertNotEqual(-1, result.find(check),
                                '"'+check+'" not found in "'+result+'"')

    def test_required(self):
        self._widget.context.required = False
        self.failIf(self._widget.required)
        self._widget.context.required = True
        self.failUnless(self._widget.required)

    def test_haveData(self):
        self.failUnless(self._widget.haveData())
        del self._widget.request.form['field.foo']
        self.failIf(self._widget.haveData())

    def testProperties(self):
        self.assertEqual(self._widget.getValue('tag'), 'input')
        self.assertEqual(self._widget.getValue('type'), 'text')
        self.assertEqual(self._widget.getValue('cssClass'), '')
        self.assertEqual(self._widget.getValue('extra'), '')

    def testRender(self):
        value = 'Foo Value'
        check_list = ('type="text"', 'name="field.foo"', 'value="Foo Value"')
        self._verifyResult(self._widget.render(value), check_list)
        check_list = ('type="hidden"',) + check_list[1:]
        self._verifyResult(self._widget.renderHidden(value), check_list)
        check_list = ('type="hidden"', 'style="color: red"') + check_list[1:]
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.renderHidden(value), check_list)

    def testLabel(self):
        label = ' '.join(self._widget.label().strip().split())
        self.assertEqual(label, '<label for="field.foo">Foo Title</label>')

    def testRow(self):
        self._widget.request.form.clear()
        label = ''.join(self._widget.label().strip().split())
        value = ''.join(self._widget().strip().split())
        row = ''.join(self._widget.row().strip().split())
        self.assertEqual(row, '<td>%s</td><td>%s</td>' % (label, value))

class TestWidget(BrowserWidget):

    def _convert(self, v):
        return v or None

class Test(BrowserWidgetTest):

    _WidgetFactory = TestWidget

    def test_showData(self):

        class W(BrowserWidget):
            def _convert(self, v):
                return u'X' + (v or '')

            def _unconvert(self, v):
                return v and v[1:] or ''

        field = Text(__name__ = 'foo', title = u"Foo Title")
        request = TestRequest()

        w = W(field, request)
        self.assertEqual(w._showData(), '')
        request.form['field.foo'] = 'val'
        self.assertEqual(w._showData(), 'val')

        w.setData('Xfoo')
        self.assertEqual(w._showData(), 'foo')        

    def test_haveData(self):
        self.failUnless(self._widget.haveData())
        del self._widget.request.form['field.foo']
        self.failIf(self._widget.haveData())
        self._widget.request.form['field.foo'] = u''
        self.failIf(self._widget.haveData())

    def test_showData_w_default(self):
        field = Text(__name__ = 'foo', title = u"Foo Title", default=u"def")
        request = TestRequest()
        widget = self._WidgetFactory(field, request)
        self.assertEqual(widget._showData(), u'def')
        

def test_suite():
    return unittest.makeSuite(Test)

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_checkboxwidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import CheckBoxWidget

from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest


class CheckBoxWidgetTest(BrowserWidgetTest):

    _WidgetFactory = CheckBoxWidget

    def testProperties(self):
        self.assertEqual(self._widget.getValue('tag'), 'input')
        self.assertEqual(self._widget.getValue('type'), 'checkbox')
        self.assertEqual(self._widget.getValue('cssClass'), '')
        self.assertEqual(self._widget.getValue('extra'), '')
        self.assertEqual(self._widget.getValue('default'), 0)

    def testRender(self):
        value = 1
        check_list = ('type="checkbox"', 'name="field.foo"',
                      'checked="checked"')
        self._verifyResult(self._widget.render(value), check_list)
        value = 0
        check_list = check_list[:-1]
        self._verifyResult(self._widget.render(value), check_list)
        check_list = ('type="hidden"',) + check_list[1:-1]
        self._verifyResult(self._widget.renderHidden(value), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.renderHidden(value), check_list)



def test_suite():
    return makeSuite(CheckBoxWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_editview.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""$Id: test_editview.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.app.event.tests.placelesssetup import getEvents
from zope.interface import Interface
from zope.schema import TextLine
from zope.schema.interfaces import ITextLine
from zope.publisher.browser import TestRequest
from zope.publisher.interfaces.browser import IBrowserPresentation
from zope.app.browser.form.editview import EditView
from zope.component.view \
     import provideView, setDefaultViewName
from zope.app.browser.form.widget import TextWidget
from zope.app.browser.form.submit import Update

class I(Interface):
    foo = TextLine(title=u"Foo")
    bar = TextLine(title=u"Bar")
    a   = TextLine(title=u"A")
    b   = TextLine(title=u"B")
    baz = TextLine(title=u"Baz")

class EV(EditView):
    schema = I

class C:
    foo = u"c foo"
    bar = u"c bar"
    a   = u"c a"
    b   = u"c b"
    baz = u"c baz"

class Test(PlacelessSetup, TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        provideView(ITextLine, 'edit', IBrowserPresentation, TextWidget)
        setDefaultViewName(ITextLine, IBrowserPresentation, "edit")

    def test_setPrefix_and_widgets(self):
        v = EV(C(), TestRequest())
        v.setPrefix("test")
        self.assertEqual(
            [w.name for w in v.widgets()],
            ['test.foo', 'test.bar', 'test.a', 'test.b', 'test.baz']
            )

    def test_apply_update_no_data(self):
        c = C()
        request = TestRequest()
        v = EV(c, request)
        d = {}
        d['foo'] = u'c foo'
        d['bar'] = u'c bar'
        d['baz'] = u'c baz'
        self.failUnless(v.apply_update(d))
        self.assertEqual(c.foo, u'c foo')
        self.assertEqual(c.bar, u'c bar')
        self.assertEqual(c.a  , u'c a')
        self.assertEqual(c.b  , u'c b')
        self.assertEqual(c.baz, u'c baz')
        self.failIf(getEvents())

    def test_apply_update(self):
        c = C()
        request = TestRequest()
        v = EV(c, request)
        d = {}
        d['foo'] = u'd foo'
        d['bar'] = u'd bar'
        d['baz'] = u'd baz'
        self.failIf(v.apply_update(d))
        self.assertEqual(c.foo, u'd foo')
        self.assertEqual(c.bar, u'd bar')
        self.assertEqual(c.a  , u'c a')
        self.assertEqual(c.b  , u'c b')
        self.assertEqual(c.baz, u'd baz')        
        self.failUnless(getEvents(filter=lambda event: event.object == c))

    def test_update_no_update(self):
        c = C()
        request = TestRequest()
        v = EV(c, request)
        self.assertEqual(v.update(), '')
        self.assertEqual(c.foo, u'c foo')
        self.assertEqual(c.bar, u'c bar')
        self.assertEqual(c.a  , u'c a')
        self.assertEqual(c.b  , u'c b')
        self.assertEqual(c.baz, u'c baz')
        request.form['field.foo'] = u'r foo'
        request.form['field.bar'] = u'r bar'
        request.form['field.a']   = u'r a'
        request.form['field.b']   = u'r b'
        request.form['field.baz'] = u'r baz'
        self.assertEqual(v.update(), '')
        self.assertEqual(c.foo, u'c foo')
        self.assertEqual(c.bar, u'c bar')
        self.assertEqual(c.a  , u'c a')
        self.assertEqual(c.b  , u'c b')
        self.assertEqual(c.baz, u'c baz')
        self.failIf(getEvents())

    def test_update(self):
        c = C()
        request = TestRequest()
        v = EV(c, request)
        request.form[Update] = ''
        request.form['field.foo'] = u'r foo'
        request.form['field.bar'] = u'r bar'
        request.form['field.baz'] = u'r baz'
        message = v.update()
        self.failUnless(message.startswith('Updated '), message)
        self.assertEqual(c.foo, u'r foo')
        self.assertEqual(c.bar, u'r bar')
        self.assertEqual(c.a  , u'c a')
        self.assertEqual(c.b  , u'c b')
        self.assertEqual(c.baz, u'r baz')

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_filewidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_filewidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import FileWidget
from StringIO import StringIO

from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest

class FileWidgetTest(BrowserWidgetTest):

    _WidgetFactory = FileWidget

    def setUp(self):        
        BrowserWidgetTest.setUp(self)

        file = StringIO('Foo Value')
        file.filename = 'test.txt'
        self._widget.request.form['field.foo'] = file

    def testProperties(self):
        self.assertEqual(self._widget.getValue('tag'), 'input')
        self.assertEqual(self._widget.getValue('type'), 'file')
        self.assertEqual(self._widget.getValue('cssClass'), '')
        self.assertEqual(self._widget.getValue('extra'), '')
        self.assertEqual(self._widget.getValue('default'), '')
        self.assertEqual(self._widget.getValue('displayWidth'), 20)
        self.assertEqual(self._widget.getValue('displayMaxWidth'), '')

    def testRender(self):
        value = 'Foo Value'
        check_list = ('type="file"', 'name="field.foo"', 'size="20"')
        self._verifyResult(self._widget.render(value), check_list)
        check_list = ('type="hidden"',) + check_list[1:-1]
        self._verifyResult(self._widget.renderHidden(value), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.renderHidden(value), check_list)



def test_suite():
    return makeSuite(FileWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_listwidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_listwidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import ListWidget

from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest

class ListWidgetTest(BrowserWidgetTest):

    def setUp(self):
        BrowserWidgetTest.setUp(self)
        self._widget.context.allowed_values = (u'foo', u'bar')

    _WidgetFactory = ListWidget

    def testProperties(self):
        self.assertEqual(self._widget.getValue('cssClass'), "")
        self.assertEqual(self._widget.getValue('extra'), '')
        self.assertEqual(self._widget.getValue('firstItem'), 0)
        self.assertEqual(self._widget.getValue('size'), 5)


    def testRenderItem(self):
        check_list = ('option', 'value="foo"', 'Foo')
        self._verifyResult(
            self._widget.renderItem('Foo', 'foo', 'field.bar', None),
            check_list)
        check_list += ('selected="selected"',)
        self._verifyResult(
            self._widget.renderSelectedItem('Foo', 'foo', 'field.bar', None),
            check_list)


    def testRenderItems(self):
        check_list = ('option', 'value="foo"', 'bar',
                      'value="foo"', 'foo', 'selected="selected"')
        self._verifyResult('\n'.join(self._widget.renderItems('foo')),
                           check_list)


    def testRender(self):
        value = 'foo'
        check_list = ('select', 'name="field.foo"', 'size="5"', 
                      'option', 'value="foo"', '>foo<',
                      'value="foo"', '>bar<', 'selected="selected"')
        self._verifyResult(self._widget.render(value), check_list)

        check_list = ('type="hidden"', 'name="field.foo"', 'value="foo"')
        self._verifyResult(self._widget.renderHidden(value), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.renderHidden(value), check_list)



def test_suite():
    return makeSuite(ListWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_multicheckboxwidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_multicheckboxwidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import MultiCheckBoxWidget

from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest

class MultiCheckBoxWidgetTest(BrowserWidgetTest):

    _WidgetFactory = MultiCheckBoxWidget

    def setUp(self):
        BrowserWidgetTest.setUp(self)
        self._widget.context.allowed_values = (u'foo', u'bar')

    def testProperties(self):
        self.assertEqual(self._widget.getValue('cssClass'), "")
        self.assertEqual(self._widget.getValue('extra'), '')
        self.assertEqual(self._widget.getValue('orientation'), 'vertical')


    def testRenderItem(self):
        check_list = ('type="checkbox"', 'name="field.bar"', 'value="foo"',
                      'Foo')
        self._verifyResult(
            self._widget.renderItem('Foo', 'foo', 'field.bar', None),
            check_list)
        check_list += ('checked="checked"',)
        self._verifyResult(
            self._widget.renderSelectedItem('Foo', 'foo', 'field.bar', None),
            check_list)


    def testRenderItems(self):
        check_list = ('type="checkbox"', 'name="field.foo"', 'value="bar"',
                      'bar', 'value="foo"', 'foo', 'checked="checked"')
        self._verifyResult('\n'.join(self._widget.renderItems('bar')),
                           check_list)


    def testRender(self):
        value = 'bar'
        check_list = ('type="checkbox"', 'name="field.foo"', 'value="bar"',
                      'bar', 'value="foo"', 'foo', 'checked="checked"')
        self._verifyResult(self._widget.render(value), check_list)

        check_list = ('type="hidden"', 'name="field.foo"', 'value="bar"')
        self._verifyResult(self._widget.renderHidden(value), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.renderHidden(value), check_list)


def test_suite():
    return makeSuite(MultiCheckBoxWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_multilistwidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_multilistwidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import MultiListWidget

from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest

class MultiListWidgetTest(BrowserWidgetTest):

    _WidgetFactory = MultiListWidget

    def setUp(self):
        BrowserWidgetTest.setUp(self)
        self._widget.context.allowed_values = (u'foo', u'bar')

    def testProperties(self):
        self.assertEqual(self._widget.getValue('cssClass'), "")
        self.assertEqual(self._widget.getValue('extra'), '')
        self.assertEqual(self._widget.getValue('size'), 5)


    def testRenderItem(self):
        check_list = ('option', 'value="foo"', 'Foo')
        self._verifyResult(
            self._widget.renderItem('Foo', 'foo', 'field.bar', None),
            check_list)
        check_list += ('selected="selected"',)
        self._verifyResult(
            self._widget.renderSelectedItem('Foo', 'foo', 'field.bar', None),
            check_list)


    def testRenderItems(self):
        check_list = ('option', 'value="foo"', 'bar',
                      'value="foo"', 'foo', 'selected="selected"')
        self._verifyResult('\n'.join(self._widget.renderItems('foo')),
                           check_list)


    def testRender(self):
        value = 'foo'
        check_list = ('select', 'name="field.foo"', 'size="5"', 
                      'option', 'value="foo"', '>foo<',
                      'value="foo"', '>bar<', 'selected="selected"',
                      'multiple="multiple"')
        self._verifyResult(self._widget.render(value), check_list)

        check_list = ('type="hidden"', 'name="field.foo"', 'value="foo"')
        self._verifyResult(self._widget.renderHidden(value), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.renderHidden(value), check_list)



def test_suite():
    return makeSuite(MultiListWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_passwordwidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_passwordwidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import PasswordWidget

from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest


class PasswordWidgetTest(BrowserWidgetTest):

    _WidgetFactory = PasswordWidget

    def testProperties(self):
        self.assertEqual(self._widget.getValue('tag'), 'input')
        self.assertEqual(self._widget.getValue('type'), 'password')
        self.assertEqual(self._widget.getValue('cssClass'), '')
        self.assertEqual(self._widget.getValue('extra'), '')
        self.assertEqual(self._widget.getValue('default'), '')
        self.assertEqual(self._widget.getValue('displayWidth'), 20)
        self.assertEqual(self._widget.getValue('displayMaxWidth'), '')

    def testRender(self):
        value = 'Foo Value'
        check_list = ('type="password"', 'name="field.foo"',
                      'value="Foo Value"', 'size="20"')
        self._verifyResult(self._widget.render(value), check_list)
        check_list = ('type="hidden"',) + check_list[1:-1]
        self._verifyResult(self._widget.renderHidden(value), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.renderHidden(value), check_list)



def test_suite():
    return makeSuite(PasswordWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_radiowidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_radiowidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import RadioWidget

from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest

class RadioWidgetTest(BrowserWidgetTest):

    _WidgetFactory = RadioWidget

    def setUp(self):
        BrowserWidgetTest.setUp(self)
        self._widget.context.allowed_values = (u'foo', u'bar')

    def testProperties(self):
        self.assertEqual(self._widget.getValue('cssClass'), "")
        self.assertEqual(self._widget.getValue('extra'), '')
        self.assertEqual(self._widget.getValue('firstItem'), 0)
        self.assertEqual(self._widget.getValue('orientation'), 'vertical')


    def testRenderItem(self):
        check_list = ('type="radio"', 'name="field.bar"', 'value="foo"',
                      'Foo')
        self._verifyResult(
            self._widget.renderItem('Foo', 'foo', 'field.bar', None),
            check_list)
        check_list += ('checked="checked"',)
        self._verifyResult(
            self._widget.renderSelectedItem('Foo', 'foo', 'field.bar', None),
            check_list)


    def testRenderItems(self):
        check_list = ('type="radio"', 'name="field.foo"', 'value="bar"',
                      'bar', 'value="foo"', 'foo', 'checked="checked"')
        self._verifyResult('\n'.join(self._widget.renderItems('bar')),
                           check_list)


    def testRender(self):
        value = 'bar'
        check_list = ('type="radio"', 'name="field.foo"', 'value="bar"',
                      'bar', 'value="foo"', 'foo', 'checked="checked"')
        self._verifyResult(self._widget.render(value), check_list)

        check_list = ('type="hidden"', 'name="field.foo"', 'value="bar"')
        self._verifyResult(self._widget.renderHidden(value), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.renderHidden(value), check_list)



def test_suite():
    return makeSuite(RadioWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_setprefix.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_setprefix.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import TextWidget
from zope.publisher.browser import TestRequest
from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest
from zope.schema import Text


class Test(TestCase):
    
    def setUp(self):
        field = Text(__name__ = 'foo')
        request = TestRequest()
        request.form['spam.foo'] = u'Foo Value'
        self._widget = TextWidget(field, request)
        self._widget.setPrefix('spam')

    def testGetData(self):
        self.assertEqual(self._widget.getData(), u'Foo Value')

    def testRender(self):
        value = 'Foo Value 2'
        check_list = ('type="text"', 'name="spam.foo"', 'value="Foo Value 2"',
                      'size="20"')
        self._widget.setData(value)
        self._verifyResult(self._widget(), check_list)
        check_list = ('type="hidden"',) + check_list[1:-1]
        self._verifyResult(self._widget.hidden(), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.hidden(), check_list)

    def _verifyResult(self, result, check_list):
        for check in check_list:
            self.assertNotEqual(-1, result.find(check),
                                '"'+check+'" not found in "'+result+'"')



def test_suite():
    return makeSuite(Test)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_textareawidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_textareawidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import TextAreaWidget

from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest


class TextAreaWidgetTest(BrowserWidgetTest):

    _WidgetFactory = TextAreaWidget

    def testProperties(self):
        self.assertEqual(self._widget.getValue('tag'), 'input')
        self.assertEqual(self._widget.getValue('type'), 'text')
        self.assertEqual(self._widget.getValue('cssClass'), '')
        self.assertEqual(self._widget.getValue('extra'), '')
        self.assertEqual(self._widget.getValue('width'), 60)
        self.assertEqual(self._widget.getValue('height'), 15)

    def testRender(self):
        value = "Foo Value"
        check_list = ('rows="15"', 'cols="60"', 'name="field.foo"', 'textarea')
        self._verifyResult(self._widget.render(value), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.render(value), check_list)
        check_list = ('type="hidden"', 'name="field.foo"', 'value="Foo Value"')
        self._verifyResult(self._widget.renderHidden(value), check_list)

    def testRow(self):
        self._widget.request.form.clear()
        label = ''.join(self._widget.label().strip().split())
        value = ''.join(self._widget().strip().split())
        row = ''.join(self._widget.row().strip().split())
        self.assertEqual(row,
                         '<tdcolspan="2">%s<br/>%s</td>' % (label, value))



def test_suite():
    return makeSuite(TextAreaWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/test_textwidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_textwidget.py,v 1.1.2.1 2002/12/23 19:31:08 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.form.widget import TextWidget

from zope.app.browser.form.tests.test_browserwidget import BrowserWidgetTest


class TextWidgetTest(BrowserWidgetTest):

    _WidgetFactory = TextWidget
    
    def testProperties(self):
        self.assertEqual(self._widget.getValue('tag'), 'input')
        self.assertEqual(self._widget.getValue('type'), 'text')
        self.assertEqual(self._widget.getValue('cssClass'), '')
        self.assertEqual(self._widget.getValue('extra'), '')
        self.assertEqual(self._widget.getValue('default'), '')
        self.assertEqual(self._widget.getValue('displayWidth'), 20)
        self.assertEqual(self._widget.getValue('displayMaxWidth'), '')

    def testRender(self):
        value = 'Foo Value'
        check_list = ('type="text"', 'name="field.foo"', 'value="Foo Value"',
                      'size="20"')
        self._verifyResult(self._widget.render(value), check_list)
        check_list = ('type="hidden"',) + check_list[1:-1]
        self._verifyResult(self._widget.renderHidden(value), check_list)
        check_list = ('style="color: red"',) + check_list
        self._widget.extra = 'style="color: red"'
        self._verifyResult(self._widget.renderHidden(value), check_list)



def test_suite():
    return makeSuite(TextWidgetTest)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/browser/form/tests/testconfigure.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:browser='http://namespaces.zope.org/browser'
>

  <!-- Test view for folders -->
  <browser:view
      permission="Zope.View" 
      for="zope.app.content.folder.IFolder"  
      factory=".SchemaTestObject.EditFactory">
      <browser:page name="testSchemaFormView.html" attribute="form" />
      <browser:page name="testSchemaFormAction.html" attribute="action" />
  </browser:view>

</zopeConfigure>


=== Added File Zope3/src/zope/app/browser/form/tests/testeditform.pt ===
<html>
  <head>
    <title>Simple Edit Form</title>
  </head>

  <body>

    <h1>This is a Schema produced form</h1>

    <div tal:condition="python: options.has_key('errors') and 
                                options['errors']">
      <span style="font-weight: bold">Errors:</span>
      <div tal:repeat="error options/errors | nothing">
        <span tal:replace="python: error[0].title" />: 
        <span tal:replace="python: error[1].error_name" />
      </div>
    </div>
    <br />
    <form action="testSchemaFormAction.html" method="post">
      <input type="hidden" name="nextURL" value=""
          tal:attributes="value request/URL" />   
      <table>

        <tal:block repeat="field view/getFields">
          <tr>
            <th tal:content="field/title">Title:</th>
	    <td tal:content="structure python: view.renderField(field)">
              <input size="20" />
            </td>            
          </tr>
	</tal:block>

      </table>
 
      <input type="submit" name="save" value="Save" />

    </form>
  </body>

</html>