Back to index

plone3  3.1.7
test_validation.py
Go to the documentation of this file.
00001 # Copyright (c) 2006
00002 # Authors: Plone
00003 #
00004 # This program is free software; you can redistribute it and/or modify
00005 # it under the terms of the GNU General Public License version 2 as published
00006 # by the Free Software Foundation.
00007 #
00008 # This program is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 # GNU General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU General Public License
00014 # along with this program; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00016 # 02111-1307, USA.
00017 #
00018 
00019 import unittest
00020 from Products.PloneTestCase import PloneTestCase
00021 from plone.app.kss.tests.kss_and_plone_layer import KSSAndPloneTestCase
00022 
00023 PloneTestCase.setupPloneSite()
00024 
00025 class ValidationViewTestCase(KSSAndPloneTestCase):
00026 
00027     def afterSetUp(self):
00028         PloneTestCase.PloneTestCase.afterSetUp(self)
00029         # commands will be rendered as data structures,
00030         self.setDebugRequest()
00031         self.loginAsPortalOwner()
00032         context = self.portal['front-page']
00033         # create content
00034         self.portal.invokeFactory(id='testfile', type_name='File')
00035         self.portal.invokeFactory(id='testdoc', type_name='Document')
00036 
00037     # --
00038     # test the Kss methods
00039     # --
00040 
00041     def testValidateFormWithEvents(self):
00042         """Test validating a form works with events
00043         """
00044         # Set up a view 
00045         context = self.portal.testdoc
00046         view = context.restrictedTraverse('kssValidateForm')
00047         # this form contains a file field that needs to be ignored. 
00048         data = {'': 'A kiv\xc3\xa1lasztott elemek elt\xc3\xa1vol\xc3\xadt\xc3\xa1sa', 'allowDiscussion': 'None',
00049             'cmfeditions_save_new_version': 'false', 'contributors': [],
00050             'creators': ['ree'], 'description': '', 'description_text_format':
00051             'text/plain', 'effectiveDate': '', 'effectiveDate_ampm': '',
00052             'effectiveDate_day': '00', 'effectiveDate_hour': '00',
00053             'effectiveDate_minute': '00', 'effectiveDate_month': '00',
00054             'effectiveDate_year': '2006', 'excludeFromNav': '0',
00055             'excludeFromNav_visible': 'false', 'expirationDate': '',
00056             'expirationDate_ampm': '', 'expirationDate_day': '00',
00057             'expirationDate_hour': '00', 'expirationDate_minute': '00',
00058             'expirationDate_month': '00', 'expirationDate_year': '2006',
00059             'fieldset': 'default', 'file_file':
00060             '', 'id':
00061             'file.2006-12-21.4001159106', 'language': 'Meghat\xc3\xa1rozatlan nyelv(a port\xc3\xa1l alap\xc3\xa9rtelmezett nyelve)', 'last_referer':
00062             'http://localhost:9888/new16/uacheckin.pdf/view?portal_status_message=Changes%20saved.',
00063             'relatedItems': [''], 'rights': '', 'rights_text_format': 'text/plain',
00064             'subject_existing_keywords': [''], 'subject_keywords': [], 'title': 'The new title'}
00065             
00066         result = view.kssValidateForm(data)
00067         
00068     def testValidateForm(self):
00069         """Test validating a form works
00070         """
00071         # Set up a view 
00072         context = self.portal.testdoc
00073         view = context.restrictedTraverse('kssValidateForm')
00074         # this form contains a file field that needs to be ignored. 
00075         data = {'': 'A kiv\xc3\xa1lasztott elemek elt\xc3\xa1vol\xc3\xadt\xc3\xa1sa', 'allowDiscussion': 'None',
00076             'cmfeditions_save_new_version': 'false', 'contributors': [],
00077             'creators': ['ree'], 'description': '', 'description_text_format':
00078             'text/plain', 'effectiveDate': '', 'effectiveDate_ampm': '',
00079             'effectiveDate_day': '00', 'effectiveDate_hour': '00',
00080             'effectiveDate_minute': '00', 'effectiveDate_month': '00',
00081             'effectiveDate_year': '2006', 'excludeFromNav': '0',
00082             'excludeFromNav_visible': 'false', 'expirationDate': '',
00083             'expirationDate_ampm': '', 'expirationDate_day': '00',
00084             'expirationDate_hour': '00', 'expirationDate_minute': '00',
00085             'expirationDate_month': '00', 'expirationDate_year': '2006',
00086             'fieldset': 'default', 'file_file':
00087             '', 'id':
00088             'file.2006-12-21.4001159106', 'language': 'Meghat\xc3\xa1rozatlan nyelv(a port\xc3\xa1l alap\xc3\xa9rtelmezett nyelve)', 'last_referer':
00089             'http://localhost:9888/new16/uacheckin.pdf/view?portal_status_message=Changes%20saved.',
00090             'relatedItems': [''], 'rights': '', 'rights_text_format': 'text/plain',
00091             'subject_existing_keywords': [''], 'subject_keywords': [], 'title': 'The new title', 
00092             'text': 'XXX'}
00093             
00094         result = view.kssValidateForm(data)
00095         
00096         self.assertEqual([(r['name'], r['selector'], r['selectorType'])
00097                              for r in result], [
00098                 ('plone-submitCurrentForm', '', 'samenode'),
00099             ])
00100 
00101     def testValidateFormFailed(self):
00102         """Test validating a form works, with the title field not validatiing
00103         """
00104         # Set up a view 
00105         context = self.portal.testdoc
00106         view = context.restrictedTraverse('kssValidateForm')
00107         # this form contains a file field that needs to be ignored. 
00108         data = {'': 'A kiv\xc3\xa1lasztott elemek elt\xc3\xa1vol\xc3\xadt\xc3\xa1sa', 'allowDiscussion': 'None',
00109             'cmfeditions_save_new_version': 'false', 'contributors': [],
00110             'creators': ['ree'], 'description': '', 'description_text_format':
00111             'text/plain', 'effectiveDate': '', 'effectiveDate_ampm': '',
00112             'effectiveDate_day': '00', 'effectiveDate_hour': '00',
00113             'effectiveDate_minute': '00', 'effectiveDate_month': '00',
00114             'effectiveDate_year': '2006', 'excludeFromNav': '0',
00115             'excludeFromNav_visible': 'false', 'expirationDate': '',
00116             'expirationDate_ampm': '', 'expirationDate_day': '00',
00117             'expirationDate_hour': '00', 'expirationDate_minute': '00',
00118             'expirationDate_month': '00', 'expirationDate_year': '2006',
00119             'fieldset': 'default', 'file_file':
00120             'thefile.txt', 'id':
00121             'file.2006-12-21.4001159106', 'language': 'Meghat\xc3\xa1rozatlan nyelv(a port\xc3\xa1l alap\xc3\xa9rtelmezett nyelve)', 'last_referer':
00122             'http://localhost:9888/new16/uacheckin.pdf/view?portal_status_message=Changes%20saved.',
00123             'relatedItems': [''], 'rights': '', 'rights_text_format': 'text/plain',
00124             'subject_existing_keywords': [''], 'subject_keywords': [], 'title': '', 'text': 'XXX'}
00125         
00126         result = view.kssValidateForm(data)
00127         
00128         self.assertEqual([(r['name'], r['selector'], r['selectorType'])
00129                              for r in result], [
00130                  ('setStyle', '.portalMessage', 'css'),
00131                  ('replaceInnerHTML', 'kssPortalMessage', 'htmlid'),
00132                  ('setAttribute', 'kssPortalMessage', 'htmlid'),
00133                  ('setStyle', 'kssPortalMessage', 'htmlid'),
00134                  ('clearChildNodes', 'div.field div.fieldErrorBox', 'css'),
00135                  ('replaceInnerHTML', 'div#archetypes-fieldname-title div.fieldErrorBox', 'css'), 
00136                  ('setAttribute', 'archetypes-fieldname-title', 'htmlid'),
00137             ])
00138 
00139     def testValidateFormWithUploads(self):
00140         """Test validating a form works with uploads
00141         """
00142         # Set up a view 
00143         context = self.portal.testfile
00144         view = context.restrictedTraverse('kssValidateForm')
00145         # this form contains a file field that needs to be ignored. 
00146         data = {'': 'A kiv\xc3\xa1lasztott elemek elt\xc3\xa1vol\xc3\xadt\xc3\xa1sa', 'allowDiscussion': 'None',
00147         'cmfeditions_save_new_version': 'false', 'contributors': [],
00148         'creators': ['ree'], 'description': '', 'description_text_format':
00149         'text/plain', 'effectiveDate': '', 'effectiveDate_ampm': '',
00150         'effectiveDate_day': '00', 'effectiveDate_hour': '00',
00151         'effectiveDate_minute': '00', 'effectiveDate_month': '00',
00152         'effectiveDate_year': '2006', 'excludeFromNav': '0',
00153         'excludeFromNav_visible': 'false', 'expirationDate': '',
00154         'expirationDate_ampm': '', 'expirationDate_day': '00',
00155         'expirationDate_hour': '00', 'expirationDate_minute': '00',
00156         'expirationDate_month': '00', 'expirationDate_year': '2006',
00157         'fieldset': 'default', 'file_file':
00158         '/home/ree/docs/canon_biztosito/melleklet.odt', 'id':
00159         'file.2006-12-21.4001159106', 'language': 'Meghat\xc3\xa1rozatlan nyelv (a port\xc3\xa1l alap\xc3\xa9rtelmezett nyelve)', 'last_referer':
00160         'http://localhost:9888/new16/uacheckin.pdf/view?portal_status_message=Changes%20saved.',
00161         'relatedItems': [''], 'rights': '', 'rights_text_format': 'text/plain',
00162         'subject_existing_keywords': [''], 'subject_keywords': [], 'title': 'New title'}
00163         
00164         result = view.kssValidateForm(data)
00165         
00166         self.assertEqual([(r['name'], r['selector'], r['selectorType'])
00167                              for r in result], [
00168                 ('plone-submitCurrentForm', '', 'samenode'),
00169             ])
00170 
00171 def test_suite():
00172     return unittest.TestSuite((
00173         unittest.makeSuite(ValidationViewTestCase),
00174         #doctest.DocTestSuite('archetypes.kss.fields'),
00175         ))