function AccessPermissionTest::testRenderCaching

Same name in other branches
  1. 8.9.x core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php \Drupal\Tests\user\Kernel\Views\AccessPermissionTest::testRenderCaching()
  2. 10 core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php \Drupal\Tests\user\Kernel\Views\AccessPermissionTest::testRenderCaching()
  3. 11.x 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));
}

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