You are here

public function ProcessorIntegrationTest::testHideOnlyOneItemProcessor in Facets 8

Test HideOnlyOneItemProcessor.

Test if after clicking an item that has only one item, the facet block no longer shows.

File

tests/src/Functional/ProcessorIntegrationTest.php, line 791

Class

ProcessorIntegrationTest
Tests the processor functionality.

Namespace

Drupal\Tests\facets\Functional

Code

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',
    'type' => 'article',
    'keywords' => [
      'kiwi',
    ],
    'category' => 'article_category',
  ])
    ->save();
  $this
    ->indexItems($this->indexId);
  $facet_name = 'Drupalcon Vienna';
  $facet_id = 'drupalcon_vienna';
  $this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
  $this
    ->createFacet($facet_name, $facet_id, 'keywords');
  $form = [
    'facet_settings[hide_1_result_facet][status]' => TRUE,
    'facet_settings[query_operator]' => 'and',
  ];
  $this
    ->drupalPostForm($this->editForm, $form, 'Save');
  $this
    ->drupalGet('search-api-test-fulltext');
  $this
    ->assertSession()
    ->pageTextContains('Displaying 1 search results');
  $this
    ->assertNoFacetBlocksAppear();
}