Facet dependencies
------------------

This tests dependencies of search facets.  A facet depending on another will
only be displayed in case a value was already selected for the latter.  We'll
use a testbrowser to check this.

First we need to activate Solr support, reindex the site's content and set
up a facet dependency:

  >>> from collective.solr.testing import activateAndReindex
  >>> from plone.app.testing import setRoles
  >>> from plone.app.testing import TEST_USER_ID
  >>> from plone.app.testing import TEST_USER_NAME
  >>> from plone.app.testing import TEST_USER_PASSWORD
  >>> from plone.testing.z2 import Browser
  >>> from transaction import commit
  >>> portal = layer['portal']
  >>> setRoles(portal, TEST_USER_ID, ['Manager'])

  >>> activateAndReindex(portal)
  >>> from zope.component import getUtility
  >>> from collective.solr.interfaces import ISolrConnectionConfig
  >>> config = getUtility(ISolrConnectionConfig)
  >>> config.facets = ['portal_type', 'review_state:portal_type']
  >>> commit()

Initially the depending facet show not show up:

  >>> browser = Browser(layer['app'])
  >>> browser.open('http://nohost/plone/')
  >>> browser.getControl('Search Site').value = 'news'
  >>> browser.getForm(name='searchform').submit()
  >>> browser.url
  'http://nohost/plone/search?...&facet.field=portal_type...'
  >>> 'Review state' in browser.contents
  False

After selecting the required facet it should, though:

  >>> browser.getLink('Collection').click()
  >>> browser.contents
  '...Search results...1 items matching...
   ...portal-searchfacets...
   ...Content type...Collection...&otimes;...
   ...Review state...
   ...published...1...
   ...Site...'

After removing the selection again we should be back to the beginning:

  >>> browser.getLink('⊗').click()
  >>> 'Review state' in browser.contents
  False
