You are here

public function CToolsViewsBasicViewBlockTest::testDisableFilters in Chaos Tool Suite (ctools) 8.3

Test ctools_views 'disable_filters' configuration.

File

modules/ctools_views/tests/src/Functional/CToolsViewsBasicViewBlockTest.php, line 290

Class

CToolsViewsBasicViewBlockTest
Tests ctools_views block display plugin overrides settings from a basic View.

Namespace

Drupal\Tests\ctools_views\Functional

Code

public function testDisableFilters() {
  $default_theme = $this
    ->config('system.theme')
    ->get('default');

  // Get the "Configure block" form for our Views block.
  $this
    ->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_filter/' . $default_theme);
  $this
    ->assertSession()
    ->fieldExists('edit-settings-override-filters-status-disable');
  $this
    ->assertSession()
    ->fieldExists('edit-settings-override-filters-job-disable');

  // Add block to sidebar_first region with default settings.
  $edit = [];
  $edit['region'] = 'sidebar_first';
  $this
    ->drupalPostForm('admin/structure/block/add/views_block:ctools_views_test_view-block_filter/' . $default_theme, $edit, $this
    ->t('Save block'));

  // Assert disable_filters default settings.
  $this
    ->drupalGet('<front>');

  // Check that the default settings show both filters.
  $this
    ->assertSession()
    ->fieldExists('status');
  $this
    ->assertSession()
    ->fieldExists('job');

  // Override disable_filters settings.
  $edit = [];
  $edit['region'] = 'sidebar_first';
  $edit['settings[override][filters][status][disable]'] = 1;
  $edit['settings[override][filters][job][disable]'] = 1;
  $this
    ->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_filter', $edit, $this
    ->t('Save block'));
  $block = $this->storage
    ->load('views_block__ctools_views_test_view_block_filter');
  $config = $block
    ->getPlugin()
    ->getConfiguration();
  $this
    ->assertEquals(1, $config['filter']['status']['disable'], "'disable_filters' setting is properly saved.");
  $this
    ->assertEquals(1, $config['filter']['job']['disable'], "'disable_filters' setting is properly saved.");

  // Assert disable_filters overridden settings.
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->fieldNotExists('status');
  $this
    ->assertSession()
    ->fieldNotExists('job');
}