Back to index

plone3  3.1.7
test_menus.py
Go to the documentation of this file.
00001 # Copyright (c) 2006
00002 # Authors:
00003 #   David '/dev/null' Convent  <davconvent@gmail.com>
00004 #   Daniel 'import pdb' Nouri
00005 # This program is free software; you can redistribute it and/or modify
00006 # it under the terms of the GNU General Public License version 2 as published
00007 # by the Free Software Foundation.
00008 #
00009 # This program is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 # GNU General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU General Public License
00015 # along with this program; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017 # 02111-1307, USA.
00018 #
00019 
00020 import unittest
00021 from Products.PloneTestCase import PloneTestCase
00022 from plone.app.kss.tests.kss_and_plone_layer import KSSAndPloneTestCase
00023 from plone.app.kss import content_replacer
00024 
00025 PloneTestCase.setupPloneSite()
00026 
00027 class ContentActionMenusTestCase(KSSAndPloneTestCase):
00028 
00029     def afterSetUp(self):
00030         KSSAndPloneTestCase.afterSetUp(self)
00031         self.setDebugRequest()
00032         self.loginAsPortalOwner()
00033         self.fpage = self.portal['front-page']
00034 
00035     # --
00036     # test the Kss methods
00037     # --
00038 
00039     def testReplaceContentRegion(self):
00040         req = self.portal.REQUEST
00041         view = content_replacer.ContentView(self.fpage, req)
00042         result = view.replaceContentRegion(self.fpage.absolute_url(), tabid='contentview-edit')
00043         self.assertEqual([(r['name'], r['selector'], r['selectorType']) for r in result],
00044                          [('replaceHTML', 'region-content', 'htmlid'),
00045                           ('setAttribute', 'ul.contentViews li', 'css'),
00046                           ('setAttribute', 'contentview-edit', 'htmlid'),
00047                           ('replaceHTML', 'contentActionMenus', 'htmlid'),
00048                          ])
00049 
00050     def testChangeViewTemplate(self):
00051         # Let's set the default page on front-page,
00052         # should set default layout of portal
00053         req = self.portal.REQUEST
00054         self.assertEqual(self.portal.getLayout(), 'folder_listing')
00055         view = content_replacer.ContentMenuView(self.fpage, req)
00056         url = self.fpage.absolute_url() + '?templateId=atct_album_view'
00057         result = view.changeViewTemplate(url)
00058         self.assertEqual(self.portal.getLayout(), 'atct_album_view')
00059         
00060         resh = req.RESPONSE.headers
00061         self.assertEqual(resh['status'], '200 OK')
00062         self.failUnless(req.RESPONSE.cookies['statusmessages'].has_key('expires'), 'cookies not expired')
00063 
00064     def testKssCutObject(self):
00065         req = self.portal.REQUEST
00066         # XXX This menu is missing from front page, so we test them on the user folder.
00067         view = content_replacer.ContentMenuView(self.folder, req)
00068         result = view.cutObject()
00069 
00070         self.assertEqual([(r['name'], r['selector'], r['selectorType']) for r in result],
00071                          [('replaceHTML', 'contentActionMenus', 'htmlid'),
00072                           ('setStyle', '.portalMessage', 'css'),
00073                           ('replaceInnerHTML', 'kssPortalMessage', 'htmlid'),
00074                           ('setAttribute', 'kssPortalMessage', 'htmlid'),
00075                           ('setStyle', 'kssPortalMessage', 'htmlid'),
00076                          ])
00077 
00078     def testCutObject(self):
00079         req = self.portal.REQUEST
00080         self.failIf(req.RESPONSE.cookies.has_key('__cp'), 'has cut cookie')
00081         # XXX This menu is missing from front page, so we test them on the user folder.
00082         view = content_replacer.ContentMenuView(self.folder, req)
00083         result = view.cutObject()
00084         resh = req.RESPONSE.headers
00085         self.assertEqual(resh['status'], '200 OK')
00086         self.failUnless(req.RESPONSE.cookies.has_key('__cp'), 'no cut cookie')
00087         
00088     def testKssCopyObject(self):
00089         req = self.portal.REQUEST
00090         # XXX This menu is missing from front page, so we test them on the user folder.
00091         view = content_replacer.ContentMenuView(self.folder, req)
00092 
00093         result = view.copyObject()
00094         self.assertEqual([(r['name'], r['selector'], r['selectorType']) for r in result],
00095                          [('replaceHTML', 'contentActionMenus', 'htmlid'),
00096                           ('setStyle', '.portalMessage', 'css'),
00097                           ('replaceInnerHTML', 'kssPortalMessage', 'htmlid'),
00098                           ('setAttribute', 'kssPortalMessage', 'htmlid'),
00099                           ('setStyle', 'kssPortalMessage', 'htmlid'),
00100                          ])
00101 
00102     def testCopyObject(self):
00103         req = self.portal.REQUEST
00104         self.failIf(req.RESPONSE.cookies.has_key('__cp'), 'has copy cookie')
00105         # XXX This menu is missing from front page, so we test them on the user folder.
00106         view = content_replacer.ContentMenuView(self.folder, req)
00107         result = view.copyObject()
00108         resh = req.RESPONSE.headers
00109         self.assertEqual(resh['status'], '200 OK')
00110         self.failUnless(req.RESPONSE.cookies.has_key('__cp'), 'no copy cookies')
00111 
00112     def testChangeWorkflowState(self):
00113         # change the state of the front-page to published
00114         # I suppose to have the publish transition available
00115         req = self.portal.REQUEST
00116         view = content_replacer.ContentMenuView(self.fpage, req)
00117         url = self.fpage.absolute_url() + '/content_status_modify?workflow_action=publish'
00118         result = view.changeWorkflowState(url)
00119         self.assertEqual([(r['name'], r['selector'], r['selectorType']) for r in result],
00120                          [
00121                           ('replaceHTML', '.contentViews', 'css'),
00122                           ('replaceHTML', 'contentActionMenus', 'htmlid'),
00123                           ('setStyle', '.portalMessage', 'css'),
00124                           ('replaceInnerHTML', 'kssPortalMessage', 'htmlid'),
00125                           ('setAttribute', 'kssPortalMessage', 'htmlid'),
00126                           ('setStyle', 'kssPortalMessage', 'htmlid'),
00127                          ])
00128 
00129 def test_suite():
00130     return unittest.TestSuite((
00131         unittest.makeSuite(ContentActionMenusTestCase),
00132         ))