public function FacetapiApiFunctions::testUrlProcessorDataProcessing in Facet API 7
Same name and namespace in other branches
- 7.2 tests/facetapi.test \FacetapiApiFunctions::testUrlProcessorDataProcessing()
Test active item processing via the url processor plugin.
See also
FacetapiUrlProcessorStandard::fetchParams()
FacetapiUrlProcessorStandard::normalizeParams()
FacetapiUrlProcessorStandard::setParams()
FacetapiUrlProcessorStandard::getParams()
FacetapiAdapter::initUrlProcessor()
FacetapiAdapter::processActiveItems()
FacetapiAdapter::getAllActiveItems()
File
- tests/
facetapi.test, line 640 - Tests for the Facet API module.
Class
- FacetapiApiFunctions
- Test cases for low level API functions.
Code
public function testUrlProcessorDataProcessing() {
list($facet, $realm, $adapter) = $this
->facetapiLoadObjects();
facetapi_save_facet_enabled($adapter, $realm, $facet);
// Capture real $_GET.
$get = $_GET;
// Fake the query string.
$_GET = array(
'q' => array(),
'page' => 1,
'f' => array(
'enabled:testone',
'disabled:testfour',
'enabled:testthree',
),
);
// Ensure that the adapter loads the URL processor plugin.
$url_processor = $adapter
->getUrlProcessor();
$passed = $url_processor instanceof FacetapiUrlProcessorStandard;
$this
->assertTrue($passed, t('An instance of FacetapiUrlProcessorStandard is returned by the adapter.'), 'Facet API');
// Test fetching params.
$fetched = $url_processor
->fetchParams();
$this
->assertEqual($fetched, $_GET, t('Parameters fetched from $_GET by FacetapiUrlProcessorStandard::fetchParams().'), 'Facet API');
// Test normalizing fetched params.
$normalized = $url_processor
->normalizeParams($fetched);
$this
->assertTrue(!isset($normalized['q']), t('The "q" variable is stripped by FacetapiUrlProcessorStandard::normalizeParams().'), 'Facet API');
$this
->assertTrue(!isset($normalized['page']), t('The "page" variable is stripped by FacetapiUrlProcessorStandard::normalizeParams().'), 'Facet API');
// Test setting and getting params.
$url_processor
->setParams($normalized);
$params = $url_processor
->getParams();
$this
->assertEqual($normalized, $params, t('Parameters are able to be set and retrieved by getter and setter methods of FacetapiUrlProcessorStandard.'), 'Facet API');
// Test processing of active items.
$adapter
->initUrlProcessor();
$active_items = $adapter
->getAllActiveItems();
$true = isset($active_items['enabled:testone']);
$this
->assertTrue($true, t('Value for enabled facet extracted as an active item.'), 'Facet API');
$false = isset($active_items['disabled:testfour']);
$this
->assertFalse($false, t('Value for disabled facet not extracted as an active item.'), 'Facet API');
// Test re-processing of active items.
$facet_d = facetapi_facet_load('disabled', 'facetapi_test');
facetapi_save_facet_enabled($adapter, $realm, $facet_d);
$adapter
->initUrlProcessor();
$active_items = $adapter
->getAllActiveItems();
$true = isset($active_items['disabled:testfour']);
$this
->assertTrue($true, t('Reprocessed value for enabled facet extracted as an active item.'), 'Facet API');
// Reset real $_GET.
$_GET = $get;
}