Static Stylish portlet configlet ================================ Static Stylish portlet ships with it's own configuration page which you can access at: ${your/portal/url}/@@staticstylishportlet-controlpanel or from Plone Control Panel under 'Add-on Product Configuration' section. Prepare testing environment --------------------------- We use zope.testbrowser to simulate browser interaction in order to show the main flow of pages. This is not a true functional test, because we also inspect and modify the internal state of the ZODB, but it is a useful way of making sure we test the full end-to-end process of creating and modifying content. >>> from Products.Five.testbrowser import Browser >>> browser = Browser() >>> portal_url = self.portal.absolute_url() The following is useful when writing and debugging testbrowser tests. It lets us see error messages properly. >>> browser.handleErrors = False >>> self.portal.error_log._ignored_exceptions = () We then turn off the various portlets, because they sometimes duplicate links and text (e.g. the navtree, the recent recent items listing) that we wish to test for in our own views. Having no portlets makes things easier. >>> from zope.component import getUtility, getMultiAdapter >>> from plone.portlets.interfaces import IPortletManager >>> from plone.portlets.interfaces import IPortletAssignmentMapping >>> left_column = getUtility(IPortletManager, name=u"plone.leftcolumn") >>> left_assignable = getMultiAdapter((self.portal, left_column), IPortletAssignmentMapping) >>> for name in left_assignable.keys(): ... del left_assignable[name] >>> right_column = getUtility(IPortletManager, name=u"plone.rightcolumn") >>> right_assignable = getMultiAdapter((self.portal, right_column), IPortletAssignmentMapping) >>> for name in right_assignable.keys(): ... del right_assignable[name] Finally, we need to log in as the portal owner, i.e. an administrator user. We do this from the login page. >>> from Products.PloneTestCase.setup import portal_owner, default_password >>> browser.open(portal_url + '/login_form?came_from=' + portal_url) >>> browser.getControl(name='__ac_name').value = portal_owner >>> browser.getControl(name='__ac_password').value = default_password >>> browser.getControl(name='submit').click() Configlet Registration ---------------------- Firstly check whether configlet is really registered: >>> from Products.CMFCore.utils import getToolByName >>> cp = getToolByName(self.portal, 'portal_controlpanel') >>> actions = [a.id for a in cp.listActions()] >>> 'StaticStylishPortlet' in actions True Access to configlet ------------------- Let's see if we can go to /@@staticstylishportlet-controlpanel url. >>> browser.open('%s/@@staticstylishportlet-controlpanel' % portal_url) Is there configlet title on the requested page? >>> 'Static Stylish portlet settings' in browser.contents True Configlet Validation Functionality ---------------------------------- Check whether validation is working properly. Set no value to new entry item. >>> browser.getControl(name='form.portlet_dropdown.add').click() >>> browser.getControl(name='form.portlet_dropdown.1.value').value = '' Now save form. We shoud obtain missing value error: >>> browser.getControl(name='form.actions.save').click() >>> 'value: Required input is missing.' in browser.contents True Configlet Save Functionality ---------------------------- It's time to correct previous error-prone situation. Set missing value. >>> browser.getControl(name='form.portlet_dropdown.1.value').value = 'new_value' And submit form again. This time we should see 'Changes saved.' message: >>> browser.getControl(name='form.actions.save').click() >>> 'Changes saved.' in browser.contents True and value should be duplicated into title field since we left title input empty: >>> browser.getControl(name='form.portlet_dropdown.1.title').value 'new_value' And finally check portal_properties to ensure our settings page did everything correctly on the back end: >>> sheet = getToolByName(self.portal, 'portal_properties').staticportlet_properties >>> 'new_value|new_value' in sheet.getProperty('portlet_dropdown') True Configlet Cancel Functionality ------------------------------ The last thing we are going to check is configlet's Cancel button: >>> browser.getControl(name='form.actions.cancel').click() >>> 'Changes canceled.' in browser.contents True >>> browser.url.endswith('/plone_control_panel') True As you can see Cancel button redirected us to Plone Control Panel. That's it.