function PagerKernelTest::testSetPagerMethods

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php \Drupal\Tests\views\Kernel\Plugin\PagerKernelTest::testSetPagerMethods()
  2. 10 core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php \Drupal\Tests\views\Kernel\Plugin\PagerKernelTest::testSetPagerMethods()
  3. 11.x 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->assertSame(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->assertSame(CacheBackendInterface::CACHE_PERMANENT, $output['#cache']['max-age'], 'Max age kept.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.