Back to index

plone3  3.1.7
test_context.py
Go to the documentation of this file.
00001 import unittest
00002 from plone.app.layout.globals.tests.base import GlobalsTestCase
00003 
00004 from zope.interface import directlyProvides
00005 from Products.CMFPlone.interfaces import INonStructuralFolder
00006 
00007 from plone.locking.interfaces import ILockable
00008 
00009 class TestContextStateView(GlobalsTestCase):
00010     """Ensure that the basic redirector setup is successful.
00011     """
00012     
00013     def afterSetUp(self):
00014         self.fview = self.folder.restrictedTraverse('@@plone_context_state')
00015 
00016         self.folder.invokeFactory('Document', 'd1')
00017         self.folder.setDefaultPage('d1')
00018         self.dview = self.folder.d1.restrictedTraverse('@@plone_context_state')
00019         
00020         self.folder.invokeFactory('Folder', 'f1')
00021         directlyProvides(self.folder.f1, INonStructuralFolder)
00022         self.sview = self.folder.f1.restrictedTraverse('@@plone_context_state')
00023         
00024         self.pview = self.portal.restrictedTraverse('@@plone_context_state')
00025     
00026     def test_current_page_url(self):
00027         url = self.folder.absolute_url() + '/some_view'
00028         self.app.REQUEST['ACTUAL_URL'] = url
00029         self.app.REQUEST['QUERY_STRING'] = 'foo=bar'
00030         self.assertEquals(self.fview.current_page_url(), url + '?foo=bar')
00031         
00032     def test_current_base_url(self):
00033         url = self.folder.absolute_url() + '/some_view'
00034         self.app.REQUEST['ACTUAL_URL'] = url
00035         self.app.REQUEST['QUERY_STRING'] = 'foo=bar'
00036         self.assertEquals(self.fview.current_base_url(), url)
00037         
00038     def test_canonical_object(self):
00039         self.assertEquals(self.fview.canonical_object(), self.folder)
00040         self.assertEquals(self.dview.canonical_object(), self.folder)
00041         
00042     def test_canonical_object_url(self):
00043         self.assertEquals(self.fview.canonical_object_url(), self.folder.absolute_url())
00044         self.assertEquals(self.dview.canonical_object_url(), self.folder.absolute_url())
00045         
00046     def test_view_url(self):
00047         self.assertEquals(self.fview.view_url(),
00048                           self.folder.absolute_url())
00049         self.assertEquals(self.dview.view_url(),
00050                           self.folder.d1.absolute_url())
00051         self.folder.invokeFactory('File', 'file1')
00052         self.fileview = self.folder.file1.restrictedTraverse('@@plone_context_state')
00053         self.assertEquals(self.fileview.view_url(),
00054                           self.folder.file1.absolute_url() + '/view')
00055                             
00056     def test_view_template_id(self):
00057         self.folder.setLayout('foo_view')
00058         self.assertEquals(self.fview.view_template_id(), 'foo_view')
00059                             
00060     def test_is_view_template_default_page(self):
00061         self.app.REQUEST['ACTUAL_URL'] = self.folder.absolute_url()
00062         # Whether you're viewing the folder or its default page ...
00063         self.assertEquals(self.fview.is_view_template(), True)
00064         self.assertEquals(self.dview.is_view_template(), True)
00065         
00066     def test_is_view_template_trailing_slash(self):
00067         self.app.REQUEST['ACTUAL_URL'] = self.folder.absolute_url() + '/'
00068         self.assertEquals(self.fview.is_view_template(), True)
00069         self.assertEquals(self.dview.is_view_template(), True)
00070                                     
00071     def test_is_view_template_template(self):
00072         self.folder.setLayout('foo_view')
00073         self.app.REQUEST['ACTUAL_URL'] = self.folder.absolute_url() + '/foo_view'
00074         self.assertEquals(self.fview.is_view_template(), True)
00075         self.assertEquals(self.dview.is_view_template(), False)
00076         
00077     def test_is_view_template_template_z3view(self):
00078         self.folder.setLayout('foo_view')
00079         self.app.REQUEST['ACTUAL_URL'] = self.folder.absolute_url() + '/@@foo_view'
00080         self.assertEquals(self.fview.is_view_template(), True)
00081         self.assertEquals(self.dview.is_view_template(), False)
00082         
00083     def test_is_view_template_view(self):
00084         self.folder.setLayout('foo_view')
00085         self.app.REQUEST['ACTUAL_URL'] = self.folder.absolute_url() + '/view'
00086         self.assertEquals(self.fview.is_view_template(), True)
00087         self.assertEquals(self.dview.is_view_template(), False)
00088                             
00089     def test_is_view_template_other(self):
00090         self.folder.setLayout('foo_view')
00091         self.app.REQUEST['ACTUAL_URL'] = self.folder.absolute_url() + '/bar_view'
00092         self.assertEquals(self.fview.is_view_template(), False)
00093         self.assertEquals(self.dview.is_view_template(), False)                            
00094                             
00095     def test_object_url(self):
00096         self.assertEquals(self.fview.object_url(), self.folder.absolute_url())
00097         self.assertEquals(self.dview.object_url(), self.folder.d1.absolute_url())
00098         
00099     def test_object_title(self):
00100         self.folder.d1.setTitle('My title')
00101         self.assertEquals(self.dview.object_title(), 'My title')
00102         
00103     def test_workflow_state(self):
00104         wfstate = self.portal.portal_workflow.getInfoFor(self.folder.d1, 'review_state')
00105         self.assertEquals(self.dview.workflow_state(), wfstate)
00106     
00107     def test_parent(self):
00108         self.assertEquals(self.dview.parent(), self.folder)
00109         self.assertEquals(self.sview.parent(), self.folder)
00110         
00111     def test_folder(self):
00112         self.assertEquals(self.fview.folder(), self.folder)
00113         self.assertEquals(self.dview.folder(), self.folder)
00114         self.assertEquals(self.sview.folder(), self.folder)
00115                             
00116     def test_is_folderish(self):
00117         self.assertEquals(self.fview.is_folderish(), True)
00118         self.assertEquals(self.dview.is_folderish(), False)
00119         self.assertEquals(self.sview.is_folderish(), True)
00120     
00121     def test_is_structural_folder(self):
00122         self.assertEquals(self.fview.is_structural_folder(), True)
00123         self.assertEquals(self.dview.is_structural_folder(), False)
00124         self.assertEquals(self.sview.is_structural_folder(), False)
00125     
00126     def test_is_default_page(self):
00127         self.assertEquals(self.fview.is_default_page(), False)
00128         self.assertEquals(self.dview.is_default_page(), True)
00129         self.assertEquals(self.sview.is_default_page(), False)
00130         
00131     def test_is_portal_root(self):
00132         self.assertEquals(self.fview.is_portal_root(), False)
00133         self.assertEquals(self.dview.is_portal_root(), False)
00134         self.assertEquals(self.sview.is_portal_root(), False)
00135         self.assertEquals(self.pview.is_portal_root(), True)
00136     
00137     def test_is_editable(self):
00138         self.assertEquals(self.dview.is_editable(), True)
00139         self.logout()
00140         del self.app.REQUEST.__annotations__
00141         self.assertEquals(self.dview.is_editable(), False)
00142     
00143     def test_is_locked(self):
00144         self.assertEquals(self.dview.is_locked(), False)
00145         ILockable(self.folder.d1).lock()
00146         self.logout() # The object is not "locked" if it was locked by the current user
00147         del self.app.REQUEST.__annotations__
00148         self.assertEquals(self.dview.is_locked(), True)
00149                             
00150     def test_actions(self):
00151         actions = self.fview.actions()
00152         self.failUnless('workflow' in actions)
00153     
00154 def test_suite():
00155     suite = unittest.TestSuite()
00156     suite.addTest(unittest.makeSuite(TestContextStateView))
00157     return suite