public function AccessTest::testDrupalBlock in Twig Tweak 8.2
Test callback.
See also
\Drupal\twig_tweak_test\Plugin\Block\FooBlock
File
- tests/
src/ Kernel/ AccessTest.php, line 309
Class
- AccessTest
- Tests for the Twig Tweak access control.
Namespace
Drupal\Tests\twig_tweak\KernelCode
public function testDrupalBlock() {
// -- Privileged user.
$this
->setUpCurrentUser([
'name' => 'User 1',
]);
$build = $this->twigExtension
->drupalBlock('twig_tweak_test_foo');
$expected_content = [
'#markup' => 'Foo',
'#cache' => [
'contexts' => [
'url',
],
'tags' => [
'tag_from_build',
],
],
];
self::assertSame($expected_content, $build['content']);
$expected_cache = [
'contexts' => [
'user',
],
'tags' => [
'tag_from_blockAccess',
'tag_twig_tweak_test_foo_plugin',
],
'max-age' => 35,
];
self::assertSame($expected_cache, $build['#cache']);
// -- Unprivileged user.
$this
->setUpCurrentUser([
'name' => 'User 2',
]);
$build = $this->twigExtension
->drupalBlock('twig_tweak_test_foo');
self::assertNull($build);
}