function CToolsViewsEntityViewBlockTest::testConfigureFiltersTaxonomy
Test ctools_views 'configure_filters' with taxonomy term field values.
File
-
modules/
ctools_views/ tests/ src/ Functional/ CToolsViewsEntityViewBlockTest.php, line 349
Class
- CToolsViewsEntityViewBlockTest
- Tests the ctools_views block display plugin overriding entity View filters.
Namespace
Drupal\Tests\ctools_views\FunctionalCode
public function testConfigureFiltersTaxonomy() {
$default_theme = $this->config('system.theme')
->get('default');
$tid = $this->terms[0]
->id();
$term_label = $this->terms[0]
->label();
$filter_id = 'field_ctools_views_tags_target_id';
// Get the "Configure block" form for our Views block.
$this->drupalGet('admin/structure/block/add/views_block:ctools_views_entity_test-block_filter_tax/' . $default_theme);
$this->assertSession()
->fieldExists('settings[exposed][filter-' . $filter_id . '][' . $filter_id . ']');
// Add block to sidebar_first region with default settings.
$edit = [];
$edit['region'] = 'sidebar_first';
$edit['id'] = 'views_block__ctools_views_entity_test_block_filter_tax';
$this->drupalGet('admin/structure/block/add/views_block:ctools_views_entity_test-block_filter_tax/' . $default_theme);
$this->submitForm($edit, 'Save block');
// Assert configure_filters default settings.
$this->drupalGet('<front>');
// Check that the default settings return all results.
$this->assertEquals(3, count($this->xpath('//div[contains(@class, "view-display-id-block_filter_tax")]//table/tbody/tr')));
// Override configure_filters settings.
$edit = [];
$edit['region'] = 'sidebar_first';
$edit['settings[exposed][filter-' . $filter_id . '][' . $filter_id . ']'] = $tid;
$this->drupalGet('admin/structure/block/manage/views_block__ctools_views_entity_test_block_filter_tax');
$this->submitForm($edit, 'Save block');
// Test settings saved correctly.
$block = $this->storage
->load('views_block__ctools_views_entity_test_block_filter_tax');
$config = $block->getPlugin()
->getConfiguration();
$this->assertEquals([
$tid => $tid,
], $config['exposed']['filter-field_ctools_views_tags_target_id']['value'], "'configure_filters' setting is properly saved.");
// Test saved settings reload into configuration form correctly.
$this->drupalGet('admin/structure/block/manage/views_block__ctools_views_entity_test_block_filter_tax');
$this->assertSession()
->elementTextEquals('xpath', '//select[@data-drupal-selector="edit-settings-exposed-filter-field-ctools-views-tags-target-id-field-ctools-views-tags-target-id"]/option[@selected="selected"]', $term_label);
// Assert configure_filters overridden settings.
$this->drupalGet('<front>');
// Check that the overridden settings return proper results.
$this->assertEquals(1, count($this->xpath('//div[contains(@class, "view-display-id-block_filter_tax")]//table/tbody/tr')));
}