1 | import unittest |
---|
2 | |
---|
3 | from zope.component import getMultiAdapter |
---|
4 | from zope.interface.verify import verifyClass |
---|
5 | |
---|
6 | from Products.CMFCore.utils import getToolByName |
---|
7 | |
---|
8 | from quintagroup.plonetabs.browser.interfaces import IPloneTabsControlPanel |
---|
9 | from quintagroup.plonetabs.browser.plonetabs import PloneTabsControlPanel as ptp |
---|
10 | from quintagroup.plonetabs.tests.base import PloneTabsTestCase |
---|
11 | |
---|
12 | class TestControlPanelAPI(PloneTabsTestCase): |
---|
13 | """Test here interface methods of control panel class""" |
---|
14 | |
---|
15 | def afterSetUp(self): |
---|
16 | self.loginAsPortalOwner() |
---|
17 | # TODO: investigate why I can't work with it but |
---|
18 | # have to traverse my view |
---|
19 | #self.panel = getMultiAdapter((self.portal, self.portal.REQUEST), |
---|
20 | #name='plonetabs-controlpanel') |
---|
21 | self.panel = self.portal.restrictedTraverse('plonetabs-controlpanel') |
---|
22 | self.tool = getToolByName(self.portal, 'portal_actions') |
---|
23 | |
---|
24 | def test_interface(self): |
---|
25 | self.failUnless(IPloneTabsControlPanel.implementedBy(ptp), |
---|
26 | 'PloneTabs control panel does not implement required interface.') |
---|
27 | self.failUnless(verifyClass(IPloneTabsControlPanel, ptp), |
---|
28 | 'PloneTabs control panel does not implement required interface.') |
---|
29 | |
---|
30 | def test_getPageTitle(self): |
---|
31 | self.assertEquals(self.panel.getPageTitle(), |
---|
32 | 'Portal Tabs Configuration', |
---|
33 | 'getPageTitle method is broken') |
---|
34 | self.assertEquals(self.panel.getPageTitle(category='notexists'), |
---|
35 | "Plone '%s' Configuration" % 'notexists', |
---|
36 | 'getPageTitle method is broken') |
---|
37 | |
---|
38 | def test_hasActions(self): |
---|
39 | method = self.panel.hasActions |
---|
40 | # purge any default portal actions |
---|
41 | self.purgeActions() |
---|
42 | self.failIf(method(), |
---|
43 | 'There should be no portal_tab actions in portal') |
---|
44 | |
---|
45 | # setup our own actions |
---|
46 | self.setupActions(self.tool) |
---|
47 | self.failUnless(method(), |
---|
48 | 'There should be portal_tab actions in portal') |
---|
49 | |
---|
50 | def test_getPortalActions(self): |
---|
51 | method = self.panel.getPortalActions |
---|
52 | # purge any default portal actions |
---|
53 | self.purgeActions() |
---|
54 | self.assertEquals(len(method()), 0, |
---|
55 | 'There should be no actions in portal_tabs category.') |
---|
56 | |
---|
57 | # setup our own actions |
---|
58 | self.setupActions(self.tool) |
---|
59 | self.assertEquals(len(method()), 2, |
---|
60 | 'There should be 2 actions in portal_tabs category.') |
---|
61 | |
---|
62 | # marginal arguments |
---|
63 | self.assertEquals(len(method('notexistent_category')), 0, |
---|
64 | 'There should be no actions for not existed category.') |
---|
65 | |
---|
66 | def test_isGeneratedTabs(self): |
---|
67 | method = self.panel.isGeneratedTabs |
---|
68 | # prepare value |
---|
69 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
70 | sp.manage_changeProperties(disable_folder_sections=True) |
---|
71 | self.failIf(method(), 'But folder sections are disabled...') |
---|
72 | |
---|
73 | def test_isNotFoldersGenerated(self): |
---|
74 | method = self.panel.isNotFoldersGenerated |
---|
75 | # prepare value |
---|
76 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
77 | sp.manage_changeProperties(disable_nonfolderish_sections=True) |
---|
78 | self.failIf(method(), 'But non folderish sections are disabled...') |
---|
79 | |
---|
80 | def test_getActionsList(self): |
---|
81 | method = self.panel.getActionsList |
---|
82 | # purge any default portal actions |
---|
83 | self.purgeActions() |
---|
84 | self.failIf('class="editform"' in method(), |
---|
85 | 'There should no be actions in actions list template.') |
---|
86 | self.setupActions(self.tool) |
---|
87 | self.failUnless('class="editform"' in method(), |
---|
88 | 'There are no actions in actions list template.') |
---|
89 | |
---|
90 | def test_getAutoGenereatedSection(self): |
---|
91 | method = self.panel.getAutoGenereatedSection |
---|
92 | self.failIf('<form' in method('user'), |
---|
93 | 'There should be no form in autogenerated tabs template ' |
---|
94 | 'for category other than portal_tabs.') |
---|
95 | self.failUnless('<form' in method('portal_tabs'), |
---|
96 | 'There should be form in autogenerated tabs template ' |
---|
97 | 'for portal_tabs category.') |
---|
98 | |
---|
99 | def test_getGeneratedTabs(self): |
---|
100 | self.panel.getGeneratedTabs() |
---|
101 | # check expiration header set by generated tabs template |
---|
102 | self.assertEquals( |
---|
103 | self.portal.REQUEST.RESPONSE.headers.get('expires', ''), |
---|
104 | 'Mon, 26 Jul 1996 05:00:00 GMT', |
---|
105 | 'Expiration header is not set properly.') |
---|
106 | |
---|
107 | def test_getRootTabs(self): |
---|
108 | method = self.panel.getRootTabs |
---|
109 | # make sure we don't depend on external settings |
---|
110 | self.purgeContent() |
---|
111 | self.assertEquals(len(method()), 0, |
---|
112 | 'There should be no root elements for navigation.') |
---|
113 | |
---|
114 | # now add some testing content |
---|
115 | self.setupContent(self.portal) |
---|
116 | self.assertEquals(len(method()), 2, |
---|
117 | 'There should be 2 elements in portal root for navigation.') |
---|
118 | |
---|
119 | # now switch off autogeneration |
---|
120 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
121 | sp.manage_changeProperties(disable_folder_sections=True) |
---|
122 | self.assertEquals(len(method()), 0, |
---|
123 | 'There should be no root elements for navigation when ' |
---|
124 | 'tabs autogeneration is switched off.') |
---|
125 | |
---|
126 | def test_getCategories(self): |
---|
127 | method = self.panel.getCategories |
---|
128 | # purge any default portal actions |
---|
129 | self.purgeActions() |
---|
130 | self.assertEquals(len(method()), 0, |
---|
131 | 'There should be no categories in portal_actions tool.') |
---|
132 | |
---|
133 | # now setup actions |
---|
134 | self.setupActions(self.tool) |
---|
135 | self.assertEquals(method(), ['portal_tabs', 'new_category'], |
---|
136 | 'There should be exactly 2 categories in portal_actions tool.') |
---|
137 | |
---|
138 | def test_portal_tabs(self): |
---|
139 | # this test doesn't work yet, view should be retrieved with another |
---|
140 | # context, request pair for not to cache results |
---|
141 | method = self.panel.portal_tabs |
---|
142 | self.purgeContent() |
---|
143 | self.purgeActions() |
---|
144 | self.assertEquals(len(method()), 0, |
---|
145 | 'There should be no portal tabs.') |
---|
146 | |
---|
147 | # add actions |
---|
148 | self.setupActions(self.tool) |
---|
149 | method = ( |
---|
150 | self.portal.restrictedTraverse('plonetabs-controlpanel').portal_tabs |
---|
151 | ) |
---|
152 | self.assertEquals(len(method()), 2, |
---|
153 | 'There should be 2 portal tabs.') |
---|
154 | |
---|
155 | # add content |
---|
156 | self.setupContent(self.portal) |
---|
157 | self.assertEquals(len(method()), 4, |
---|
158 | 'There should be 4 portal tabs.') |
---|
159 | |
---|
160 | def test_selected_portal_tab(self): |
---|
161 | pass |
---|
162 | |
---|
163 | def test_test(self): |
---|
164 | pass |
---|
165 | |
---|
166 | |
---|
167 | def test_suite(): |
---|
168 | suite = unittest.TestSuite() |
---|
169 | #suite.addTest(unittest.makeSuite(TestControlPanelHelperMethods)) |
---|
170 | suite.addTest(unittest.makeSuite(TestControlPanelAPI)) |
---|
171 | #suite.addTest(unittest.makeSuite(TestControlPanelManageMethods)) |
---|
172 | #suite.addTest(unittest.makeSuite(TestControlPanelKSSMethods)) |
---|
173 | return suite |
---|