public function AccessTest::testView in Twig Tweak 8.2
Test callback.
File
- tests/
src/ Kernel/ AccessTest.php, line 515
Class
- AccessTest
- Tests for the Twig Tweak access control.
Namespace
Drupal\Tests\twig_tweak\KernelCode
public function testView() {
// -- Unprivileged user with access check.
$this
->setUpCurrentUser([
'name' => 'User 1',
]);
$build = $this->twigExtension
->view($this->node);
self::assertNull($build);
// -- Unprivileged user without access check.
$build = $this->twigExtension
->view($this->node, NULL, NULL, FALSE);
self::assertArrayHasKey('#node', $build);
$expected_cache = [
'tags' => [
'node:1',
'node_view',
],
'contexts' => [],
'max-age' => Cache::PERMANENT,
];
self::assertSame($expected_cache, $build['#cache']);
// -- Privileged user with access check.
$this
->setUpCurrentUser([
'name' => 'User 2',
], [
'access content',
]);
$build = $this->twigExtension
->view($this->node, NULL);
self::assertArrayHasKey('#node', $build);
$expected_cache = [
'tags' => [
'node:1',
'node_view',
'tag_from_twig_tweak_test_node_access',
],
'contexts' => [
'user',
'user.permissions',
],
'max-age' => 50,
];
self::assertSame($expected_cache, $build['#cache']);
// -- Privileged user without access check.
$build = $this->twigExtension
->view($this->node, NULL, NULL, FALSE);
self::assertArrayHasKey('#node', $build);
$expected_cache = [
'tags' => [
'node:1',
'node_view',
],
'contexts' => [],
'max-age' => Cache::PERMANENT,
];
self::assertSame($expected_cache, $build['#cache']);
}