You are here

protected function RendererTest::assertAccess in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Render/RendererTest.php \Drupal\Tests\Core\Render\RendererTest::assertAccess()

Asserts that a render array with access checking renders correctly.

Parameters

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

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 540
Contains \Drupal\Tests\Core\Render\RendererTest.

Class

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

Namespace

Drupal\Tests\Core\Render

Code

protected function assertAccess($build, $access) {
  $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));
  }
}