Commit ef4d9143 authored by Adam G-H's avatar Adam G-H
Browse files

Add a test of Layout Builder integration with static context values stored in...

Add a test of Layout Builder integration with static context values stored in an entity view display's third party settings.
parent a5ecd562
Loading
Loading
Loading
Loading
+53 −1
Original line number Diff line number Diff line
@@ -33,10 +33,62 @@ class LayoutBuilderIntegrationTest extends BrowserTestBase {
    $this->drupalCreateContentType(['type' => 'page']);
  }

  /**
   * Tests that context values in an entity display's third-party settings
   * appear in Layout Builder.
   */
  public function testContextValuesInEntityDisplayThirdPartySettings() {
    $component = SectionComponent::fromArray([
      'uuid' => $this->container->get('uuid')->generate(),
      'region' => 'content',
      'configuration' => [
        'id' => 'context_block',
        'context_mapping' => [
          'value' => '@core_context.entity:value',
          'letter' => '@core_context.entity:letter',
        ],
      ],
      'additional' => [],
      'weight' => 0,
    ]);

    $section = new Section('layout_onecol');
    $section->appendComponent($component);

    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display */
    $display = $this->container->get('entity_display.repository')
      ->getViewDisplay('node', 'page', 'full');
    $display->enableLayoutBuilder()
      ->setOverridable()
      ->appendSection($section)
      ->setThirdPartySetting('core_context', 'contexts', [
        'value' => [
          'type' => 'integer',
          'label' => 'Holy computer number',
          'description' => 'A convenient power of two',
          'value' => 512,
        ],
        'letter' => [
          'type' => 'string',
          'label' => 'Sponsoring letter',
          'description' => 'A letter of the NATO phonetic alphabet',
          'value' => 'Charlie',
        ],
      ])
      ->save();

    $node = $this->drupalCreateNode(['type' => 'page']);
    $this->drupalGet($node->toUrl());

    $assert_session = $this->assertSession();
    $assert_session->statusCodeEquals(200);
    $assert_session->pageTextContains('The context value is 512, brought to you by the letter Charlie.');
  }

  /**
   * Tests that context values in an entity field appear in Layout Builder.
   */
  public function testContextValuesInEntityFIeld() {
  public function testContextValuesInEntityField() {
    $component = SectionComponent::fromArray([
      'uuid' => $this->container->get('uuid')->generate(),
      'region' => 'content',