Commit 335f9198 authored by git's avatar git Committed by borisson_

Issue #2862698 by alan-ps, shkiper, borisson_: Summary count produces error on initial state

parent bd717bda
......@@ -24,6 +24,11 @@ class ShowCountProcessor extends ProcessorPluginBase implements BuildProcessorIn
* {@inheritdoc}
*/
public function build(FacetsSummaryInterface $facets_summary, array $build, array $facets) {
// Do nothing if there are no selected facets.
if (!isset($build['#items'])) {
return $build;
}
$count = $facets_summary->getFacetSource()->getCount();
$build_count = [
'#theme' => 'facets_summary_count',
......
......@@ -88,6 +88,7 @@ class IntegrationTest extends FacetsTestBase {
$this->drupalPostForm(NULL, ['facets[llama][checked]' => TRUE], 'Save');
$this->assertFieldChecked('edit-facets-llama-checked');
$this->configureShowCountProcessor();
$this->configureResetFacetsProcessor();
}
......@@ -174,6 +175,7 @@ class IntegrationTest extends FacetsTestBase {
->findAll('css', 'li');
$this->assertCount(2, $list_items);
$this->checkShowCountProcessor();
$this->checkResetFacetsProcessor();
}
......@@ -209,6 +211,16 @@ class IntegrationTest extends FacetsTestBase {
$this->assertEquals('none', $current_cache['type']);
}
/**
* Tests configuring show_count processor.
*/
protected function configureShowCountProcessor() {
$this->assertSession()->checkboxNotChecked('edit-facets-summary-settings-show-count-status');
$this->drupalPostForm(NULL, ['facets_summary_settings[show_count][status]' => TRUE], 'Save');
$this->assertSession()->checkboxChecked('edit-facets-summary-settings-show-count-status');
$this->assertSession()->pageTextContains(t('Facets Summary Owl has been updated.'));
}
/**
* Tests configuring reset facets processor.
*/
......@@ -224,6 +236,55 @@ class IntegrationTest extends FacetsTestBase {
$this->assertSession()->fieldValueEquals('facets_summary_settings[reset_facets][settings][link_text]', 'Reset facets');
}
/**
* Tests show_count processor.
*/
protected function checkShowCountProcessor() {
// Create new facets summary.
FacetsSummary::create([
'id' => 'show_count',
'name' => 'Show count summary',
'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1',
'facets' => [
'giraffe' => [
'checked' => 1,
'label' => 'Giraffe',
'separator' => ',',
'weight' => 0,
'show_count' => 0,
],
'llama' => [
'checked' => 1,
'label' => 'Llama',
'separator' => ',',
'weight' => 0,
'show_count' => 0,
],
],
'processor_configs' => [
'show_count' => [
'processor_id' => 'show_count',
'weights' => ['build' => -10],
],
],
])->save();
// Clear the cache after the new facet summary entity was created.
$this->resetAll();
// Place a block and test show_count processor.
$this->drupalPlaceBlock('facets_summary_block:show_count', ['region' => 'footer', 'id' => 'show-count']);
$this->drupalGet('search-api-test-fulltext');
$this->assertSession()->pageTextNotContains('5 results found');
$this->clickLink('apple');
$this->assertSession()->pageTextContains('2 results found');
$this->clickLink('item');
$this->assertSession()->pageTextContains('1 result found');
}
/**
* Tests reset facets processor.
*/
......
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