function RendererTest::assertAccess

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::assertAccess()
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::assertAccess()
  3. 11.x core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::assertAccess()

Asserts that a render array with access checking renders correctly.

@internal

Parameters

array $build: A render array with either #access or #access_callback.

\Drupal\Core\Access\AccessResultInterface|bool $access: Whether the render array is accessible or not.

4 calls to RendererTest::assertAccess()
RendererTest::testRenderWithAccessCallbackCallable in core/tests/Drupal/Tests/Core/Render/RendererTest.php
@covers ::render @covers ::doRender
RendererTest::testRenderWithAccessControllerResolved in core/tests/Drupal/Tests/Core/Render/RendererTest.php
@covers ::render @covers ::doRender
RendererTest::testRenderWithAccessPropertyAndCallback in core/tests/Drupal/Tests/Core/Render/RendererTest.php
Ensures that the #access property wins over the callable.
RendererTest::testRenderWithPresetAccess in core/tests/Drupal/Tests/Core/Render/RendererTest.php
@covers ::render @covers ::doRender

File

core/tests/Drupal/Tests/Core/Render/RendererTest.php, line 742

Class

RendererTest
@coversDefaultClass \Drupal\Core\Render\Renderer @group Render

Namespace

Drupal\Tests\Core\Render

Code

protected function assertAccess(array $build, $access) : void {
    $sensitive_content = $this->randomContextValue();
    $build['#markup'] = $sensitive_content;
    if ($access instanceof AccessResultInterface && $access->isAllowed() || $access === TRUE) {
        $this->assertSame($sensitive_content, (string) $this->renderer
            ->renderRoot($build));
    }
    else {
        $this->assertSame('', (string) $this->renderer
            ->renderRoot($build));
    }
}

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