public function AccessTest::testDrupalEntity in Twig Tweak 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/AccessTest.php \Drupal\Tests\twig_tweak\Kernel\AccessTest::testDrupalEntity()
Test callback.
File
- tests/
src/ Kernel/ AccessTest.php, line 82
Class
- AccessTest
- Tests for the Twig Tweak access control.
Namespace
Drupal\Tests\twig_tweak\KernelCode
public function testDrupalEntity() {
// -- Unprivileged user.
$this
->setUpCurrentUser([
'name' => 'User 1',
]);
$build = $this->twigExtension
->drupalEntity('node', $this->node
->id());
self::assertNull($build);
// -- Privileged user.
$this
->setUpCurrentUser([
'name' => 'User 2',
], [
'access content',
]);
$build = $this->twigExtension
->drupalEntity('node', $this->node
->id());
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']);
}