function AddComponentTest::testAddMultipleComponents

Tests adding multiple components at once.

File

core/modules/layout_builder/tests/src/Kernel/Plugin/ConfigAction/AddComponentTest.php, line 430

Class

AddComponentTest
Tests that `addComponentToLayout` config action.

Namespace

Drupal\Tests\layout_builder\Kernel\Plugin\ConfigAction

Code

public function testAddMultipleComponents() : void {
  $uuid1 = '955493d5-f4c0-4fd1-a8aa-6bcf92d455e6';
  $uuid2 = 'b6e2f3d1-a496-426c-b0e5-eff1d14fc461';
  $this->configActionManager
    ->applyAction('addComponentsToLayout', 'core.entity_view_display.entity_test.bundle_with_extra_fields.default', [
    [
      'section' => 0,
      'position' => 0,
      'component' => [
        'region' => [
          'layout_twocol_section' => 'first',
        ],
        'default_region' => 'content',
        'configuration' => [
          'id' => 'my_plugin_id',
        ],
        'uuid' => $uuid1,
      ],
    ],
    [
      'section' => 0,
      'position' => 1,
      'component' => [
        'region' => [
          'layout_twocol_section' => 'first',
        ],
        'default_region' => 'content',
        'configuration' => [
          'id' => 'my_plugin_id',
        ],
        'uuid' => $uuid2,
      ],
    ],
  ]);
  $display = EntityViewDisplay::load('entity_test.bundle_with_extra_fields.default');
  $components = $display?->getSection(0)->getComponents();
  $this->assertArrayHasKey($uuid1, $components);
  $this->assertArrayHasKey($uuid2, $components);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.