Back to index

plone3  3.1.7
testNavigationParent.py
Go to the documentation of this file.
00001 #
00002 # Tests the navigationParent script
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 
00007 
00008 class TestNavigationParent(PloneTestCase.PloneTestCase):
00009 
00010     def afterSetUp(self):
00011         self.folder.invokeFactory('Folder', 'f1', title = 'Folder 1')
00012         self.f1 = getattr(self.folder, 'f1')
00013         self.f1.invokeFactory('Folder', 'f2', title = 'Folder 2')
00014         self.f2 = getattr(self.f1, 'f2')
00015 
00016     def testPortalRoot(self):
00017         self.failUnless(self.portal.navigationParent() is None)
00018 
00019     def testFolderInPortal(self):
00020         self.setRoles(['Manager'])
00021         self.portal.invokeFactory('Folder', 'pf', title = 'portal folder')
00022         pf = getattr(self.portal, 'pf')
00023         self.assertEqual(pf.navigationParent(), self.portal.absolute_url())
00024         
00025     def testFolderInFolder(self):
00026         self.assertEqual(self.f2.navigationParent(), self.f1.absolute_url())
00027         
00028     def testDocumentInFolder(self):
00029         self.f1.invokeFactory('Document', 'd1', title = 'Document 1')
00030         d1 = getattr(self.f1, 'd1')
00031         self.assertEqual(d1.navigationParent(), self.f1.absolute_url())
00032         
00033         
00034     # Standard behaviour for default_page/index_html - go up two levels,
00035     # since going to parent will just end you up at the same object again
00036         
00037     def testIndexHtmlInFolder(self):
00038         self.f2.invokeFactory('Document', 'index_html', title = 'Document 1')
00039         d1 = getattr(self.f2, 'index_html')
00040         self.assertEqual(d1.navigationParent(), self.f1.absolute_url())
00041         
00042     def testDefaultPageInFolder(self):
00043         self.f2.invokeFactory('Document', 'd1', title = 'Document 1')
00044         d1 = getattr(self.f2, 'd1')
00045         self.f2.setDefaultPage('d1')
00046         self.assertEqual(d1.navigationParent(), self.f1.absolute_url())
00047         
00048     def testFolderishIndexHtmlInFolder(self):
00049         self.f2.invokeFactory('Folder', 'index_html', title = 'Index folder')
00050         ih = getattr(self.f2, 'index_html')
00051         self.assertEqual(ih.navigationParent(), self.f1.absolute_url())
00052     
00053     def testFolderishDefaultPageInFolder(self):
00054         self.f1.setDefaultPage('f2')
00055         self.assertEqual(self.f2.navigationParent(), self.folder.absolute_url())
00056 
00057     # Optional behaviour - don't fall through, go straight to parent. 
00058     # This is what we do on folder_contents, for example. It's only sensible
00059     # if you intend to link/redirect to an object + a page template
00060 
00061     def testNoFallThroughIndexHtmlInFolder(self):
00062         self.f2.invokeFactory('Document', 'index_html', title = 'Document 1')
00063         d1 = getattr(self.f2, 'index_html')
00064         self.assertEqual(d1.navigationParent(fallThroughDefaultPage=False), 
00065                             self.f2.absolute_url())
00066 
00067     def testNoFallThroughDefaultPageInFolder(self):
00068         self.f2.invokeFactory('Document', 'd1', title = 'Document 1')
00069         d1 = getattr(self.f2, 'd1')
00070         self.f2.setDefaultPage('d1')
00071         self.assertEqual(d1.navigationParent(fallThroughDefaultPage=False), 
00072                             self.f2.absolute_url())
00073 
00074     def testNoFallThroughFolderishIndexHtmlInFolder(self):
00075         self.f2.invokeFactory('Folder', 'index_html', title = 'Index folder')
00076         ih = getattr(self.f2, 'index_html')
00077         self.assertEqual(ih.navigationParent(fallThroughDefaultPage=False), 
00078                             self.f2.absolute_url())
00079         
00080     def testNoFallThroughFolderishDefaultPageInFolder(self):
00081         self.f1.setDefaultPage('f2')
00082         self.assertEqual(self.f2.navigationParent(fallThroughDefaultPage=False), 
00083                             self.f1.absolute_url())
00084                             
00085     # Very special case - if you have an index_html inside an index_html...
00086     def testRecursiveDefaultPage(self):
00087         self.f1.setDefaultPage('f2')
00088         self.f2.invokeFactory('Folder', 'index_html', title = 'index index index')
00089         ih = getattr(self.f2, 'index_html')
00090         self.assertEqual(ih.navigationParent(), self.folder.absolute_url())
00091 
00092     # Permission checks on parent
00093         
00094     def testNoParentViewPermission(self):
00095         self.setRoles(['Manager'])
00096         self.portal.invokeFactory('Folder', 'pf', title = 'portal folder')
00097         pf = getattr(self.portal, 'pf')
00098         pf.invokeFactory('Folder', 'lf', title = 'listable folder')
00099         lf = getattr(pf, 'lf')
00100         pf.manage_permission('List folder contents', ['Manager'], 0)
00101         pf.manage_permission('View', ['Manager'], 0)
00102         lf.manage_permission('List folder contents', ['Member', 'Manager', 'Owner'], 0)
00103         lf.manage_permission('View', ['Member', 'Manager', 'Owner'], 0)
00104         self.setRoles(['Member'])
00105         
00106         self.failUnless(lf.navigationParent() is None)
00107         
00108     def testNoParentListPermissions(self):
00109         self.setRoles(['Manager'])
00110         self.portal.invokeFactory('Folder', 'pf', title = 'portal folder')
00111         pf = getattr(self.portal, 'pf')
00112         pf.invokeFactory('Folder', 'lf', title = 'listable folder')
00113         lf = getattr(pf, 'lf')
00114         pf.manage_permission('List folder contents', ['Manager'], 0)
00115         lf.manage_permission('List folder contents', ['Member', 'Manager', 'Owner'], 0)
00116         self.setRoles(['Member'])
00117         
00118         self.failUnless(lf.navigationParent(checkPermissions = ['List folder contents']) is None) 
00119                 
00120 
00121 def test_suite():
00122     from unittest import TestSuite, makeSuite
00123     suite = TestSuite()
00124     suite.addTest(makeSuite(TestNavigationParent))
00125     return suite