You are here

class LayoutBuilderEntityViewDisplayTest in Drupal 10

Same name in this branch
  1. 10 core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php \Drupal\Tests\layout_builder\Kernel\LayoutBuilderEntityViewDisplayTest
  2. 10 core/modules/layout_builder/tests/src/Functional/Jsonapi/LayoutBuilderEntityViewDisplayTest.php \Drupal\Tests\layout_builder\Functional\Jsonapi\LayoutBuilderEntityViewDisplayTest
Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php \Drupal\Tests\layout_builder\Kernel\LayoutBuilderEntityViewDisplayTest
  2. 9 core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php \Drupal\Tests\layout_builder\Kernel\LayoutBuilderEntityViewDisplayTest

@coversDefaultClass \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay

@group layout_builder

Hierarchy

Expanded class hierarchy of LayoutBuilderEntityViewDisplayTest

File

core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php, line 13

Namespace

Drupal\Tests\layout_builder\Kernel
View source
class LayoutBuilderEntityViewDisplayTest extends SectionListTestBase {

  /**
   * {@inheritdoc}
   */
  protected function getSectionList(array $section_data) {
    $display = LayoutBuilderEntityViewDisplay::create([
      'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => 'default',
      'status' => TRUE,
      'third_party_settings' => [
        'layout_builder' => [
          'enabled' => TRUE,
          'sections' => $section_data,
        ],
      ],
    ]);
    $display
      ->save();
    return $display;
  }

  /**
   * Tests that configuration schema enforces valid values.
   */
  public function testInvalidConfiguration() {
    $this
      ->expectException(SchemaIncompleteException::class);
    $this->sectionList
      ->getSection(0)
      ->getComponent('first-uuid')
      ->setConfiguration([
      'id' => 'foo',
      'bar' => 'baz',
    ]);
    $this->sectionList
      ->save();
  }

  /**
   * @dataProvider providerTestIsLayoutBuilderEnabled
   */
  public function testIsLayoutBuilderEnabled($expected, $view_mode, $enabled) {
    $display = LayoutBuilderEntityViewDisplay::create([
      'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => $view_mode,
      'status' => TRUE,
      'third_party_settings' => [
        'layout_builder' => [
          'enabled' => $enabled,
        ],
      ],
    ]);
    $result = $display
      ->isLayoutBuilderEnabled();
    $this
      ->assertSame($expected, $result);
  }

  /**
   * Provides test data for ::testIsLayoutBuilderEnabled().
   */
  public function providerTestIsLayoutBuilderEnabled() {
    $data = [];
    $data['default enabled'] = [
      TRUE,
      'default',
      TRUE,
    ];
    $data['default disabled'] = [
      FALSE,
      'default',
      FALSE,
    ];
    $data['full enabled'] = [
      TRUE,
      'full',
      TRUE,
    ];
    $data['full disabled'] = [
      FALSE,
      'full',
      FALSE,
    ];
    $data['_custom enabled'] = [
      FALSE,
      '_custom',
      TRUE,
    ];
    $data['_custom disabled'] = [
      FALSE,
      '_custom',
      FALSE,
    ];
    return $data;
  }

  /**
   * Tests that setting overridable enables Layout Builder only when TRUE.
   */
  public function testSetOverridable() {

    // Disable Layout Builder.
    $this->sectionList
      ->disableLayoutBuilder();

    // Set Overridable to TRUE and ensure Layout Builder is enabled.
    $this->sectionList
      ->setOverridable();
    $this
      ->assertTrue($this->sectionList
      ->isLayoutBuilderEnabled());

    // Ensure Layout Builder is still enabled after setting Overridable to FALSE.
    $this->sectionList
      ->setOverridable(FALSE);
    $this
      ->assertTrue($this->sectionList
      ->isLayoutBuilderEnabled());
  }

}

Members