You are here

public function PagerKernelTest::testSetPagerMethods in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php \Drupal\Tests\views\Kernel\Plugin\PagerKernelTest::testSetPagerMethods()

Tests pager-related setter methods on ViewExecutable.

See also

\Drupal\views\ViewExecutable::setItemsPerPage

\Drupal\views\ViewExecutable::setOffset

\Drupal\views\ViewExecutable::setCurrentPage

File

core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php, line 43

Class

PagerKernelTest
Tests pager-related APIs.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testSetPagerMethods() {
  $view = Views::getView('test_pager_full');

  // Mark the view as cacheable in order have the cache checking working
  // below.
  $display =& $view->storage
    ->getDisplay('default');
  $display['display_options']['cache']['type'] = 'tag';
  $view->storage
    ->save();
  $output = $view
    ->preview();
  \Drupal::service('renderer')
    ->renderPlain($output);
  $this
    ->assertIdentical(CacheBackendInterface::CACHE_PERMANENT, $output['#cache']['max-age']);
  foreach ([
    'setItemsPerPage',
    'setOffset',
    'setCurrentPage',
  ] as $method) {
    $view = Views::getView('test_pager_full');
    $view
      ->setDisplay('default');
    $view
      ->{$method}(1);
    $output = $view
      ->preview();
    \Drupal::service('renderer')
      ->renderPlain($output);
    $this
      ->assertIdentical(CacheBackendInterface::CACHE_PERMANENT, $output['#cache']['max-age'], 'Max age kept.');
  }
}