Verified Commit a4785d91 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3385283 by e0ipso, smustgrave, idiaz.roncero, jldust, wotnak:...

Issue #3385283 by e0ipso, smustgrave, idiaz.roncero, jldust, wotnak: Components without props throw error

(cherry picked from commit 99040d47)
parent c4db1fe9
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@ public function validateDefinition(array $definition, bool $enforce_schemas): bo
      }
      return TRUE;
    }
    // If there are no props, force casting to object instead of array.
    if (($schema['properties'] ?? NULL) === []) {
      $schema['properties'] = new \stdClass();
    }
    $classes_per_prop = $this->getClassProps($schema);
    $missing_class_errors = [];
    foreach ($classes_per_prop as $prop_name => $class_types) {
+6 −0
Original line number Diff line number Diff line
$schema: https://git.drupalcode.org/project/sdc/-/raw/1.x/src/metadata.schema.json
name: No props
description: Component without properties
props:
  type: object
  properties: {}
+1 −0
Original line number Diff line number Diff line
This is a test string.
+17 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public function testRender(): void {
    $this->checkRenderElementAlters();
    $this->checkSlots();
    $this->checkInvalidSlot();
    $this->checkEmptyProps();
  }

  /**
@@ -335,6 +336,22 @@ public function checkInvalidSlot(): void {
    $this->renderComponentRenderArray($build);
  }

  /**
   * Ensure that components can have 0 props.
   */
  public function checkEmptyProps(): void {
    $build = [
      '#type' => 'component',
      '#component' => 'sdc_test:no-props',
      '#props' => [],
    ];
    $crawler = $this->renderComponentRenderArray($build);
    $this->assertEquals(
      $crawler->filter('#sdc-wrapper')->innerText(),
      'This is a test string.'
    );
  }

  /**
   * Ensures some key aspects of the plugin definition are correctly computed.
   *