Commit 27d088d7 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2949260 by borisson_: Show active facets even when "Hide facet with 1 result" is selected

parent 3b27b114
...@@ -24,7 +24,7 @@ class HideOnlyOneItemProcessor extends ProcessorPluginBase implements BuildProce ...@@ -24,7 +24,7 @@ class HideOnlyOneItemProcessor extends ProcessorPluginBase implements BuildProce
* {@inheritdoc} * {@inheritdoc}
*/ */
public function build(FacetInterface $facet, array $results) { public function build(FacetInterface $facet, array $results) {
if (count($results) === 1) { if (count($results) === 1 && !$results[0]->isActive()) {
return []; return [];
} }
......
...@@ -768,6 +768,12 @@ class ProcessorIntegrationTest extends FacetsTestBase { ...@@ -768,6 +768,12 @@ class ProcessorIntegrationTest extends FacetsTestBase {
public function testHideOnlyOneItemProcessor() { public function testHideOnlyOneItemProcessor() {
$entity_test_storage = \Drupal::entityTypeManager() $entity_test_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_mulrev_changed'); ->getStorage('entity_test_mulrev_changed');
// Load all items and delete them.
$all = $entity_test_storage->loadMultiple();
foreach ($all as $item) {
$item->delete();
}
$entity_test_storage->create([ $entity_test_storage->create([
'name' => 'baz baz', 'name' => 'baz baz',
'body' => 'foo test', 'body' => 'foo test',
...@@ -775,7 +781,6 @@ class ProcessorIntegrationTest extends FacetsTestBase { ...@@ -775,7 +781,6 @@ class ProcessorIntegrationTest extends FacetsTestBase {
'keywords' => ['kiwi'], 'keywords' => ['kiwi'],
'category' => 'article_category', 'category' => 'article_category',
])->save(); ])->save();
$this->indexItems($this->indexId); $this->indexItems($this->indexId);
$facet_name = 'Drupalcon Vienna'; $facet_name = 'Drupalcon Vienna';
...@@ -790,8 +795,7 @@ class ProcessorIntegrationTest extends FacetsTestBase { ...@@ -790,8 +795,7 @@ class ProcessorIntegrationTest extends FacetsTestBase {
$this->drupalPostForm($this->editForm, $form, 'Save'); $this->drupalPostForm($this->editForm, $form, 'Save');
$this->drupalGet('search-api-test-fulltext'); $this->drupalGet('search-api-test-fulltext');
$this->assertFacetBlocksAppear(); $this->assertSession()->pageTextContains(' Displaying 1 search results');
$this->clickLink('kiwi');
$this->assertNoFacetBlocksAppear(); $this->assertNoFacetBlocksAppear();
} }
......
...@@ -33,6 +33,25 @@ class HideOnlyOneItemProcessorTest extends UnitTestCase { ...@@ -33,6 +33,25 @@ class HideOnlyOneItemProcessorTest extends UnitTestCase {
$this->assertCount(0, $processed_results); $this->assertCount(0, $processed_results);
} }
/**
* Tests with one result that is already active.
*
* @covers ::build
*/
public function testWithOneActiveResult() {
$processor = new HideOnlyOneItemProcessor([], 'hide_only_one_item', []);
$facet = new Facet([], 'facets_facet');
$results = [
new Result($facet, '1', 1, 1),
];
$results[0]->setActiveState(TRUE);
$facet = $this->getMockBuilder(Facet::class)
->disableOriginalConstructor()
->getMock();
$processed_results = $processor->build($facet, $results);
$this->assertCount(1, $processed_results);
}
/** /**
* Tests with one result. * Tests with one result.
* *
......
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