function CToolsViewsBasicViewBlockTest::testOffset

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

Test ctools_views "offset" configuration.

File

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

Class

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

Namespace

Drupal\Tests\ctools_views\Functional

Code

public function testOffset() {
    $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_pager/' . $default_theme);
    $this->assertNotEmpty($this->xpath('//input[@type="number" and @name="settings[override][pager_offset]"]'), 'items_per_page setting is a number field');
    // Add block to sidebar_first region with default settings.
    $edit = [];
    $edit['region'] = 'sidebar_first';
    $edit['id'] = 'views_block__ctools_views_test_view_block_pager';
    $edit['settings[override][items_per_page]'] = 0;
    $this->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_pager/' . $default_theme);
    $this->submitForm($edit, 'Save block');
    // Assert pager offset default settings.
    $this->drupalGet('<front>');
    $elements = $this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table//tr//td[contains(@class, "views-field-id")]');
    $results = array_map(function ($element) {
        return $element->getText();
    }, $elements);
    $this->assertEquals([
        1,
        2,
        3,
    ], $results);
    // Override pager offset settings.
    $edit = [];
    $edit['region'] = 'sidebar_first';
    $edit['settings[override][items_per_page]'] = 0;
    $edit['settings[override][pager_offset]'] = 1;
    $this->drupalGet('admin/structure/block/manage/views_block__ctools_views_test_view_block_pager');
    $this->submitForm($edit, 'Save block');
    $block = $this->storage
        ->load('views_block__ctools_views_test_view_block_pager');
    $config = $block->getPlugin()
        ->getConfiguration();
    $this->assertEquals(1, $config['pager_offset'], "'Pager offset' is properly saved.");
    // Assert pager offset overridden settings.
    $this->drupalGet('<front>');
    $elements = $this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table//tr//td[contains(@class, "views-field-id")]');
    $results = array_map(function ($element) {
        return $element->getText();
    }, $elements);
    $this->assertEquals([
        2,
        3,
        4,
    ], $results);
}