Back to index

plone3  3.1.7
test_browserdefaultmixin.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 """
00021 
00022 __author__ = 'Leonardo Almeida and Martin Aspeli <optilude@gmx.net>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 from Testing import ZopeTestCase # side effect import. leave it here.
00026 from Products.ATContentTypes.tests import atcttestcase
00027 
00028 from Products.CMFDynamicViewFTI.browserdefault import BrowserDefaultMixin
00029 from Products.ATContentTypes import permission
00030 from Products.CMFDynamicViewFTI.interfaces import ISelectableBrowserDefault as ZopeTwoISelectableBrowserDefault
00031 from Products.CMFDynamicViewFTI.interface import ISelectableBrowserDefault
00032 
00033 tests = []
00034 
00035 # XXX: This should probably move to the new CMFDynamicViewFTI
00036 class TestBrowserDefaultMixin(atcttestcase.ATCTSiteTestCase):
00037     folder_type = 'Folder'
00038     image_type = 'Image'
00039     document_type = 'Document'
00040     file_type = 'File'
00041 
00042     def afterSetUp(self):
00043         atcttestcase.ATCTSiteTestCase.afterSetUp(self)
00044         self.folder.invokeFactory(self.folder_type, id='af')
00045         # an ATCT folder
00046         self.af = self.folder.af
00047         # Needed because getFolderContents needs to clone the REQUEST
00048         self.app.REQUEST.set('PARENTS', [self.app])
00049 
00050     def test_isMixedIn(self):
00051         self.failUnless(isinstance(self.af, BrowserDefaultMixin),
00052                         "ISelectableBrowserDefault was not mixed in to ATFolder")
00053         self.failUnless(ZopeTwoISelectableBrowserDefault.isImplementedBy(self.af),
00054                         "ISelectableBrowserDefault not implemented by ATFolder instance")
00055         self.failUnless(ISelectableBrowserDefault.providedBy(self.af),
00056                         "ISelectableBrowserDefault not implemented by ATFolder instance")
00057 
00058     def test_defaultFolderViews(self):
00059         self.assertEqual(self.af.getLayout(), 'folder_listing')
00060         self.assertEqual(self.af.getDefaultPage(), None)
00061         self.assertEqual(self.af.defaultView(), 'folder_listing')
00062         self.assertEqual(self.af.getDefaultLayout(), 'folder_listing')
00063         layoutKeys = [v[0] for v in self.af.getAvailableLayouts()]
00064         self.failUnless('folder_listing' in layoutKeys)
00065         self.failUnless('atct_album_view' in layoutKeys)
00066 
00067         resolved = self.af.unrestrictedTraverse('folder_listing')()
00068         browserDefault = self.af.__browser_default__(None)[1][0]
00069         browserDefaultResolved = self.af.unrestrictedTraverse(browserDefault)()
00070         self.assertEqual(resolved, browserDefaultResolved)
00071 
00072     def test_canSetLayout(self):
00073         self.failUnless(self.af.canSetLayout())
00074         self.af.invokeFactory('Document', 'ad')
00075         self.portal.manage_permission(permission.ModifyViewTemplate, [], 0)
00076         self.failIf(self.af.canSetLayout()) # Not permitted
00077 
00078     def test_setLayout(self):
00079         self.af.setLayout('atct_album_view')
00080         self.assertEqual(self.af.getLayout(), 'atct_album_view')
00081         self.assertEqual(self.af.getDefaultPage(), None)
00082         self.assertEqual(self.af.defaultView(), 'atct_album_view')
00083         self.assertEqual(self.af.getDefaultLayout(), 'folder_listing')
00084         layoutKeys = [v[0] for v in self.af.getAvailableLayouts()]
00085         self.failUnless('folder_listing' in layoutKeys)
00086         self.failUnless('atct_album_view' in layoutKeys)
00087 
00088         resolved = self.af.unrestrictedTraverse('atct_album_view')()
00089         browserDefault = self.af.__browser_default__(None)[1][0]
00090         browserDefaultResolved = self.af.unrestrictedTraverse(browserDefault)()
00091         self.assertEqual(resolved, browserDefaultResolved)
00092 
00093     def test_canSetDefaultPage(self):
00094         self.failUnless(self.af.canSetDefaultPage())
00095         self.af.invokeFactory('Document', 'ad')
00096         self.failIf(self.af.ad.canSetDefaultPage()) # Not folderish
00097         self.portal.manage_permission(permission.ModifyViewTemplate, [], 0)
00098         self.failIf(self.af.canSetDefaultPage()) # Not permitted
00099 
00100     def test_setDefaultPage(self):
00101         self.af.invokeFactory('Document', 'ad')
00102         self.af.setDefaultPage('ad')
00103         self.assertEqual(self.af.getDefaultPage(), 'ad')
00104         self.assertEqual(self.af.defaultView(), 'ad')
00105         self.assertEqual(self.af.__browser_default__(None), (self.af, ['ad',]))
00106 
00107         # still have layout settings
00108         self.assertEqual(self.af.getLayout(), 'folder_listing')
00109         self.assertEqual(self.af.getDefaultLayout(), 'folder_listing')
00110         layoutKeys = [v[0] for v in self.af.getAvailableLayouts()]
00111         self.failUnless('folder_listing' in layoutKeys)
00112         self.failUnless('atct_album_view' in layoutKeys)
00113 
00114     def test_setDefaultPageUpdatesCatalog(self):
00115         # Ensure that Default page changes update the catalog
00116         cat = self.portal.portal_catalog
00117         self.af.invokeFactory('Document', 'ad')
00118         self.af.invokeFactory('Document', 'other')
00119         self.assertEqual(len(cat(getId=['ad','other'],is_default_page=True)), 0)
00120         self.af.setDefaultPage('ad')
00121         self.assertEqual(len(cat(getId='ad',is_default_page=True)), 1)
00122         self.af.setDefaultPage('other')
00123         self.assertEqual(len(cat(getId='other',is_default_page=True)), 1)
00124         self.assertEqual(len(cat(getId='ad',is_default_page=True)), 0)
00125         self.af.setDefaultPage(None)
00126         self.assertEqual(len(cat(getId=['ad','other'],is_default_page=True)), 0)
00127         
00128 
00129     def test_setLayoutUnsetsDefaultPage(self):
00130         layout = 'atct_album_view'
00131         self.af.invokeFactory('Document', 'ad')
00132         self.af.setDefaultPage('ad')
00133         self.assertEqual(self.af.getDefaultPage(), 'ad')
00134         self.assertEqual(self.af.defaultView(), 'ad')
00135         self.af.setLayout(layout)
00136         self.assertEqual(self.af.getDefaultPage(), None)
00137         self.assertEqual(self.af.defaultView(), layout)
00138         resolved = self.af.unrestrictedTraverse(layout)()
00139         browserDefault = self.af.__browser_default__(None)[1][0]
00140         browserDefaultResolved = self.af.unrestrictedTraverse(browserDefault)()
00141         self.assertEqual(resolved, browserDefaultResolved)
00142 
00143     def test_inherit_parent_layout(self):
00144         # Check to see if subobjects of the same type inherit the layout set
00145         # on the parent object
00146         af = self.af
00147         af.setLayout('folder_tabular_view')
00148         af.invokeFactory('Folder', 'subfolder', title='folder 2')
00149         subfolder = af.subfolder
00150         self.assertEqual(subfolder.getLayout(), 'folder_tabular_view')
00151 
00152     def test_inherit_parent_layout_if_different_type(self):
00153         # Objects will not inherit the layout if parent object is a different
00154         # type
00155         af = self.af
00156         af.setLayout('folder_tabular_view')
00157         # Create a subobject of a different type (need to enable LPF globally)
00158         lpf_fti = self.portal.portal_types['Large Plone Folder']
00159         lpf_fti.global_allow = 1
00160         af.invokeFactory('Large Plone Folder', 'subfolder', title='folder 2')
00161         subfolder = af.subfolder
00162         self.failIf(subfolder.getLayout() == 'folder_tabular_view')
00163 
00164 tests.append(TestBrowserDefaultMixin)
00165 
00166 import unittest
00167 def test_suite():
00168     suite = unittest.TestSuite()
00169     for test in tests:
00170         suite.addTest(unittest.makeSuite(test))
00171     return suite