Set manager role for test user

    >>> from plone.app.testing import TEST_USER_ID, TEST_USER_NAME
    >>> from plone.app.testing import TEST_USER_PASSWORD
    >>> from plone.portlets.constants import USER_CATEGORY
    >>> from plone.testing.z2 import Browser
    >>> import transaction
    >>> from plone.portlets.utils import unhashPortletInfo, hashPortletInfo

    >>> portal = layer['portal']
    >>> portal_url = portal.absolute_url()

    >>> props = portal.portal_properties.get('ftw.dashboard')

    >>> portal = layer['portal']
    >>> portal_url = portal.absolute_url()
    >>> props = portal.portal_properties.get('ftw.dashboard')
    >>> props._setPropValue('dashboardEditable', True)
    >>> transaction.commit()

Define browser client
    >>> browser = Browser(layer['app'])

Login
    >>> browser.open(portal_url + '/login_form')
    >>> browser.getControl(name='__ac_name').value = TEST_USER_NAME
    >>> browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD
    >>> browser.getControl(name='submit').click()


Add again a Calendar portlet

    >>> browser.open(portal_url + '/++dashboard++plone.dashboard1+' + TEST_USER_ID + '/+/portlets.Calendar')
    >>> browser.open(portal_url + '/dashboard')
    >>> browser.contents.count('portletCalendar')
    1
    
Test remove action for the given portlets
    >>> url = portal_url + '/ftw.dashboard.dragndrop-removeportlet'

Construct hash for the exitsing calendar portlet

    >>> info = dict(manager = 'plone.dashboard1',
    ...    category = USER_CATEGORY,
    ...    key = TEST_USER_ID,
    ...    name = 'calendar')
    >>> portlethash = hashPortletInfo(info)
    >>> params = '?hash=%s' % portlethash

Remove Portlet

    >>> browser.open(url + params)
    >>> browser.open(portal_url + '/dashboard')
    >>> 'portletCalendar' in browser.contents
    False
    
    
Add a new editable portlets (rss portlet)

    >>> url = '/++dashboard++plone.dashboard1+' + TEST_USER_ID + '/+/portlets.rss'
    >>> browser.open(portal_url + url)
    >>> browser.getControl(name='form.url').value = u'http://www.heise.de/newsticker/heise.rdf'
    >>> browser.getControl(name='form.actions.save').click()


Call edit view
    >>> info = dict(manager = 'plone.dashboard1',
    ...    category = USER_CATEGORY,
    ...    key = TEST_USER_ID,
    ...    name = 'rss-http-www-heise-de')
    >>> portlethash = hashPortletInfo(info)

Double check the result

    >>> browser.open('dashboardEditLinkView?hash=' + portlethash)
    http://nohost/plone/++dashboard++plone.dashboard1+test_user_1_/rss-http-www-heise-de/edit?referer=localhost
    >>> 'Edit RSS Portlet' in browser.contents
    True
    
Fold portlet

    >>> browser.open('ftw.dashboard.dragndrop-foldportlet?folded=1&hash='+portlethash)

Check portlet has attr isFolded ( and it should be True)

    >>> from zope.component import getUtility
    >>> from plone.portlets.interfaces import IPortletManager
    >>> column_manager = getUtility(IPortletManager, name='plone.dashboard1')
    >>> column = column_manager.get(USER_CATEGORY, {}).get(TEST_USER_ID, {})
    >>> portlet = column.get('rss-http-www-heise-de')
    >>> getattr(portlet, 'isFolded', False)
    True
    
    
Test reordering of portlets
For this case, add one more portlet to the same column as the rss portlet is

    >>> url = '/++dashboard++plone.dashboard1+' + TEST_USER_ID + '/+/portlets.Calendar'
    >>> browser.open(portal_url + url)

Create parameter for reorder function
The reorder function looks for "portlets:list"
btw: info is still out rss portlet (first position)
    >>> portlet1 = 'portlets:list=plone.dashboard1:' + portlethash

Second portlet
    >>> info2 = dict(manager = 'plone.dashboard1',
    ...    category = USER_CATEGORY,
    ...    key = TEST_USER_ID,
    ...    name = 'calendar')
    >>> portlethash2 = hashPortletInfo(info)
    >>> portlet2 = 'portlets:list=plone.dashboard1:' + portlethash2

Currently portlet1 is rendered befor portlet2
    
    >>> browser.open(portal_url + "/dashboard")
    >>> browser.contents.find('portletRss') < browser.contents.find('portletCalendar')
    True

    Change the order
    
    >>> url = '/ftw.dashboard.dragndrop-update_order?%s&%s' % (portlet2, portlet1)
    >>> browser.open(portal_url + url)
    >>> browser.open(portal_url + "/dashboard")

Now the rss portlet should be rendered after the calendar portelt

    >>> browser.contents.find('portletRss') > browser.contents.find('portletCalendar')
    True

Move calendar portlet to column 2
Use precalculated hashes

    >>> params = "portlets:list=plone.dashboard1:706c6f6e652e64617368626f617264310a757365720a7a6f70656d61737465720a7273732d68656973652d6f6e6c696e652d6e657773&portlets:list=plone.dashboard1:706c6f6e652e64617368626f617264310a757365720a7a6f70656d61737465720a7273732d687474702d7777772d68656973652d6465&portlets:list=plone.dashboard2:706c6f6e652e64617368626f617264310a757365720a7a6f70656d61737465720a63616c656e646172"
    >>> url = '/ftw.dashboard.dragndrop-update_order?'+params
    >>> browser.open(portal_url + url)
    >>> params2 = "portlets:list=plone.dashboard1:706c6f6e652e64617368626f617264310a757365720a7a6f70656d61737465720a7273732d68656973652d6f6e6c696e652d6e657773&portlets:list=plone.dashboard1:706c6f6e652e64617368626f617264310a757365720a7a6f70656d61737465720a7273732d687474702d7777772d68656973652d6465&portlets:list=plone.dashboard2:706c6f6e652e64617368626f617264320a757365720a7a6f70656d61737465720a63616c656e646172"
    >>> url2 = '/ftw.dashboard.dragndrop-update_order?'+params2
    >>> browser.open(portal_url + url2)
    >>> browser.open(portal_url + "/dashboard")

Check if the new portlet hash is available

    >>> newhash = '706c6f6e652e64617368626f617264320a757365720a746573745f757365725f315f0a63616c656e646172'
    >>> newhash in browser.contents
    True
