Back to index

plone3  3.1.7
testNextPrevious.py
Go to the documentation of this file.
00001 #
00002 # Next / Previous navigation tests
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 from plone.app.layout.nextprevious.interfaces import INextPreviousProvider
00007 
00008 class TestNextPrevious(PloneTestCase.PloneTestCase):
00009     """Basic use cases and tests for next/previous navigation
00010     """
00011     
00012     def afterSetUp(self):
00013         self.populateSite()
00014 
00015     #set up a lot of content - can be reused in each (sub)test
00016     def populateSite(self):
00017         self.setRoles(['Manager'])
00018         self.portal.invokeFactory('Document', 'doc1')
00019         self.portal.invokeFactory('Document', 'doc2')
00020         self.portal.invokeFactory('Document', 'doc3')
00021         self.portal.invokeFactory('Folder', 'folder1')
00022         self.portal.invokeFactory('Link', 'link1')
00023         self.portal.link1.setRemoteUrl('http://plone.org')
00024         self.portal.link1.reindexObject()
00025         folder1 = getattr(self.portal, 'folder1')
00026         folder1.invokeFactory('Document', 'doc11')
00027         folder1.invokeFactory('Document', 'doc12')
00028         folder1.invokeFactory('Document', 'doc13')
00029         self.portal.invokeFactory('Folder', 'folder2')
00030         folder2 = getattr(self.portal, 'folder2')
00031         folder2.invokeFactory('Document', 'doc21')
00032         folder2.invokeFactory('Document', 'doc22')
00033         folder2.invokeFactory('Document', 'doc23')
00034         folder2.invokeFactory('File', 'file21')
00035         self.setRoles(['Member'])
00036 
00037     def testIfFolderImplementsPreviousNext(self):
00038         self.folder.invokeFactory('Folder', 'case')
00039         self.failUnless(INextPreviousProvider(self.folder.case, None) is not None)
00040 
00041     def testNextPreviousEnablingOnCreation(self):
00042         self.folder.invokeFactory('Folder', 'case')
00043         
00044         #first the field on the atfolder direct, to get sure the field is there
00045         enabled = self.folder.case.getNextPreviousEnabled()
00046         self.failIf(enabled)
00047         
00048         #secoundly we test if the adapter provides the isNextPreviousEnabled()
00049         adapter = INextPreviousProvider(self.folder.case)
00050         self.failIf(adapter.enabled)
00051 
00052     def testNextPreviousViewDisabled(self):
00053         view = self.portal.folder1.doc11.restrictedTraverse('@@plone_nextprevious_view', None)
00054         self.failIf(view is None)
00055         
00056         #is it enabled (default is false)
00057         self.failIf(view.enabled())
00058 
00059     def testNextPreviousViewEnabled(self):
00060         #set the parent folder "getNextPreviousEnabled" to true
00061         self.portal.folder1.setNextPreviousEnabled(True)
00062         
00063         # clear request memos
00064         view = self.portal.folder1.doc12.restrictedTraverse('@@plone_nextprevious_view', None)
00065         self.failUnless(view.enabled())
00066 
00067         # test the next method
00068         next = view.next()
00069         self.assertEquals(next['url'], self.portal.folder1.doc13.absolute_url())
00070         
00071         # test the previous method
00072         previous = view.previous()
00073         self.assertEquals(previous['url'], self.portal.folder1.doc11.absolute_url())
00074 
00075     def testAdapterOnPortal(self):
00076         view = self.portal.doc1.restrictedTraverse('@@plone_nextprevious_view', None)
00077         self.failUnless(view)
00078         self.failIf(view.enabled())
00079         self.assertEquals(None, view.next())
00080         self.assertEquals(None, view.previous())
00081 
00082     def testNextPreviousItems(self):
00083         self.folder.invokeFactory('Folder', 'case3')
00084         
00085         for documentCounter in range(1, 6):
00086             self.folder.case3.invokeFactory('Document', 'subDoc%d' % documentCounter)
00087     
00088         container  = self.folder.case3
00089         testedItem = container.subDoc2
00090         
00091         #set up the adapter for the folder
00092         adapter = INextPreviousProvider(container)
00093 
00094         #test the next item of subDoc2
00095         next = adapter.getNextItem(self.folder.case3.subDoc2)
00096         self.failUnlessEqual(next["id"], 'subDoc3')
00097 
00098         #test that the contenttype is defined correct
00099         self.failUnlessEqual(next["portal_type"], 'Document')
00100         
00101         #test the previous item of subDoc2
00102         previous = adapter.getPreviousItem(self.folder.case3.subDoc2)
00103         self.failUnlessEqual(previous["id"], 'subDoc1')
00104         
00105         #first item should not have a previous item
00106         previous = adapter.getPreviousItem(self.folder.case3.subDoc1)
00107         self.failUnlessEqual(previous, None)
00108 
00109         #last item should not have a next item
00110         next = adapter.getNextItem(self.folder.case3.subDoc5)
00111         self.failUnlessEqual(next, None)
00112 
00113 def test_suite():
00114     from unittest import TestSuite, makeSuite
00115     suite = TestSuite()
00116     suite.addTest(makeSuite(TestNextPrevious))
00117     return suite