public function FacetsTest::testFacets in Search API Solr 8
Same name and namespace in other branches
- 8.3 tests/src/Functional/FacetsTest.php \Drupal\Tests\search_api_solr\Functional\FacetsTest::testFacets()
- 8.2 tests/src/Functional/FacetsTest.php \Drupal\Tests\search_api_solr\Functional\FacetsTest::testFacets()
- 4.x tests/src/Functional/FacetsTest.php \Drupal\Tests\search_api_solr\Functional\FacetsTest::testFacets()
Tests basic facets integration.
File
- tests/
src/ Functional/ FacetsTest.php, line 52
Class
- FacetsTest
- Tests the facets functionality using the Solr backend.
Namespace
Drupal\Tests\search_api_solr\FunctionalCode
public function testFacets() {
$this->indexId = 'solr_search_index';
$view = View::load('search_api_test_view');
$this
->assertEquals('search_api_index_solr_search_index', $view
->get('base_table'));
// Create the users used for the tests.
$admin_user = $this
->drupalCreateUser([
'administer search_api',
'administer facets',
'access administration pages',
'administer blocks',
]);
$this
->drupalLogin($admin_user);
// Check that the test index is on the admin overview.
$this
->drupalGet('admin/config/search/search-api');
$this
->assertSession()
->pageTextContains('Test index');
$this
->setUpExampleStructure();
$this
->insertExampleContent();
$indexed_items = $this
->indexItems($this->indexId);
$this
->assertEquals(5, $indexed_items, 'Five items are indexed.');
// Create a facet, enable 'show numbers'.
$this
->createFacet('Owl', 'owl');
$edit = [
'widget' => 'links',
'widget_config[show_numbers]' => '1',
];
$this
->drupalPostForm('admin/config/search/facets/owl/edit', $edit, 'Save');
// Verify that the facet results are correct.
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertFacetLabel('item (3)');
$this
->assertFacetLabel('article (2)');
$this
->assertSession()
->pageTextContains('Displaying 5 search results');
$this
->clickLinkPartialName('item');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Displaying 3 search results');
}