.. -*-doctest-*-

=======
Sorting
=======

Open a browser and log in as a normal user.

    >>> from Products.Five.testbrowser import Browser
    >>> from Products.PloneTestCase import ptc
    >>> browser = Browser()
    >>> browser.handleErrors = False
    >>> browser.open(portal.absolute_url())
    >>> browser.getLink('Log in').click()
    >>> browser.getControl('Login Name').value = ptc.default_user
    >>> browser.getControl(
    ...     'Password').value = ptc.default_password
    >>> browser.getControl('Log in').click()

Load the edit form of a collection.

    >>> foo_topic = self.folder['foo-topic-title']
    >>> browser.open(foo_topic.absolute_url())
    >>> browser.getLink('Edit').click()

An widget is avialable for selecting which of the possible
sort fields should be available for sorting on.  The InAndOutWidget is
used so that the order can be specified.  The "Relevance" field
corresponds to a sort by weight for searches that include queries
against indexs that support weighted results.

    >>> print browser.contents
    <...
    <div class="field ArchetypesInAndOutWidget
    kssattr-atfieldname-sortFields"
    id="archetypes-fieldname-sortFields">...
    ...>Relevance</option>...
    ...>Date</option>...
    ...>Item Type</option>...

The InAndOutWidget uses JavaScript so we'll set the field manually for
testing.

    >>> self.login()
    >>> foo_topic.setSortFields(['', 'Date', 'Type'])

Change the display layout of the collection to the "Search Form" then
submit a search criteria to test that the sort links preserve search
criteria.

    >>> foo_topic.setLayout('criteria_form')
    >>> foo_topic.addCriterion(
    ...     'Type','ATPortalTypeCriterion').setFormFields(['value'])
    >>> browser.getLink('View').click()
    >>> 

When the batch macro is rendered on a collection view, such as one of
the listings, it includes links to the different possible sorts.

    >>> browser.getLink('Relevance')
    <Link XXX>
    >>> browser.getLink('Date')
    <Link XXX>
    >>> browser.getLink('Item Type')
    <Link XXX>
