Commit 7fbabdf8 authored by borisson_'s avatar borisson_ Committed by borisson_
Browse files

Issue #2841357 by borisson_, jummonk: Facet summary manager builds deselected...

Issue #2841357 by borisson_, jummonk: Facet summary manager builds deselected facets for the facet summary
parent 432a4625
......@@ -91,6 +91,14 @@ class DefaultFacetsSummaryManager {
// @see \Drupal\facets\Processor\SortProcessorInterface.
$this->facetManager->updateResults($facetsource_id);
$facets_config = $facets_summary->getFacets();
// Exclude facets which were not selected for this summary.
$facets = array_filter($facets,
function($item) use ($facets_config) {
return (isset($facets_config[$item->id()]));
}
);
foreach ($facets as $facet) {
// For clarity, process facets is called each build.
// The first facet therefor will trigger the processing. Note that
......@@ -108,7 +116,6 @@ class DefaultFacetsSummaryManager {
);
$results = [];
$facets_config = $facets_summary->getFacets();
// Go through each facet and get the results. After, check if we have to
// show the counts for each facet and respectively set those to NULL if this
......
......@@ -45,25 +45,6 @@ class IntegrationTest extends FacetsTestBase {
$this->blocks = NULL;
}
/**
* {@inheritdoc}
*/
protected function installModulesFromClassProperty(ContainerInterface $container) {
// This will just set the Drupal state to include the necessary bundles for
// our test entity type. Otherwise, fields from those bundles won't be found
// and thus removed from the test index. (We can't do it in setUp(), before
// calling the parent method, since the container isn't set up at that
// point.)
$bundles = array(
'entity_test_mulrev_changed' => array('label' => 'Entity Test Bundle'),
'item' => array('label' => 'item'),
'article' => array('label' => 'article'),
);
\Drupal::state()->set('entity_test_mulrev_changed.bundles', $bundles);
parent::installModulesFromClassProperty($container);
}
/**
* Tests the overall functionality of the Facets summary admin UI.
*/
......@@ -106,4 +87,87 @@ class IntegrationTest extends FacetsTestBase {
$this->assertFieldChecked('edit-facets-llama-checked');
}
/**
* Tests with multiple facets.
*
* Includes a regression test for #2841357
*/
public function testMultipleFacets() {
// Create facets.
$this->createFacet('Giraffe', 'giraffe', 'keywords');
// Clear all the caches between building the 2 facets - because things fail
// otherwise.
$this->resetAll();
$this->createFacet('Llama', 'llama');
// Add a summary.
$values = [
'name' => 'Owlß',
'id' => 'owl',
'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1',
];
$this->drupalPostForm('admin/config/search/facets/add-facet-summary', $values, 'Save');
$this->drupalPostForm(NULL, [], 'Save');
// Edit the summary and enable the giraffe's.
$summaries = [
'facets[giraffe][checked]' => TRUE,
'facets[giraffe][label]' => 'Summary giraffe',
];
$this->drupalPostForm('admin/config/search/facets/facet-summary/owl/edit', $summaries, 'Save');
$block = [
'region' => 'footer',
'id' => str_replace('_', '-', 'owl'),
'weight' => 50,
];
$block = $this->drupalPlaceBlock('facets_summary_block:owl', $block);
$this->drupalGet('search-api-test-fulltext');
$this->assertText('Displaying 5 search results');
$this->assertText($block->label());
$this->assertFacetBlocksAppear();
$this->clickLink('apple');
$list_items = $this->getSession()
->getPage()
->findById('block-' . $block->id())
->findAll('css', 'li');
$this->assertCount(1, $list_items);
$this->clickLink('item');
$list_items = $this->getSession()
->getPage()
->findById('block-' . $block->id())
->findAll('css', 'li');
$this->assertCount(1, $list_items);
// Edit the summary and enable the giraffe's.
$summaries = [
'facets[giraffe][checked]' => TRUE,
'facets[giraffe][label]' => 'Summary giraffe',
'facets[llama][checked]' => TRUE,
'facets[llama][label]' => 'Summary llama',
];
$this->drupalPostForm('admin/config/search/facets/facet-summary/owl/edit', $summaries, 'Save');
$this->drupalGet('search-api-test-fulltext');
$this->assertText('Displaying 5 search results');
$this->assertText($block->label());
$this->assertFacetBlocksAppear();
$this->clickLink('apple');
$list_items = $this->getSession()
->getPage()
->findById('block-' . $block->id())
->findAll('css', 'li');
$this->assertCount(1, $list_items);
$this->clickLink('item');
$list_items = $this->getSession()
->getPage()
->findById('block-' . $block->id())
->findAll('css', 'li');
$this->assertCount(2, $list_items);
}
}
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