Commit 5ebc2472 authored by Nick_vh's avatar Nick_vh

Adding first processor test

parent eeee3817
......@@ -5,10 +5,10 @@
* Contains Drupal\facetapi\Plugin\AdapterBase.
*/
namespace Drupal\facetapi\Plugin;
namespace Drupal\facetapi\Plugin\Adapter;
use Drupal\Core\Plugin\PluginBase;
use Drupal\facetapi\AdapterInterface;
use Drupal\facetapi\Plugin\Adapter\AdapterInterface;
/**
* Base class for Facet API adapters.
......@@ -65,6 +65,28 @@ abstract class AdapterBase extends PluginBase implements AdapterInterface {
*/
protected $queryTypes = array();
/**
* Returns a boolean flagging whether facets in a realm shoud be displayed.
*
* Useful, for example, for suppressing sidebar blocks in some cases. Apache
* Solr Search Integration used this method to prevent blocks from being
* displayed when the module was configured to render them in the search body
* on "empty" searches instead of the normal facet location.
*
* @param string $realm_name
* The machine readable name of the realm.
*
* @return boolean
* A boolean flagging whether to display a given realm.
*
* @todo It appears that no implementing modules are leveraging this anymore.
* Let's discuss whether to deprecate this method or even remove it from
* future versions of Facet API at http://drupal.org/node/1661410.
*/
public function suppressOutput($realm_name) {
return false;
}
/**
* @TODO: generalize to ProcessorInterface and properly type hint in __construct().
* The url processor plugin associated with this adapter.
......
......@@ -5,7 +5,7 @@
* Contains Drupal\facetapi\Plugin\AdapterInterface.
*/
namespace Drupal\facetapi;
namespace Drupal\facetapi\Plugin\Adapter;
interface AdapterInterface {
......@@ -23,7 +23,7 @@ interface AdapterInterface {
* @param array $searcher_info
* The searcher information as returned by facetapi_get_searcher_info().
*/
public function __construct(SearcherInterface $searcher);
//public function __construct(SearcherInterface $searcher);
/**
* Returns a boolean flagging whether $this->searcher['searcher'] executed a
......
......@@ -8,6 +8,8 @@
namespace Drupal\facetapi\Plugin\Url;
use Drupal\facetapi\Plugin\Adapter\AdapterInterface;
/**
* In D7 this was the abstract class extended by all url processor plugins.
* This called FacetApiUrlProcessor but the name would then no longer be consistent
......@@ -31,7 +33,7 @@ abstract class FacetUrlProcessor {
/**
* Held the adapter that the url processor plugin was associated with.
*
* @var FacetapiAdapter
* @var AdapterInterface
*/
protected $adapter;
......@@ -54,10 +56,10 @@ abstract class FacetUrlProcessor {
/**
* Constructed the FacetapiUrlProcessor object.
*
* @param FacetapiAdapter $adapter
* @param AdapterInterface $adapter
* The adapter that the url processor plugin would get associated with.
*/
public function __construct(FacetapiAdapter $adapter) {
public function __construct(AdapterInterface $adapter) {
$this->adapter = $adapter;
}
......@@ -161,7 +163,7 @@ abstract class FacetUrlProcessor {
* Hardcoded to 'f' in D7 but actually it is already defined in the filterKey property
* so it might make sense to no longer hardcode this in here if this function remains?
*
* @return FacetapiUrlParser
* @return FacetUrlProcessor
* An instance of this class.
*/
public function setParams(array $params, $filter_key = 'f') {
......
......@@ -7,6 +7,8 @@
namespace Drupal\facetapi\Plugin\Url;
use \Drupal\Component\Utility\UrlHelper;
/**
* In D7 this was the standard url processor
* This called FacetApiUrlProcessorStandard but the name would then no longer be consistent
......@@ -53,7 +55,7 @@ class FacetUrlProcessorStandard extends FacetUrlProcessor {
* An associative array containing the normalized params.
*/
public function normalizeParams(array $params, $filter_key = 'f') {
return drupal_get_query_parameters($params, array('q', 'page'));
return UrlHelper::filterQueryParameters($params, array('q', 'page'));
}
/**
......
<?php
/**
* @file
* Contains \Drupal\Tests\facetapi\Plugin\Plugin\Url\FacetUrlProcessorStandardTest.
*/
namespace Drupal\Tests\facetapi\Plugin\Url;
use Drupal\facetapi\Plugin\Url\FacetUrlProcessorStandard;
use Drupal\Tests\UnitTestCase;
/**
* Tests the "URL field" processor.
*
* @group facetapi
*
* @see \Drupal\facetapi\Plugin\Url\FacetUrlProcessorStandard
*/
class FacetUrlProcessorStandardTest extends UnitTestCase {
/**
* Stores the processor to be tested.
*
* @var \Drupal\facetapi\Plugin\Url\FacetUrlProcessorStandard
*/
protected $processor;
/**
* Stores the processor to be tested.
*
* @var \Drupal\facetapi\Plugin\Adapter\AdapterInterface
*/
protected $adapter;
/**
* Creates a new processor object for use in the tests.
*/
protected function setUp() {
parent::setUp();
// Create a mock for the URL to be returned.
$this->adapter = $this->getMock('Drupal\facetapi\Plugin\Adapter\AdapterInterface');
// Create the URL-Processor and set the mocked indexer.
$this->processor = new FacetUrlProcessorStandard($this->adapter);
}
/**
* Tests processIndexItems.
*
* Check if the items are processed as expected.
*/
public function testNormalizeParams() {
// Process the items.
$params = array('foo' => 'bar', 'bar' => 'baz', 'q' => 'testing', 'page' => 'blabla');
$normalized_param = $this->processor->normalizeParams($params);
$this->assertArrayNotHasKey('q', $normalized_param, 'q parameter was removed');
$this->assertArrayNotHasKey('page', $normalized_param, 'page parameter was removed');
$this->assertArrayHasKey('foo', $normalized_param, 'foo parameter is still there');
$this->assertArrayHasKey('bar', $normalized_param, 'bar parameter is still there');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment