public function HierarchicalFacetIntegrationTest::testHierarchicalFacet in Facets 8
Same name in this branch
- 8 tests/src/Functional/HierarchicalFacetIntegrationTest.php \Drupal\Tests\facets\Functional\HierarchicalFacetIntegrationTest::testHierarchicalFacet()
- 8 modules/facets_summary/tests/src/Functional/HierarchicalFacetIntegrationTest.php \Drupal\Tests\facets_summary\Functional\HierarchicalFacetIntegrationTest::testHierarchicalFacet()
Test the hierarchical facets functionality.
File
- modules/
facets_summary/ tests/ src/ Functional/ HierarchicalFacetIntegrationTest.php, line 116
Class
- HierarchicalFacetIntegrationTest
- Tests the hierarchical facets implementation.
Namespace
Drupal\Tests\facets_summary\FunctionalCode
public function testHierarchicalFacet() {
// Verify that the link to the index processors settings page is available.
$this
->drupalGet($this->facetEditPage);
$this
->clickLink('Search api index processor configuration');
$this
->assertSession()
->statusCodeEquals(200);
// Enable hierarchical facets and translation of entity ids to its names for
// a better readability.
$this
->drupalGet($this->facetEditPage);
$edit = [
'facet_settings[use_hierarchy]' => '1',
'facet_settings[translate_entity][status]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$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');
$block = [
'region' => 'footer',
'id' => str_replace('_', '-', 'owl'),
'weight' => 50,
];
$block = $this
->drupalPlaceBlock('facets_summary_block:owl', $block);
// Child elements should be collapsed and invisible.
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetBlocksAppear();
$this
->assertFacetLabel('Parent 1');
$this
->assertFacetLabel('Parent 2');
$this
->assertSession()
->linkNotExists('Child 1');
$this
->assertSession()
->linkNotExists('Child 2');
$this
->assertSession()
->linkNotExists('Child 3');
$this
->assertSession()
->linkNotExists('Child 4');
$this
->assertSession()
->pageTextContains($block
->label());
// Click the first parent and make sure its children are visible.
$this
->clickLink('Parent 1');
$this
->assertFacetBlocksAppear();
$this
->checkFacetIsActive('Parent 1');
$this
->assertFacetLabel('Child 1');
$this
->assertFacetLabel('Child 2');
$this
->assertSession()
->linkNotExists('Child 3');
$this
->assertSession()
->linkNotExists('Child 4');
$this
->assertSession()
->pageTextContains($block
->label());
}