You are here

class PagerKernelTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php \Drupal\Tests\views\Kernel\Plugin\PagerKernelTest
  2. 9 core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php \Drupal\Tests\views\Kernel\Plugin\PagerKernelTest

Tests pager-related APIs.

@group views

Hierarchy

  • class \Drupal\Tests\views\Kernel\Plugin\PagerKernelTest extends \Drupal\Tests\views\Kernel\ViewsKernelTestBase

Expanded class hierarchy of PagerKernelTest

File

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

Namespace

Drupal\Tests\views\Kernel\Plugin
View source
class PagerKernelTest extends ViewsKernelTestBase {

  /**
   * {@inheritdoc}
   */
  public static $testViews = [
    'test_pager_full',
  ];

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'user',
    'node',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE) : void {
    parent::setUp($import_test_views);
    $this
      ->installEntitySchema('node');
    $this
      ->installEntitySchema('user');
  }

  /**
   * Tests pager-related setter methods on ViewExecutable.
   *
   * @see \Drupal\views\ViewExecutable::setItemsPerPage
   * @see \Drupal\views\ViewExecutable::setOffset
   * @see \Drupal\views\ViewExecutable::setCurrentPage
   */
  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.');
    }
  }

}

Members