public function ExtraFieldsTest::testExtraFieldAccess in Entity Print 8.2
Test the access control for the extra fields.
File
- tests/
src/ Kernel/ ExtraFieldsTest.php, line 74
Class
- ExtraFieldsTest
- Tests the hook_extra_fields() implementation.
Namespace
Drupal\Tests\entity_print\KernelCode
public function testExtraFieldAccess() {
$controller = NodeViewController::create($this->container);
$renderer = $this->container
->get('renderer');
// The View PDF links are rendered.
$build = $controller
->view($this->node, 'default');
$text = (string) $renderer
->renderPlain($build);
$this
->assertStringContainsString('View PDF', $text);
// Change to the anonymous user.
$this->container
->get('current_user')
->setAccount(new AnonymousUserSession());
// The View PDF links are not rendered because we don't have access.
$build = $controller
->view($this->node, 'default');
$text = (string) $renderer
->renderPlain($build);
$this
->assertStringNotContainsString('View PDF', $text);
}