Commit 76eba8b7 authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch
Browse files

Issue #3321150 by e0ipso: [META] Test coverage

parent 07395073
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -96,13 +96,15 @@ final class ComponentMetadata {
   *
   * @param array $metadata_info
   *   The metadata info.
   * @param string $app_root
   *   The application root.
   *
   * @throws \Drupal\sdc\Exception\InvalidComponentException
   */
  public function __construct(array $metadata_info = []) {
  public function __construct(array $metadata_info, string $app_root) {
    $path = $metadata_info['path'];
    // Make the absolute path, relative to the Drupal root.
    $app_root = rtrim(\Drupal::root(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    $app_root = rtrim($app_root, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    if (str_starts_with($path, $app_root)) {
      $path = substr($path, strlen($app_root));
    }
+9 −3
Original line number Diff line number Diff line
@@ -47,9 +47,15 @@ class SchemaCompatibilityChecker {
  public function isCompatible(array $original_schema, array $new_schema): void {
    $error_messages = [];
    // First check the required properties.
    $error_messages = [...$error_messages, ...$this->checkRequired($original_schema, $new_schema)];
    $error_messages = [
      ...$error_messages,
      ...$this->checkRequired($original_schema, $new_schema),
    ];
    // Next, compare the property types to ensure compatibility.
    $error_messages = [...$error_messages, ...$this->checkSharedProperties($original_schema, $new_schema)];
    $error_messages = [
      ...$error_messages,
      ...$this->checkSharedProperties($original_schema, $new_schema),
    ];
    // Finally, raise any potential issues that we might have detected.
    if (!empty($error_messages)) {
      $message = implode("\n", $error_messages);
@@ -139,7 +145,7 @@ class SchemaCompatibilityChecker {
            sprintf(
              'Property "%s" does not allow some necessary enum values [%s]. These are supported in the original schema and should be supported in the new schema for compatibility.',
              $property_name,
              $unsupported_enums
              implode(', ', $unsupported_enums),
            ),
          ];
        }
+2 −2
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ class ComponentNegotiator {
    // Consider only the component definitions matching the component ID.
    $matches = array_filter(
      $all_definitions,
      static fn(array $definition) => $component_id === ($definition['replaces'] ?? ''),
      static fn(array $definition) => $component_id === ($definition['replaces'] ?? NULL),
    );
    $negotiated_plugin_id = $this->maybeNegotiateByTheme($matches);
    if ($negotiated_plugin_id) {
@@ -140,7 +140,7 @@ class ComponentNegotiator {
    );
    $sort_by_module_weight = static function (array $definition_a, array $definition_b) use ($module_list) {
      $a_weight = $module_list[$definition_a['provider'] ?? '']?->weight ?? 999;
      $b_weight = $theme_weights[$definition_b['provider'] ?? '']?->weight ?? 999;
      $b_weight = $module_list[$definition_b['provider'] ?? '']?->weight ?? 999;
      return $a_weight <=> $b_weight;
    };
    uasort($candidates, $sort_by_module_weight);
+3 −3
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ class ComponentElement extends RenderElement {
    $context = $element['#context'] ?? [];
    $bubbleable_metadata = new BubbleableMetadata();
    $twig_blocks = $element['#twig_blocks'] ?? [];
    $trusted_blocks = $element['#trusted_blocks'] ?? FALSE;
    $trusted_blocks = $element['#trusted_blocks'] ?? TRUE;
    $inline_template = static::generateComponentTemplate(
      $id,
      $twig_blocks,
@@ -114,11 +114,11 @@ class ComponentElement extends RenderElement {
        : $block_value;
      $block_build = $trusted_blocks
        ? ['#markup' => Xss::filterAdmin($bl_val)]
        : [
        : array_filter([
          '#type' => 'processed_text',
          '#text' => $bl_val,
          '#format' => is_array($block_value) ? $block_value['format'] : NULL,
        ];
        ]);
      try {
        $value = \Drupal::service('renderer')->render($block_build);
      }
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ class Component extends PluginBase {
    $this->template = $plugin_definition['template'] ?? NULL;
    $this->machineName = $plugin_definition['machineName'];
    $this->library = $plugin_definition['library'] ?? [];
    $this->metadata = new ComponentMetadata($plugin_definition);
    $this->metadata = new ComponentMetadata($plugin_definition, \Drupal::root());
    $this->validate();
  }

Loading