function CToolsViewsBasicViewBlockTest::testPager

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

Test ctools_views "pager" configuration.

File

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

Class

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

Namespace

Drupal\Tests\ctools_views\Functional

Code

public function testPager() {
    $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->assertSession()
        ->fieldValueEquals('edit-settings-override-pager-view', 'view');
    $this->assertSession()
        ->fieldExists('edit-settings-override-pager-some');
    $this->assertSession()
        ->fieldExists('edit-settings-override-pager-none');
    // 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 default settings.
    $this->drupalGet('<front>');
    $this->assertSession()
        ->pageTextContains('Page 1');
    $this->assertSession()
        ->pageTextContains('Next ›');
    // Override pager settings to 'some'.
    $edit = [];
    $edit['region'] = 'sidebar_first';
    $edit['settings[override][items_per_page]'] = 0;
    $edit['settings[override][pager]'] = 'some';
    $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('some', $config['pager'], "'Pager' setting is properly saved.");
    // Assert pager overridden settings to 'some', showing no pager.
    $this->drupalGet('<front>');
    $this->assertEquals(3, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
    $this->assertSession()
        ->elementNotExists('css', '#block-views-block-ctools-views-test-view-block-pager .pager');
    // Override pager settings to 'none'.
    $edit = [];
    $edit['region'] = 'sidebar_first';
    $edit['settings[override][items_per_page]'] = 0;
    $edit['settings[override][pager]'] = 'none';
    $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('none', $config['pager'], "'Pager' setting is properly saved.");
    // Assert pager overridden settings to 'some', showing no pager.
    $this->drupalGet('<front>');
    $this->assertEquals(5, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
    $this->assertSession()
        ->elementNotExists('css', '#block-views-block-ctools-views-test-view-block-pager .pager');
}