function CToolsViewsBasicViewBlockTest::testHideFields

Same name in other branches
  1. 4.0.x modules/ctools_views/tests/src/Functional/CToolsViewsBasicViewBlockTest.php \Drupal\Tests\ctools_views\Functional\CToolsViewsBasicViewBlockTest::testHideFields()

Test ctools_views 'hide_fields' configuration.

File

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

Class

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

Namespace

Drupal\Tests\ctools_views\Functional

Code

public function testHideFields() {
    $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_fields/' . $default_theme);
    $this->assertSession()
        ->fieldExists('edit-settings-override-order-fields-id-hide');
    // Add block to sidebar_first region with default settings.
    $edit = [];
    $edit['region'] = 'sidebar_first';
    $edit['id'] = 'views_block__ctools_views_test_view_block_fields';
    $this->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_fields/' . $default_theme);
    $this->submitForm($edit, 'Save block');
    // Assert hide_fields default settings.
    $this->drupalGet('<front>');
    $this->assertEquals(5, count($this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//td[contains(@class, "views-field-id")]')));
    // Override hide_fields settings.
    $edit = [];
    $edit['region'] = 'sidebar_first';
    $edit['settings[override][order_fields][id][hide]'] = 1;
    $this->drupalGet('admin/structure/block/manage/views_block__ctools_views_test_view_block_fields');
    $this->submitForm($edit, 'Save block');
    $block = $this->storage
        ->load('views_block__ctools_views_test_view_block_fields');
    $config = $block->getPlugin()
        ->getConfiguration();
    $this->assertEquals(1, $config['fields']['id']['hide'], "'hide_fields' setting is properly saved.");
    $this->assertEquals(0, $config['fields']['name']['hide'], "'hide_fields' setting is properly saved.");
    // Assert hide_fields overridden settings.
    $this->drupalGet('<front>');
    $this->assertEquals(0, count($this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//td[contains(@class, "views-field-id")]')));
}