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
* {@inheritdoc}
*/
public function build(FacetInterface $facet, array $results) {
if (count($results) === 1) {
if (count($results) === 1 && !$results[0]->isActive()) {
return [];
}
......
......@@ -768,6 +768,12 @@ class ProcessorIntegrationTest extends FacetsTestBase {
public function testHideOnlyOneItemProcessor() {
$entity_test_storage = \Drupal::entityTypeManager()
->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([
'name' => 'baz baz',
'body' => 'foo test',
......@@ -775,7 +781,6 @@ class ProcessorIntegrationTest extends FacetsTestBase {
'keywords' => ['kiwi'],
'category' => 'article_category',
])->save();
$this->indexItems($this->indexId);
$facet_name = 'Drupalcon Vienna';
......@@ -790,8 +795,7 @@ class ProcessorIntegrationTest extends FacetsTestBase {
$this->drupalPostForm($this->editForm, $form, 'Save');
$this->drupalGet('search-api-test-fulltext');
$this->assertFacetBlocksAppear();
$this->clickLink('kiwi');
$this->assertSession()->pageTextContains(' Displaying 1 search results');
$this->assertNoFacetBlocksAppear();
}
......
......@@ -33,6 +33,25 @@ class HideOnlyOneItemProcessorTest extends UnitTestCase {
$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.
*
......
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