function CToolsViewsEntityViewBlockTest::testConfigureFiltersTextfieldGrouped
Test ctools_views 'configure_filters' with grouped text field.
File
-
modules/
ctools_views/ tests/ src/ Functional/ CToolsViewsEntityViewBlockTest.php, line 274
Class
- CToolsViewsEntityViewBlockTest
- Tests the ctools_views block display plugin overriding entity View filters.
Namespace
Drupal\Tests\ctools_views\FunctionalCode
public function testConfigureFiltersTextfieldGrouped() {
$default_theme = $this->config('system.theme')
->get('default');
$filter_id = 'title';
$filter_op_id = $filter_id . '_op';
$block = [];
$block['id'] = 'views_block:ctools_views_entity_test-block_filter_text_grouped';
$block['region'] = 'sidebar_first';
$block['theme'] = $this->config('system.theme')
->get('default');
// Get the "Configure block" form for our Views block.
$this->drupalGet('admin/structure/block/add/' . $block['id'] . '/' . $block['theme']);
$this->assertSession()
->fieldExists('settings[exposed][filter-' . $filter_id . '][' . $filter_id . ']');
// Add block to sidebar_first region with default settings.
$this->submitForm([
'region' => $block['region'],
'id' => 'views_block__ctools_views_entity_test_block_filter_text_grouped',
], '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_text_grouped")]//table/tbody/tr')));
// Override configure_filters settings with test value contains group.
$edit = [];
$edit['region'] = 'sidebar_first';
$edit['settings[exposed][filter-' . $filter_id . '][' . $filter_id . ']'] = '1';
$this->drupalGet('admin/structure/block/manage/views_block__ctools_views_entity_test_block_filter_text_grouped');
$this->submitForm($edit, 'Save block');
$block = $this->storage
->load('views_block__ctools_views_entity_test_block_filter_text_grouped');
$config = $block->getPlugin()
->getConfiguration();
$this->assertEquals('1', $config['exposed']['filter-' . $filter_id]['group_info']['default_group'], "'configure_filters' value is properly saved.");
$this->assertEquals('string', $config['exposed']['filter-' . $filter_id]['plugin_id'], "'configure_filters' plugin_id is properly saved.");
// 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_text_grouped")]//table/tbody/tr')));
$this->assertSession()
->elementTextEquals('xpath', '(//div[contains(@class, "view-display-id-block_filter_text_grouped")]//table/tbody/tr)[1]', 'Test entity 2');
// Override configure_filters settings with test value not group.
$edit = [];
$edit['region'] = 'sidebar_first';
$edit['settings[exposed][filter-' . $filter_id . '][' . $filter_id . ']'] = '2';
$this->drupalGet('admin/structure/block/manage/views_block__ctools_views_entity_test_block_filter_text_grouped');
$this->submitForm($edit, 'Save block');
// Assert configure_filters overridden settings.
$this->drupalGet('<front>');
// Check that the overridden operator returns proper results.
$this->assertEquals(2, count($this->xpath('//div[contains(@class, "view-display-id-block_filter_text_grouped")]//table/tbody/tr')));
$this->assertSession()
->elementTextEquals('xpath', '(//div[contains(@class, "view-display-id-block_filter_text_grouped")]//table/tbody/tr)[1]', 'Test entity 1');
$this->assertSession()
->elementTextEquals('xpath', '(//div[contains(@class, "view-display-id-block_filter_text_grouped")]//table/tbody/tr)[2]', 'Test entity 2');
// Override configure_filters settings with test value equals group.
$edit = [];
$edit['region'] = 'sidebar_first';
$edit['settings[exposed][filter-' . $filter_id . '][' . $filter_id . ']'] = '3';
$this->drupalGet('admin/structure/block/manage/views_block__ctools_views_entity_test_block_filter_text_grouped');
$this->submitForm($edit, 'Save block');
// Assert configure_filters overridden settings.
$this->drupalGet('<front>');
// Check that the overridden operator returns proper results.
$this->assertEquals(1, count($this->xpath('//div[contains(@class, "view-display-id-block_filter_text_grouped")]//table/tbody/tr')));
$this->assertSession()
->elementTextEquals('xpath', '(//div[contains(@class, "view-display-id-block_filter_text_grouped")]//table/tbody/tr)[1]', 'Test entity 1');
}