class EntityViewAlterTest
Same name and namespace in other branches
- 11.x core/modules/layout_builder/tests/src/Kernel/EntityViewAlterTest.php \Drupal\Tests\layout_builder\Kernel\EntityViewAlterTest
@covers layout_builder_entity_view_alter
@group layout_builder
Hierarchy
- class \Drupal\Tests\layout_builder\Kernel\EntityViewAlterTest
Expanded class hierarchy of EntityViewAlterTest
File
-
core/
modules/ layout_builder/ tests/ src/ Kernel/ EntityViewAlterTest.php, line 21
Namespace
Drupal\Tests\layout_builder\KernelView source
class EntityViewAlterTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'layout_discovery',
'layout_builder',
'layout_builder_defaults_test',
'entity_test',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
entity_test_create_bundle('bundle_with_extra_fields');
$this->installEntitySchema('entity_test');
$this->installConfig([
'layout_builder_defaults_test',
]);
}
/**
* Tests that contextual links are removed when rendering Layout Builder.
*/
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.
layout_builder_entity_view_alter($build, $entity, $display);
$this->assertArrayNotHasKey('#contextual_links', $build);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
EntityViewAlterTest::$modules | protected static | property | Modules to install. |
EntityViewAlterTest::setUp | protected | function | |
EntityViewAlterTest::testContextualLinksRemoved | public | function | Tests that contextual links are removed when rendering Layout Builder. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.