You are here

public function AccessPermissionTest::testRenderCaching in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php \Drupal\Tests\user\Kernel\Views\AccessPermissionTest::testRenderCaching()
  2. 9 core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php \Drupal\Tests\user\Kernel\Views\AccessPermissionTest::testRenderCaching()

Tests access on render caching.

File

core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php, line 89

Class

AccessPermissionTest
Tests views perm access plugin.

Namespace

Drupal\Tests\user\Kernel\Views

Code

public function testRenderCaching() {
  $view = Views::getView('test_access_perm');
  $display =& $view->storage
    ->getDisplay('default');
  $display['display_options']['cache'] = [
    'type' => 'tag',
  ];
  $renderer = $this->container
    ->get('renderer');
  $account_switcher = $this->container
    ->get('account_switcher');

  // First access as user without access.
  $build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default');
  $account_switcher
    ->switchTo($this->webUser);
  $this
    ->assertEmpty($renderer
    ->renderPlain($build));

  // Then with access.
  $build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default');
  $account_switcher
    ->switchTo($this->normalUser);
  $this
    ->assertNotEmpty($renderer
    ->renderPlain($build));
}