Handle criteria
===============

Imports
-------

    >>> from zope.component import getMultiAdapter
    >>> from plone.app.testing import setRoles
    >>> from plone.app.testing import TEST_USER_ID
    >>> from eea.facetednavigation.interfaces import ICriteria

Set up
------

Setup sandbox

    >>> portal = layer["portal"]
    >>> request = layer['request']
    >>> sandbox = portal['sandbox']
    >>> subtyper = getMultiAdapter((sandbox, request), name=u'faceted_subtyper')
    >>> subtyper.can_enable
    True

    >>> subtyper.enable()

Cleanup default widgets
-----------------------

    >>> cids = ICriteria(sandbox).keys()
    >>> for cid in cids:
    ...     ICriteria(sandbox).delete(cid)
    >>> ICriteria(sandbox).keys()
    []

Add criteria
------------

    >>> _ = ICriteria(sandbox).add('alphabetic', 'top')
    >>> _ = ICriteria(sandbox).add('checkbox', 'top')
    >>> _ = ICriteria(sandbox).add('criteria', 'left')
    >>> _ = ICriteria(sandbox).add('daterange', 'left')
    >>> _ = ICriteria(sandbox).add('radio', 'center')
    >>> _ = ICriteria(sandbox).add('select', 'center')
    >>> _ = ICriteria(sandbox).add('sorting', 'right')
    >>> _ = ICriteria(sandbox).add('text', 'right')

Get criteria
------------

    >>> ICriteria(sandbox).keys()
    [u'c0', u'c1', u'c2', u'c3', u'c4', u'c5', u'c6', u'c7']

    >>> ICriteria(sandbox).values()
    [<eea.facetednavigation.widgets.storage.Criterion object at...>, ...]

    >>> ICriteria(sandbox).items()
    [(u'c0', <eea.facetednavigation.widgets.storage.Criterion object at...>), ...]

    >>> ICriteria(sandbox).get('c0')
    <eea.facetednavigation.widgets.storage.Criterion object at...>

Edit criterion
--------------

  Alphabetic criterion

    >>> ICriteria(sandbox).edit('c0', title='Alphabetic', index='Title', hidden=False)
    >>> criterion = ICriteria(sandbox).get('c0')
    >>> criterion.get('title')
    u'Alphabetic'
    >>> criterion.hidden
    False
    >>> criterion.get('index')
    u'Title'

  Checkbox criterion

    >>> ICriteria(sandbox).edit('c1',
    ...    title='Check boxes',
    ...    index='portal_type',
    ...    vocabulary='eea.faceted.vocabularies.FacetedPortalTypes',
    ...    catalog='portal_catalog',
    ...    maxitems=4, hidden=True
    ... )
    >>> criterion = ICriteria(sandbox).get('c1')
    >>> criterion.get('title')
    u'Check boxes'
    >>> criterion.hidden
    True
    >>> criterion.get('maxitems')
    4

Delete criteria
---------------

    >>> ICriteria(sandbox).delete('c0')
    >>> ICriteria(sandbox).delete('c1')
    >>> ICriteria(sandbox).delete('c2')
    >>> ICriteria(sandbox).keys()
    [u'c3', u'c4', u'c5', u'c6', u'c7']

Move up/down
------------

    >>> ICriteria(sandbox).down('c4')
    >>> ICriteria(sandbox).up('c5')
    >>> ICriteria(sandbox).keys()
    [u'c5', u'c3', u'c4', u'c6', u'c7']

Change position
---------------

    >>> ICriteria(sandbox).position(
    ...     top=['c7', 'c6'],
    ...     left=['c5', 'c4'],
    ...     center=['c3'],
    ...     right=[]
    ... )
    >>> ICriteria(sandbox).keys()
    [u'c7', u'c6', u'c5', u'c4', u'c3']
    >>> ICriteria(sandbox).get('c4').get('position')
    u'left'

Add criteria to specific sections
---------------------------------

    >>> _ = ICriteria(sandbox).add('alphabetic', 'top', section='advanced')
    >>> _ = ICriteria(sandbox).add('alphabetic', 'top')
    >>> ICriteria(sandbox).get('c2').get('section')
    u'advanced'
    >>> ICriteria(sandbox).get('c1').get('section')
    u'default'
    >>> ICriteria(sandbox).keys()
    [u'c7', u'c6', u'c1', u'c2', u'c5', u'c4', u'c3']
