[616] | 1 | Static Stylish portlet configlet |
---|
| 2 | ================================ |
---|
| 3 | |
---|
| 4 | Static Stylish portlet ships with it's own configuration page which you can |
---|
| 5 | access at: |
---|
| 6 | ${your/portal/url}/@@staticstylishportlet-controlpanel |
---|
| 7 | |
---|
| 8 | or from Plone Control Panel under 'Add-on Product Configuration' section. |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | Prepare testing environment |
---|
| 12 | --------------------------- |
---|
| 13 | |
---|
| 14 | We use zope.testbrowser to simulate browser interaction in order to show |
---|
| 15 | the main flow of pages. This is not a true functional test, because we also |
---|
| 16 | inspect and modify the internal state of the ZODB, but it is a useful way of |
---|
| 17 | making sure we test the full end-to-end process of creating and modifying |
---|
| 18 | content. |
---|
| 19 | |
---|
| 20 | >>> from Products.Five.testbrowser import Browser |
---|
| 21 | >>> browser = Browser() |
---|
| 22 | >>> portal_url = self.portal.absolute_url() |
---|
| 23 | |
---|
| 24 | The following is useful when writing and debugging testbrowser tests. It lets |
---|
| 25 | us see error messages properly. |
---|
| 26 | |
---|
| 27 | >>> browser.handleErrors = False |
---|
| 28 | >>> self.portal.error_log._ignored_exceptions = () |
---|
| 29 | |
---|
| 30 | We then turn off the various portlets, because they sometimes duplicate links |
---|
| 31 | and text (e.g. the navtree, the recent recent items listing) that we wish to |
---|
| 32 | test for in our own views. Having no portlets makes things easier. |
---|
| 33 | |
---|
| 34 | >>> from zope.component import getUtility, getMultiAdapter |
---|
| 35 | >>> from plone.portlets.interfaces import IPortletManager |
---|
| 36 | >>> from plone.portlets.interfaces import IPortletAssignmentMapping |
---|
| 37 | |
---|
| 38 | >>> left_column = getUtility(IPortletManager, name=u"plone.leftcolumn") |
---|
| 39 | >>> left_assignable = getMultiAdapter((self.portal, left_column), IPortletAssignmentMapping) |
---|
| 40 | >>> for name in left_assignable.keys(): |
---|
| 41 | ... del left_assignable[name] |
---|
| 42 | |
---|
| 43 | >>> right_column = getUtility(IPortletManager, name=u"plone.rightcolumn") |
---|
| 44 | >>> right_assignable = getMultiAdapter((self.portal, right_column), IPortletAssignmentMapping) |
---|
| 45 | >>> for name in right_assignable.keys(): |
---|
| 46 | ... del right_assignable[name] |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | Finally, we need to log in as the portal owner, i.e. an administrator user. We |
---|
| 50 | do this from the login page. |
---|
| 51 | |
---|
| 52 | >>> from Products.PloneTestCase.setup import portal_owner, default_password |
---|
| 53 | >>> browser.open(portal_url + '/login_form?came_from=' + portal_url) |
---|
| 54 | >>> browser.getControl(name='__ac_name').value = portal_owner |
---|
| 55 | >>> browser.getControl(name='__ac_password').value = default_password |
---|
| 56 | >>> browser.getControl(name='submit').click() |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | Configlet Registration |
---|
| 60 | ---------------------- |
---|
| 61 | |
---|
| 62 | Firstly check whether configlet is really registered: |
---|
| 63 | |
---|
| 64 | >>> from Products.CMFCore.utils import getToolByName |
---|
| 65 | >>> cp = getToolByName(self.portal, 'portal_controlpanel') |
---|
| 66 | >>> actions = [a.id for a in cp.listActions()] |
---|
| 67 | >>> 'StaticStylishPortlet' in actions |
---|
| 68 | True |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | Access to configlet |
---|
| 72 | ------------------- |
---|
| 73 | |
---|
| 74 | Let's see if we can go to /@@staticstylishportlet-controlpanel url. |
---|
| 75 | |
---|
| 76 | >>> browser.open('%s/@@staticstylishportlet-controlpanel' % portal_url) |
---|
| 77 | |
---|
| 78 | Is there configlet title on the requested page? |
---|
| 79 | |
---|
| 80 | >>> 'Static Stylish portlet settings' in browser.contents |
---|
| 81 | True |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | Configlet Validation Functionality |
---|
| 85 | ---------------------------------- |
---|
| 86 | |
---|
| 87 | Check whether validation is working properly. Set no value to new entry item. |
---|
| 88 | |
---|
| 89 | >>> browser.getControl(name='form.portlet_dropdown.add').click() |
---|
| 90 | >>> browser.getControl(name='form.portlet_dropdown.1.value').value = '' |
---|
| 91 | |
---|
| 92 | Now save form. We shoud obtain missing value error: |
---|
| 93 | |
---|
| 94 | >>> browser.getControl(name='form.actions.save').click() |
---|
| 95 | >>> 'value: Required input is missing.' in browser.contents |
---|
| 96 | True |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | Configlet Save Functionality |
---|
| 100 | ---------------------------- |
---|
| 101 | |
---|
| 102 | It's time to correct previous error-prone situation. Set missing value. |
---|
| 103 | |
---|
| 104 | >>> browser.getControl(name='form.portlet_dropdown.1.value').value = 'new_value' |
---|
| 105 | |
---|
| 106 | And submit form again. This time we should see 'Changes saved.' message: |
---|
| 107 | |
---|
| 108 | >>> browser.getControl(name='form.actions.save').click() |
---|
| 109 | >>> 'Changes saved.' in browser.contents |
---|
| 110 | True |
---|
| 111 | |
---|
| 112 | and value should be duplicated into title field since we left title input empty: |
---|
| 113 | |
---|
| 114 | >>> browser.getControl(name='form.portlet_dropdown.1.title').value |
---|
| 115 | 'new_value' |
---|
| 116 | |
---|
| 117 | And finally check portal_properties to ensure our settings page did everything |
---|
| 118 | correctly on the back end: |
---|
| 119 | |
---|
| 120 | >>> sheet = getToolByName(self.portal, 'portal_properties').staticportlet_properties |
---|
| 121 | >>> 'new_value|new_value' in sheet.getProperty('portlet_dropdown') |
---|
| 122 | True |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | Configlet Cancel Functionality |
---|
| 126 | ------------------------------ |
---|
| 127 | |
---|
| 128 | The last thing we are going to check is configlet's Cancel button: |
---|
| 129 | |
---|
| 130 | >>> browser.getControl(name='form.actions.cancel').click() |
---|
| 131 | >>> 'Changes canceled.' in browser.contents |
---|
| 132 | True |
---|
| 133 | |
---|
| 134 | >>> browser.url.endswith('/plone_control_panel') |
---|
| 135 | True |
---|
| 136 | |
---|
| 137 | As you can see Cancel button redirected us to Plone Control Panel. |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | That's it. |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|