############################################################################## # # Copyright (c) 2003, 2004 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. # ############################################################################## """Functional tests for ZPT Page. $Id: ftests.py 25177 2004-06-02 13:17:31Z jim $ """ import unittest from zope.app.testing.functional import BrowserTestCase from zope.app.zptpage.zptpage import ZPTPage from xml.sax.saxutils import escape class ZPTPageTest(BrowserTestCase): content = u'

' def addZPTPage(self): zptpage = ZPTPage() zptpage.source = self.content root = self.getRootFolder() root['zptpage'] = zptpage self.commit() def testAddForm(self): response = self.publish( '/+/zope.app.zptpage.ZPTPage=', basic='mgr:mgrpw') self.assertEqual(response.getStatus(), 200) body = response.getBody() self.assert_('Add a ZPT Page' in body) self.assert_('Source' in body) self.assert_('Expand macros' in body) self.assert_('Evaluate Inline Code' in body) self.assert_('Object Name' in body) self.assert_('"Add"' in body) self.checkForBrokenLinks(body, '/+/zope.app.zptpage.ZPTPage=', 'mgr:mgrpw') def testAdd(self): response = self.publish( '/+/zope.app.zptpage.ZPTPage=', form={'type_name': u'zope.app.zptpage.ZPTPage', 'field.source': u'

A ZPT Page

', 'field.expand.used': u'', 'field.evaluateInlineCode.used': u'', 'add_input_name': u'zptpage', 'UPDATE_SUBMIT': u'Add'}, basic='mgr:mgrpw') self.assertEqual(response.getStatus(), 302) self.assertEqual(response.getHeader('Location'), 'http://localhost/@@contents.html') root = self.getRootFolder() self.assert_('zptpage' in root) zptpage = root['zptpage'] self.assertEqual(zptpage.source, '

A ZPT Page

') self.assertEqual(zptpage.expand, False) self.assertEqual(zptpage.evaluateInlineCode, False) response = self.publish( '/+/zope.app.zptpage.ZPTPage=', form={'type_name': u'zope.app.zptpage.ZPTPage', 'field.source': u'

A ZPT Page

\n', 'field.expand.used': u'', 'field.expand': u'on', 'field.evaluateInlineCode.used': u'', 'field.evaluateInlineCode': u'on', 'add_input_name': u'zptpage1', 'UPDATE_SUBMIT': u'Add'}, basic='mgr:mgrpw') root = self.getRootFolder() zptpage = root['zptpage1'] self.assertEqual(zptpage.source, '

A ZPT Page

\n') self.assertEqual(zptpage.expand, True) self.assertEqual(zptpage.evaluateInlineCode, True) def testEditForm(self): self.addZPTPage() response = self.publish( '/zptpage/@@edit.html', basic='mgr:mgrpw') self.assertEqual(response.getStatus(), 200) body = response.getBody() self.assert_('Source' in body) self.assert_('Expand macros' in body) self.assert_(escape(self.content) in body) self.checkForBrokenLinks(body, '/zptpage/@@edit.html', 'mgr:mgrpw') def testEdit(self): self.addZPTPage() response = self.publish( '/zptpage/@@edit.html', form={'form.source': u'

A ZPT Page

\n', 'form.expand.used': u'', 'form.expand': u'on', 'form.actions.apply': u'Apply'}, basic='mgr:mgrpw') self.assertEqual(response.getStatus(), 200) body = response.getBody() self.assert_('Source' in body) self.assert_(escape(u'

A ZPT Page

') in body) root = self.getRootFolder() zptpage = root['zptpage'] self.assertEqual(zptpage.source, '

A ZPT Page

\n') self.assertEqual(zptpage.expand, True) def testIssue199(self): # This is a test to protect us against issue 199 in the future self.addZPTPage() source = u"""
write this in the body slot.
""" response = self.publish( '/zptpage/@@edit.html', form={'form.source': source, 'form.expand.used': u'', 'form.expand': u'on', 'form.actions.apply': u'Apply'}, basic='mgr:mgrpw') self.assertEqual(response.getStatus(), 200) body = response.getBody() # Check for a string from the default template self.assert_(escape(u'Z3 UI') in body) self.failIf(u"Macro expansion failed" in body) def testIndex(self): self.addZPTPage() response = self.publish( '/zptpage/@@index.html', basic='mgr:mgrpw') self.assertEqual(response.getStatus(), 200) self.assertEqual(response.getBase(), '') body = response.getBody() self.assertEqual( body, '

http://localhost/zptpage

\n') self.checkForBrokenLinks(body, '/zptpage/@@index.html', 'mgr:mgrpw') def testPreview(self): self.addZPTPage() response = self.publish( '/zptpage/@@preview.html', basic='mgr:mgrpw') self.assertEqual(response.getStatus(), 200) body = response.getBody() self.assert_('