[775] | 1 | import unittest |
---|
| 2 | |
---|
[799] | 3 | from zope.interface import Interface |
---|
[775] | 4 | from zope.interface.verify import verifyClass |
---|
[799] | 5 | from zope.component import getMultiAdapter, provideAdapter |
---|
[775] | 6 | |
---|
| 7 | from Products.CMFCore.utils import getToolByName |
---|
[798] | 8 | from Products.CMFCore.ActionInformation import Action, ActionCategory |
---|
[775] | 9 | |
---|
[874] | 10 | from quintagroup.plonetabs import messageFactory as _ |
---|
[775] | 11 | from quintagroup.plonetabs.browser.interfaces import IPloneTabsControlPanel |
---|
[3402] | 12 | from quintagroup.plonetabs.browser.plonetabs \ |
---|
| 13 | import PloneTabsControlPanel as ptp |
---|
[775] | 14 | from quintagroup.plonetabs.tests.base import PloneTabsTestCase |
---|
[798] | 15 | from quintagroup.plonetabs.tests.data import PORTAL_ACTIONS |
---|
[775] | 16 | |
---|
[3402] | 17 | |
---|
[798] | 18 | class TestControlPanelHelperMethods(PloneTabsTestCase): |
---|
| 19 | """Test here configlet helper methods""" |
---|
[775] | 20 | def afterSetUp(self): |
---|
[865] | 21 | super(TestControlPanelHelperMethods, self).afterSetUp() |
---|
[775] | 22 | self.loginAsPortalOwner() |
---|
[865] | 23 | panel = getMultiAdapter((self.portal, self.portal.REQUEST), |
---|
| 24 | name='plonetabs-controlpanel') |
---|
| 25 | # we need this to apply zope2 security (got from zope2 traverse method) |
---|
| 26 | self.panel = panel.__of__(self.portal) |
---|
[775] | 27 | self.tool = getToolByName(self.portal, 'portal_actions') |
---|
[3402] | 28 | |
---|
[798] | 29 | def test_redirect(self): |
---|
| 30 | response = self.portal.REQUEST.RESPONSE |
---|
| 31 | method = self.panel.redirect |
---|
[3402] | 32 | portal_url = getMultiAdapter((self.portal, self.portal.REQUEST), |
---|
[798] | 33 | name=u"plone_portal_state").portal_url() |
---|
[865] | 34 | url = '%s/@@plonetabs-controlpanel' % portal_url |
---|
[798] | 35 | method() |
---|
| 36 | self.assertEquals(response.headers.get('location', ''), url, |
---|
| 37 | 'Redirect method is not working properly.') |
---|
[3402] | 38 | |
---|
[798] | 39 | # check query string and anchor hash |
---|
| 40 | method('http://quintagroup.com', 'q=test', 'hash_code') |
---|
| 41 | self.assertEquals(response.headers.get('location', ''), |
---|
| 42 | 'http://quintagroup.com?q=test#hash_code', |
---|
| 43 | 'Redirect method is not working properly.') |
---|
[3402] | 44 | |
---|
[798] | 45 | def test_fixExpression(self): |
---|
| 46 | method = self.panel.fixExpression |
---|
| 47 | self.assertEquals(method('/slash'), 'string:${portal_url}/slash') |
---|
[3402] | 48 | self.assertEquals(method('https://test.com'), |
---|
| 49 | 'string:https://test.com') |
---|
[798] | 50 | self.assertEquals(method('python:True'), 'python:True') |
---|
| 51 | self.assertEquals(method('hello'), 'string:${object_url}/hello') |
---|
[3402] | 52 | |
---|
[798] | 53 | def test_copyAction(self): |
---|
| 54 | data = PORTAL_ACTIONS[0][1]['children'][0][1] |
---|
| 55 | action = Action('act1', **data) |
---|
| 56 | info = self.panel.copyAction(action) |
---|
| 57 | self.assertEquals(len(info.keys()), 6) |
---|
| 58 | self.assertEquals(info['description'], 'The most important place') |
---|
[3402] | 59 | |
---|
[798] | 60 | def test_validateActionFields(self): |
---|
| 61 | method = self.panel.validateActionFields |
---|
| 62 | good_data = PORTAL_ACTIONS[0][1]['children'][0][1].copy() |
---|
| 63 | good_data['id'] = 'new_one' |
---|
| 64 | errors = method('new_category', good_data) |
---|
| 65 | self.assertEquals(errors, {}, |
---|
| 66 | 'There should be no errors for valid data.') |
---|
[3402] | 67 | |
---|
| 68 | bad_data = {'id': '', |
---|
[798] | 69 | 'title': ' ', |
---|
| 70 | 'available_expr': 'bad_type:test', |
---|
| 71 | 'url_expr': 'bad_type:test'} |
---|
[3402] | 72 | |
---|
[801] | 73 | # Revert PloneTestCase's optimization |
---|
| 74 | # because this breaks our test |
---|
| 75 | def __init__(self, text): |
---|
| 76 | self.text = text |
---|
| 77 | if text.strip(): |
---|
| 78 | self._v_compiled = getEngine().compile(text) |
---|
| 79 | from Products.CMFCore.Expression import Expression |
---|
| 80 | optimized__init__ = Expression.__init__ |
---|
| 81 | Expression.__init__ = __init__ |
---|
[798] | 82 | errors = method('new_category', bad_data) |
---|
[801] | 83 | # rollback our patch |
---|
| 84 | Expression.__init__ = optimized__init__ |
---|
[3402] | 85 | |
---|
[798] | 86 | self.assertEquals(len(errors.keys()), 4, |
---|
[801] | 87 | 'validateActionFields method is not working properly.') |
---|
[3402] | 88 | |
---|
[798] | 89 | def test_processErrors(self): |
---|
[799] | 90 | method = self.panel.processErrors |
---|
[3402] | 91 | errors = {'error': 'error message'} |
---|
[799] | 92 | self.assertEquals(method(errors), errors, |
---|
| 93 | 'processErrors method is not working properly.') |
---|
| 94 | self.assertEquals(method(errors, 'pre_', '_post'), |
---|
| 95 | {'pre_error_post': 'error message'}, |
---|
| 96 | 'processErrors method is not working properly.') |
---|
[3402] | 97 | |
---|
[798] | 98 | def test_parseEditForm(self): |
---|
[799] | 99 | method = self.panel.parseEditForm |
---|
| 100 | form = {'orig_id': 'id1', |
---|
| 101 | 'category': 'cat1', |
---|
| 102 | 'visible_id1': True, |
---|
| 103 | 'id_id1': 'id_new', |
---|
| 104 | 'title_id1': 'title1', |
---|
| 105 | 'url_expr_id1': 'expr1', |
---|
| 106 | 'available_expr_id1': 'expr2'} |
---|
| 107 | self.assertEquals(method(form), |
---|
| 108 | ('id1', 'cat1', {'id': 'id_new', |
---|
| 109 | 'title': 'title1', |
---|
| 110 | 'url_expr': 'expr1', |
---|
| 111 | 'available_expr': 'expr2', |
---|
| 112 | 'visible': True}), |
---|
| 113 | 'parseEditForm method is not working properly.') |
---|
[3402] | 114 | |
---|
[799] | 115 | del form['orig_id'] |
---|
| 116 | self.failUnlessRaises(KeyError, method, form) |
---|
[3402] | 117 | |
---|
[798] | 118 | def test_parseAddForm(self): |
---|
[799] | 119 | method = self.panel.parseAddForm |
---|
| 120 | form = {'id': 'id1', |
---|
| 121 | 'category': 'cat1', |
---|
| 122 | 'visible': True, |
---|
| 123 | 'title': 'title1', |
---|
| 124 | 'url_expr': 'string:expr1', |
---|
| 125 | 'available_expr': 'expr2'} |
---|
| 126 | self.assertEquals(method(form), |
---|
| 127 | ('id1', 'cat1', {'id': 'id1', |
---|
| 128 | 'visible': True, |
---|
| 129 | 'title': 'title1', |
---|
| 130 | 'url_expr': 'string:expr1', |
---|
| 131 | 'available_expr': 'expr2'}), |
---|
| 132 | 'parseAddForm method is not working properly.') |
---|
[3402] | 133 | |
---|
[799] | 134 | del form['id'] |
---|
| 135 | self.failUnlessRaises(KeyError, method, form) |
---|
[3402] | 136 | |
---|
[798] | 137 | def test_getActionCategory(self): |
---|
[799] | 138 | method = self.panel.getActionCategory |
---|
| 139 | self.purgeActions() |
---|
| 140 | self.failUnlessRaises(KeyError, method, 'portal_tabs') |
---|
[3402] | 141 | |
---|
[799] | 142 | self.setupActions(self.tool) |
---|
| 143 | self.assertEquals(method('portal_tabs').id, 'portal_tabs', |
---|
| 144 | 'getActionCategory is not working properly.') |
---|
[3402] | 145 | |
---|
[798] | 146 | def test_getOrCreateCategory(self): |
---|
[799] | 147 | method = self.panel.getOrCreateCategory |
---|
| 148 | self.purgeActions() |
---|
| 149 | self.assertEquals(method('portal_tabs').id, 'portal_tabs', |
---|
| 150 | 'getOrCreateCategory is not working properly.') |
---|
[3402] | 151 | |
---|
[798] | 152 | def test_setSiteProperties(self): |
---|
[799] | 153 | self.panel.setSiteProperties(title='Test Title') |
---|
| 154 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 155 | self.assertEquals(sp.getProperty('title'), 'Test Title', |
---|
| 156 | 'setSiteProperties method is not working properly.') |
---|
[3402] | 157 | |
---|
[798] | 158 | def test_renderViewlet(self): |
---|
[799] | 159 | # register test viewlet and it's manager |
---|
| 160 | from zope.viewlet.interfaces import IViewlet, IViewletManager |
---|
| 161 | from zope.viewlet.viewlet import ViewletBase |
---|
| 162 | from zope.viewlet.manager import ViewletManagerBase |
---|
| 163 | from zope.publisher.interfaces.browser import IDefaultBrowserLayer |
---|
| 164 | from zope.publisher.interfaces.browser import IBrowserView |
---|
[3402] | 165 | |
---|
[799] | 166 | class TestViewlet(ViewletBase): |
---|
| 167 | def __of__(self, obj): |
---|
| 168 | return self |
---|
[3402] | 169 | |
---|
[799] | 170 | def render(self): |
---|
| 171 | return 'test viewlet' |
---|
[3402] | 172 | |
---|
[799] | 173 | provideAdapter( |
---|
| 174 | TestViewlet, |
---|
| 175 | (Interface, IDefaultBrowserLayer, IBrowserView, IViewletManager), |
---|
| 176 | IViewlet, |
---|
| 177 | name=u'test_viewlet') |
---|
| 178 | provideAdapter( |
---|
| 179 | ViewletManagerBase, |
---|
| 180 | (Interface, IDefaultBrowserLayer, IBrowserView), |
---|
| 181 | IViewletManager, |
---|
| 182 | name=u'test_manager') |
---|
[3402] | 183 | |
---|
[799] | 184 | self.assertEquals( |
---|
| 185 | self.panel.renderViewlet('test_manager', 'test_viewlet'), |
---|
| 186 | 'test viewlet', |
---|
| 187 | 'renderViewlet method is not workig properly') |
---|
[3402] | 188 | |
---|
[798] | 189 | def test_addAction(self): |
---|
[799] | 190 | self.purgeActions() |
---|
[3402] | 191 | self.panel.addAction('new_category', {'id': 'id1', 'title': 'Test'}) |
---|
[799] | 192 | self.failUnless('id1' in self.tool.new_category.objectIds(), |
---|
| 193 | 'addAction method is not workig properly') |
---|
[3402] | 194 | |
---|
[798] | 195 | def test_updateAction(self): |
---|
[799] | 196 | method = self.panel.updateAction |
---|
[3402] | 197 | |
---|
[799] | 198 | self.purgeActions() |
---|
[3402] | 199 | self.failUnlessRaises(KeyError, method, 'id1', 'cat1', {'id': 'new'}) |
---|
| 200 | |
---|
[799] | 201 | self.setupActions(self.tool) |
---|
| 202 | # we need to commit transaction because |
---|
| 203 | # we are going to rename just added action now |
---|
| 204 | import transaction |
---|
| 205 | transaction.savepoint() |
---|
[3402] | 206 | method('home', 'portal_tabs', {'id': 'new_home'}) |
---|
[799] | 207 | self.failUnless('new_home' in self.tool.portal_tabs.objectIds(), |
---|
| 208 | 'updateAction method is not workig properly') |
---|
[3402] | 209 | |
---|
[798] | 210 | def test_deleteAction(self): |
---|
[799] | 211 | self.purgeActions() |
---|
| 212 | self.setupActions(self.tool) |
---|
| 213 | self.panel.deleteAction('home', 'portal_tabs') |
---|
| 214 | self.failIf('home' in self.tool.portal_tabs.objectIds(), |
---|
| 215 | 'deleteAction method is not workig properly') |
---|
[3402] | 216 | |
---|
[798] | 217 | def test_moveAction(self): |
---|
[799] | 218 | self.purgeActions() |
---|
| 219 | self.setupActions(self.tool) |
---|
| 220 | pos = self.tool.portal_tabs.getObjectPosition |
---|
| 221 | self.assertEquals(pos('home'), 0, |
---|
| 222 | 'moveAction method is not workig properly') |
---|
| 223 | self.panel.moveAction('home', 'portal_tabs', -1) |
---|
| 224 | self.assertEquals(pos('home'), 1, |
---|
| 225 | 'moveAction method is not workig properly') |
---|
[798] | 226 | |
---|
| 227 | |
---|
[917] | 228 | class TestControlPanelAPIMethods(PloneTabsTestCase): |
---|
[798] | 229 | """Test here interface methods of control panel class""" |
---|
[3402] | 230 | |
---|
[798] | 231 | def afterSetUp(self): |
---|
[917] | 232 | super(TestControlPanelAPIMethods, self).afterSetUp() |
---|
[798] | 233 | self.loginAsPortalOwner() |
---|
[865] | 234 | panel = getMultiAdapter((self.portal, self.portal.REQUEST), |
---|
| 235 | name='plonetabs-controlpanel') |
---|
| 236 | # we need this to apply zope2 security (got from zope2 traverse method) |
---|
| 237 | self.panel = panel.__of__(self.portal) |
---|
[798] | 238 | self.tool = getToolByName(self.portal, 'portal_actions') |
---|
[3402] | 239 | |
---|
[775] | 240 | def test_interface(self): |
---|
| 241 | self.failUnless(IPloneTabsControlPanel.implementedBy(ptp), |
---|
| 242 | 'PloneTabs control panel does not implement required interface.') |
---|
| 243 | self.failUnless(verifyClass(IPloneTabsControlPanel, ptp), |
---|
| 244 | 'PloneTabs control panel does not implement required interface.') |
---|
[3402] | 245 | |
---|
[775] | 246 | def test_getPageTitle(self): |
---|
| 247 | self.assertEquals(self.panel.getPageTitle(), |
---|
[874] | 248 | _(u"Portal Tabs Configuration"), |
---|
[775] | 249 | 'getPageTitle method is broken') |
---|
| 250 | self.assertEquals(self.panel.getPageTitle(category='notexists'), |
---|
[874] | 251 | _(u"Plone '${cat_name}' Configuration", |
---|
| 252 | mapping={'cat_name': 'notexists'}), |
---|
[775] | 253 | 'getPageTitle method is broken') |
---|
[3402] | 254 | |
---|
[775] | 255 | def test_hasActions(self): |
---|
| 256 | method = self.panel.hasActions |
---|
| 257 | # purge any default portal actions |
---|
| 258 | self.purgeActions() |
---|
| 259 | self.failIf(method(), |
---|
| 260 | 'There should be no portal_tab actions in portal') |
---|
[3402] | 261 | |
---|
[775] | 262 | # setup our own actions |
---|
| 263 | self.setupActions(self.tool) |
---|
| 264 | self.failUnless(method(), |
---|
| 265 | 'There should be portal_tab actions in portal') |
---|
[3402] | 266 | |
---|
[775] | 267 | def test_getPortalActions(self): |
---|
| 268 | method = self.panel.getPortalActions |
---|
| 269 | # purge any default portal actions |
---|
| 270 | self.purgeActions() |
---|
| 271 | self.assertEquals(len(method()), 0, |
---|
| 272 | 'There should be no actions in portal_tabs category.') |
---|
[3402] | 273 | |
---|
[775] | 274 | # setup our own actions |
---|
| 275 | self.setupActions(self.tool) |
---|
| 276 | self.assertEquals(len(method()), 2, |
---|
| 277 | 'There should be 2 actions in portal_tabs category.') |
---|
[3402] | 278 | |
---|
[775] | 279 | # marginal arguments |
---|
| 280 | self.assertEquals(len(method('notexistent_category')), 0, |
---|
| 281 | 'There should be no actions for not existed category.') |
---|
[3402] | 282 | |
---|
[775] | 283 | def test_isGeneratedTabs(self): |
---|
| 284 | method = self.panel.isGeneratedTabs |
---|
| 285 | # prepare value |
---|
| 286 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 287 | sp.manage_changeProperties(disable_folder_sections=True) |
---|
| 288 | self.failIf(method(), 'But folder sections are disabled...') |
---|
[3402] | 289 | |
---|
[775] | 290 | def test_isNotFoldersGenerated(self): |
---|
| 291 | method = self.panel.isNotFoldersGenerated |
---|
| 292 | # prepare value |
---|
| 293 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 294 | sp.manage_changeProperties(disable_nonfolderish_sections=True) |
---|
| 295 | self.failIf(method(), 'But non folderish sections are disabled...') |
---|
[3402] | 296 | |
---|
[775] | 297 | def test_getActionsList(self): |
---|
| 298 | method = self.panel.getActionsList |
---|
| 299 | # purge any default portal actions |
---|
| 300 | self.purgeActions() |
---|
| 301 | self.failIf('class="editform"' in method(), |
---|
| 302 | 'There should no be actions in actions list template.') |
---|
| 303 | self.setupActions(self.tool) |
---|
| 304 | self.failUnless('class="editform"' in method(), |
---|
| 305 | 'There are no actions in actions list template.') |
---|
[3402] | 306 | |
---|
[775] | 307 | def test_getAutoGenereatedSection(self): |
---|
| 308 | method = self.panel.getAutoGenereatedSection |
---|
| 309 | self.failIf('<form' in method('user'), |
---|
| 310 | 'There should be no form in autogenerated tabs template ' |
---|
| 311 | 'for category other than portal_tabs.') |
---|
| 312 | self.failUnless('<form' in method('portal_tabs'), |
---|
| 313 | 'There should be form in autogenerated tabs template ' |
---|
| 314 | 'for portal_tabs category.') |
---|
[3402] | 315 | |
---|
[775] | 316 | def test_getGeneratedTabs(self): |
---|
| 317 | self.panel.getGeneratedTabs() |
---|
| 318 | # check expiration header set by generated tabs template |
---|
| 319 | self.assertEquals( |
---|
| 320 | self.portal.REQUEST.RESPONSE.headers.get('expires', ''), |
---|
| 321 | 'Mon, 26 Jul 1996 05:00:00 GMT', |
---|
| 322 | 'Expiration header is not set properly.') |
---|
[3402] | 323 | |
---|
[775] | 324 | def test_getRootTabs(self): |
---|
| 325 | method = self.panel.getRootTabs |
---|
| 326 | # make sure we don't depend on external settings |
---|
| 327 | self.purgeContent() |
---|
| 328 | self.assertEquals(len(method()), 0, |
---|
| 329 | 'There should be no root elements for navigation.') |
---|
[3402] | 330 | |
---|
[775] | 331 | # now add some testing content |
---|
| 332 | self.setupContent(self.portal) |
---|
| 333 | self.assertEquals(len(method()), 2, |
---|
| 334 | 'There should be 2 elements in portal root for navigation.') |
---|
[3402] | 335 | |
---|
[775] | 336 | # now switch off autogeneration |
---|
| 337 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 338 | sp.manage_changeProperties(disable_folder_sections=True) |
---|
| 339 | self.assertEquals(len(method()), 0, |
---|
| 340 | 'There should be no root elements for navigation when ' |
---|
| 341 | 'tabs autogeneration is switched off.') |
---|
[3402] | 342 | |
---|
[775] | 343 | def test_getCategories(self): |
---|
| 344 | method = self.panel.getCategories |
---|
| 345 | # purge any default portal actions |
---|
| 346 | self.purgeActions() |
---|
| 347 | self.assertEquals(len(method()), 0, |
---|
| 348 | 'There should be no categories in portal_actions tool.') |
---|
[3402] | 349 | |
---|
[775] | 350 | # now setup actions |
---|
| 351 | self.setupActions(self.tool) |
---|
| 352 | self.assertEquals(method(), ['portal_tabs', 'new_category'], |
---|
| 353 | 'There should be exactly 2 categories in portal_actions tool.') |
---|
[3402] | 354 | |
---|
[775] | 355 | def test_portal_tabs(self): |
---|
| 356 | method = self.panel.portal_tabs |
---|
| 357 | self.purgeContent() |
---|
| 358 | self.purgeActions() |
---|
| 359 | self.assertEquals(len(method()), 0, |
---|
| 360 | 'There should be no portal tabs.') |
---|
[3402] | 361 | |
---|
[798] | 362 | # cleanup memoize cache |
---|
| 363 | # cause actions method of portal context state is caching it's |
---|
| 364 | # results in request and we have the same request for every call |
---|
| 365 | self.purgeCache(self.portal.REQUEST) |
---|
[3402] | 366 | |
---|
[775] | 367 | # add actions |
---|
| 368 | self.setupActions(self.tool) |
---|
| 369 | self.assertEquals(len(method()), 2, |
---|
| 370 | 'There should be 2 portal tabs.') |
---|
[3402] | 371 | |
---|
[775] | 372 | # add content |
---|
| 373 | self.setupContent(self.portal) |
---|
| 374 | self.assertEquals(len(method()), 4, |
---|
| 375 | 'There should be 4 portal tabs.') |
---|
[3402] | 376 | |
---|
[775] | 377 | def test_selected_portal_tab(self): |
---|
[798] | 378 | self.assertEquals(self.panel.selected_portal_tab(), 'index_html', |
---|
| 379 | 'index_html is not selected tab while being on configlet.') |
---|
[775] | 380 | |
---|
| 381 | def test_test(self): |
---|
[798] | 382 | self.assertEquals(self.panel.test(True, 'true', 'false'), 'true', |
---|
[801] | 383 | 'Test function does not work properly.') |
---|
[775] | 384 | |
---|
| 385 | |
---|
[801] | 386 | class TestControlPanelManageMethods(PloneTabsTestCase): |
---|
| 387 | """Test here management methods of control panel class""" |
---|
[3402] | 388 | |
---|
[801] | 389 | def afterSetUp(self): |
---|
[865] | 390 | super(TestControlPanelManageMethods, self).afterSetUp() |
---|
[801] | 391 | self.loginAsPortalOwner() |
---|
[865] | 392 | panel = getMultiAdapter((self.portal, self.portal.REQUEST), |
---|
| 393 | name='plonetabs-controlpanel') |
---|
| 394 | # we need this to apply zope2 security (got from zope2 traverse method) |
---|
| 395 | self.panel = panel.__of__(self.portal) |
---|
[801] | 396 | self.tool = getToolByName(self.portal, 'portal_actions') |
---|
[3402] | 397 | |
---|
[801] | 398 | # purge standard set of actions and set our own testing ones |
---|
| 399 | self.purgeActions() |
---|
| 400 | self.setupActions(self.tool) |
---|
[3402] | 401 | |
---|
[801] | 402 | def test_manage_setAutogeneration(self): |
---|
| 403 | self.setupContent(self.portal) |
---|
| 404 | form = {'generated_tabs': '1', |
---|
| 405 | 'nonfolderish_tabs': '0', |
---|
| 406 | 'folder1': '0'} |
---|
| 407 | self.panel.manage_setAutogeneration(form, {}) |
---|
| 408 | self.failUnless(self.portal.folder1.exclude_from_nav()) |
---|
| 409 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 410 | self.failIf(sp.disable_folder_sections) |
---|
| 411 | self.failUnless(sp.disable_nonfolderish_sections) |
---|
[3402] | 412 | |
---|
[801] | 413 | def test_manage_addAction(self): |
---|
| 414 | self.purgeActions() |
---|
| 415 | form = {'id': 'id1', |
---|
| 416 | 'category': 'cat1', |
---|
| 417 | 'visible': True, |
---|
| 418 | 'title': 'title1', |
---|
| 419 | 'url_expr': 'string:expr1', |
---|
| 420 | 'available_expr': 'expr2'} |
---|
| 421 | postback = self.panel.manage_addAction(form, {}) |
---|
| 422 | self.failUnless('id1' in self.tool.cat1.objectIds()) |
---|
| 423 | self.failIf(postback, |
---|
| 424 | 'There should be redirect after successfull adding.') |
---|
[3402] | 425 | |
---|
[801] | 426 | def test_manage_editAction(self): |
---|
| 427 | method = self.panel.manage_editAction |
---|
| 428 | self.purgeActions() |
---|
| 429 | self.setupActions(self.tool) |
---|
| 430 | form = {'orig_id': 'home', |
---|
| 431 | 'category': 'portal_tabs', |
---|
| 432 | 'visible_home': True, |
---|
| 433 | 'id_home': 'id_new', |
---|
| 434 | 'title_home': 'title1', |
---|
| 435 | 'url_expr_home': 'expr1', |
---|
| 436 | 'available_expr_home': 'expr2'} |
---|
| 437 | import transaction |
---|
| 438 | transaction.savepoint() |
---|
[3402] | 439 | |
---|
[801] | 440 | postback = method(form, {}) |
---|
| 441 | self.failUnless('id_new' in self.tool.portal_tabs.objectIds()) |
---|
| 442 | self.failIf(postback, |
---|
| 443 | 'There should be redirect after successfull edition.') |
---|
[3402] | 444 | |
---|
[801] | 445 | form['category'] = 'non_existent' |
---|
| 446 | self.failUnlessRaises(KeyError, method, form, {}) |
---|
[3402] | 447 | |
---|
[801] | 448 | def test_manage_deleteAction(self): |
---|
| 449 | self.purgeActions() |
---|
| 450 | self.setupActions(self.tool) |
---|
| 451 | form = {'orig_id': 'home', |
---|
| 452 | 'category': 'portal_tabs', |
---|
| 453 | 'visible_home': True, |
---|
| 454 | 'id_home': 'id_new', |
---|
| 455 | 'title_home': 'title1', |
---|
| 456 | 'url_expr_home': 'expr1', |
---|
| 457 | 'available_expr_home': 'expr2'} |
---|
| 458 | self.panel.manage_deleteAction(form, {}) |
---|
| 459 | self.failIf('home' in self.tool.portal_tabs.objectIds()) |
---|
[3402] | 460 | |
---|
[801] | 461 | def test_manage_moveUpAction(self): |
---|
| 462 | self.purgeActions() |
---|
| 463 | self.setupActions(self.tool) |
---|
| 464 | form = {'orig_id': 'quintagroup', |
---|
| 465 | 'category': 'portal_tabs', |
---|
| 466 | 'visible_quintagroup': True, |
---|
| 467 | 'id_quintagroup': 'quintagroup', |
---|
| 468 | 'title_quintagroup': 'title1', |
---|
| 469 | 'url_expr_quintagroup': 'expr1', |
---|
| 470 | 'available_expr_quintagroup': 'expr2'} |
---|
| 471 | self.panel.manage_moveUpAction(form, {}) |
---|
| 472 | self.assertEquals( |
---|
| 473 | self.tool.portal_tabs.getObjectPosition('quintagroup'), 0) |
---|
[3402] | 474 | |
---|
[801] | 475 | def test_manage_moveDownAction(self): |
---|
| 476 | self.purgeActions() |
---|
| 477 | self.setupActions(self.tool) |
---|
| 478 | form = {'orig_id': 'home', |
---|
| 479 | 'category': 'portal_tabs', |
---|
| 480 | 'visible_home': True, |
---|
| 481 | 'id_home': 'home', |
---|
| 482 | 'title_home': 'title1', |
---|
| 483 | 'url_expr_home': 'expr1', |
---|
| 484 | 'available_expr_home': 'expr2'} |
---|
| 485 | self.panel.manage_moveDownAction(form, {}) |
---|
| 486 | self.assertEquals(self.tool.portal_tabs.getObjectPosition('home'), 1) |
---|
| 487 | |
---|
| 488 | |
---|
[775] | 489 | def test_suite(): |
---|
| 490 | suite = unittest.TestSuite() |
---|
[798] | 491 | suite.addTest(unittest.makeSuite(TestControlPanelHelperMethods)) |
---|
[917] | 492 | suite.addTest(unittest.makeSuite(TestControlPanelAPIMethods)) |
---|
[801] | 493 | suite.addTest(unittest.makeSuite(TestControlPanelManageMethods)) |
---|
[3402] | 494 | |
---|
[865] | 495 | # these tests are implemented as Selenium KSS Tests |
---|
| 496 | # using kss.demo package, and KSS plugins are tested by means of |
---|
| 497 | # ecmaunit.js |
---|
[775] | 498 | #suite.addTest(unittest.makeSuite(TestControlPanelKSSMethods)) |
---|
| 499 | return suite |
---|