PagerKernelTest.php in Drupal 9
File
core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php
View source
<?php
namespace Drupal\Tests\views\Kernel\Plugin;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
class PagerKernelTest extends ViewsKernelTestBase {
public static $testViews = [
'test_pager_full',
];
protected static $modules = [
'user',
'node',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
}
public function testSetPagerMethods() {
$view = Views::getView('test_pager_full');
$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.');
}
}
}