function EntityViewAlterTest::testContextualLinksRemoved
Same name in other branches
- 10 core/modules/layout_builder/tests/src/Kernel/EntityViewAlterTest.php \Drupal\Tests\layout_builder\Kernel\EntityViewAlterTest::testContextualLinksRemoved()
Tests that contextual links are removed when rendering Layout Builder.
File
-
core/
modules/ layout_builder/ tests/ src/ Kernel/ EntityViewAlterTest.php, line 48
Class
- EntityViewAlterTest
- @covers layout_builder_entity_view_alter
Namespace
Drupal\Tests\layout_builder\KernelCode
public function testContextualLinksRemoved() : void {
$display = LayoutBuilderEntityViewDisplay::load('entity_test.bundle_with_extra_fields.default');
$entity = EntityTest::create();
$build = [
'#contextual_links' => [
'entity.node.canonical',
],
];
// Create a fake request that starts with layout_builder.
$request = Request::create('<front>');
$request->attributes
->set(RouteObjectInterface::ROUTE_NAME, 'layout_builder.test');
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
$request->setSession(new Session(new MockArraySessionStorage()));
\Drupal::requestStack()->push($request);
// Assert the contextual links are removed.
$layoutBuilderEntityViewAlter = new LayoutBuilderHooks();
$layoutBuilderEntityViewAlter->entityViewAlter($build, $entity, $display);
$this->assertArrayNotHasKey('#contextual_links', $build);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.