You are here

public function IntegrationTest::testFacetCountCalculations in Facets 8

Tests calculations of facet count.

File

tests/src/Functional/IntegrationTest.php, line 546

Class

IntegrationTest
Tests the overall functionality of the Facets admin UI.

Namespace

Drupal\Tests\facets\Functional

Code

public function testFacetCountCalculations() {
  $this
    ->addFacet('Type');
  $this
    ->addFacet('Keywords', 'keywords');
  $this
    ->createBlock('type');
  $this
    ->createBlock('keywords');
  $edit = [
    'widget' => 'links',
    'widget_config[show_numbers]' => '1',
    'facet_settings[query_operator]' => 'and',
  ];
  $this
    ->drupalPostForm('admin/config/search/facets/keywords/edit', $edit, 'Save');
  $this
    ->drupalPostForm('admin/config/search/facets/type/edit', $edit, 'Save');
  $this
    ->drupalGet('search-api-test-fulltext');
  $this
    ->assertSession()
    ->pageTextContains('Displaying 5 search results');
  $this
    ->assertFacetLabel('article (2)');
  $this
    ->assertFacetLabel('grape (3)');

  // Make sure that after clicking on article, which has only 2 entities,
  // there are only 2 items left in the results for other facets as well.
  // In this case, that means we can't have 3 entities tagged with grape. Both
  // remaining entities are tagged with grape and strawberry.
  $this
    ->clickPartialLink('article');
  $this
    ->assertSession()
    ->pageTextNotContains('(3)');
  $this
    ->assertFacetLabel('grape (2)');
  $this
    ->assertFacetLabel('strawberry (2)');
  $this
    ->drupalGet('search-api-test-fulltext');
  $this
    ->assertSession()
    ->pageTextContains('Displaying 5 search results');
  $this
    ->assertFacetLabel('article (2)');
  $this
    ->assertFacetLabel('grape (3)');

  // Make sure that after clicking on grape, which has only 3 entities, there
  // are only 3 items left in the results for other facets as well. In this
  // case, that means 2 entities of type article and 1 item.
  $this
    ->clickPartialLink('grape');
  $this
    ->assertSession()
    ->pageTextContains('Displaying 3 search results');
  $this
    ->assertFacetLabel('article (2)');
  $this
    ->assertFacetLabel('item (1)');
}