You are here

public function IntegrationTest::testMultipleFacets in Facets 8

Same name in this branch
  1. 8 tests/src/Functional/IntegrationTest.php \Drupal\Tests\facets\Functional\IntegrationTest::testMultipleFacets()
  2. 8 modules/facets_summary/tests/src/Functional/IntegrationTest.php \Drupal\Tests\facets_summary\Functional\IntegrationTest::testMultipleFacets()

Tests with multiple facets.

Includes a regression test for #2841357

File

modules/facets_summary/tests/src/Functional/IntegrationTest.php, line 90

Class

IntegrationTest
Tests the overall functionality of the Facets summary admin UI.

Namespace

Drupal\Tests\facets_summary\Functional

Code

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
    ->assertSession()
    ->pageTextContains('Displaying 5 search results');
  $this
    ->assertSession()
    ->pageTextContains($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
    ->assertSession()
    ->pageTextContains('Displaying 5 search results');
  $this
    ->assertSession()
    ->pageTextContains($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);
  $this
    ->checkShowCountProcessor();
  $this
    ->checkResetFacetsProcessor();
}