Skip to content
Snippets Groups Projects
Verified Commit 35adb459 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3341438 by DanielVeza, andypost: Add test coverage for layout_builder_entity_view_alter()

(cherry picked from commit 82ba8f54)
parent a55f5739
No related branches found
No related tags found
7 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words
Pipeline #110257 passed with warnings
Pipeline: drupal

#110261

    <?php
    declare(strict_types=1);
    namespace Drupal\Tests\layout_builder\Kernel;
    use Drupal\Core\Routing\RouteObjectInterface;
    use Drupal\entity_test\Entity\EntityTest;
    use Drupal\KernelTests\KernelTestBase;
    use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Session\Session;
    use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
    use Symfony\Component\Routing\Route;
    /**
    * @covers layout_builder_entity_view_alter
    *
    * @group layout_builder
    */
    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);
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment