##############################################################################
#
# 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.1 (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.
#
##############################################################################
"""TextWidget Tests
$Id: test_textwidget.py 68730 2006-06-18 05:35:59Z ctheune $
"""
import unittest
import transaction
from persistent import Persistent
import zope.security.checker
from zope.interface import Interface, implements
from zope.schema import TextLine, Choice
from zope.traversing.api import traverse
from zope.app.form.browser.ftests.support import *
from zope.app.testing.functional import BrowserTestCase
class ITextLineTest(Interface):
s2 = TextLine(
required=False,
missing_value=u'')
s3 = Choice(
required=False,
values=(u'Bob', u'is', u'Your', u'Uncle'))
s1 = TextLine(
required=True,
min_length=2,
max_length=10)
class TextLineTest(Persistent):
implements(ITextLineTest)
def __init__(self):
self.s1 = ''
self.s2 = u'foo'
self.s3 = None
class Test(BrowserTestCase):
def setUp(self):
BrowserTestCase.setUp(self)
registerEditForm(ITextLineTest)
defineSecurity(TextLineTest, ITextLineTest)
def test_display_editform(self):
self.getRootFolder()['test'] = TextLineTest()
transaction.commit()
# display edit view
response = self.publish('/test/edit.html')
self.assertEqual(response.getStatus(), 200)
# s1 and s2 should be displayed in text fields
self.assert_(patternExists(
'', response.getBody()))
self.assert_(patternExists(
'', response.getBody()))
# s3 should be in a dropdown
self.assert_(patternExists(
'