You are here

protected function InfiniteScrollTest::createView in Views Infinite Scroll 8

Create a view setup for testing views_infinite_scroll.

Parameters

string $path: The path for the view.

array $settings: The VIS settings.

int $items_per_page: The number of items per page to display.

1 call to InfiniteScrollTest::createView()
InfiniteScrollTest::testInfiniteScroll in tests/src/FunctionalJavascript/InfiniteScrollTest.php
Test infinite scrolling under different conditions.

File

tests/src/FunctionalJavascript/InfiniteScrollTest.php, line 150

Class

InfiniteScrollTest
Test views infinite scroll.

Namespace

Drupal\Tests\views_infinite_scroll\FunctionalJavascript

Code

protected function createView($path, array $settings, $items_per_page = 3) {
  View::create([
    'label' => 'VIS Test',
    'id' => $this
      ->randomMachineName(),
    'base_table' => 'node_field_data',
    'display' => [
      'default' => [
        'display_plugin' => 'default',
        'id' => 'default',
        'display_options' => [
          'row' => [
            'type' => 'entity:node',
            'options' => [
              'view_mode' => 'teaser',
            ],
          ],
          'pager' => [
            'type' => 'infinite_scroll',
            'options' => [
              'items_per_page' => $items_per_page,
              'offset' => 0,
              'views_infinite_scroll' => $settings,
            ],
          ],
          'use_ajax' => TRUE,
        ],
      ],
      'page_1' => [
        'display_plugin' => 'page',
        'id' => 'page_1',
        'display_options' => [
          'path' => $path,
        ],
      ],
    ],
  ])
    ->save();
  \Drupal::service('router.builder')
    ->rebuild();
}