Skip to content
Snippets Groups Projects
Verified Commit d2b22e76 authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3462700 by niklan, richardgaunt, smustgrave, pdureau: Update...

Issue #3462700 by niklan, richardgaunt, smustgrave, pdureau: Update ComponentValidator to always include the component ID

(cherry picked from commit 39b27921)
parent 8e61da94
No related branches found
No related tags found
12 merge requests!11515Issue #3480419 by mondrake, smustgrave, catch: Method...,!11380Issue #3490698 by catch, spokje: Bump MINIMUM_STABILITY back to 'stable' when...,!11281Use Drupal Core Leadership terminology in MAINTAINERS.txt,!11239Issue #3507548: Allow workspace changes listing to show all items, without a pager,!11238Fix issue #3051797,!11213Issue #3506743 by tomislav.matokovic: Increasing the color contrast for the navigation block title against the background of the navigation sidebar to at least 4.5:1,!11147Draft: Try to avoid manually setting required cache contexts,!11108Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks,!11093Drupal on MongoDB 11.1.x,!11017Issue #3502540: Add date filter for moderated content.,!11009Issue #3486972 migrate feed icon,!10999Cleaning up Taxonomy hooks and updating baseline.
Pipeline #403959 passed
Pipeline: drupal

#403960

    ...@@ -138,7 +138,7 @@ public function validateDefinition(array $definition, bool $enforce_schemas): bo ...@@ -138,7 +138,7 @@ public function validateDefinition(array $definition, bool $enforce_schemas): bo
    ...$message_parts, ...$message_parts,
    ...$missing_class_errors, ...$missing_class_errors,
    ]; ];
    $message = implode("/n", $message_parts); $message = implode("\n", $message_parts);
    // Throw the exception with the error message. // Throw the exception with the error message.
    throw new InvalidComponentException($message); throw new InvalidComponentException($message);
    } }
    ...@@ -208,7 +208,7 @@ function (array $error) use ($context): bool { ...@@ -208,7 +208,7 @@ function (array $error) use ($context): bool {
    return TRUE; return TRUE;
    } }
    $message_parts = array_map( $message_parts = array_map(
    static function (array $error): string { static function (array $error) use ($component_id, $context): string {
    // We check the error message instead of values and definitions here // We check the error message instead of values and definitions here
    // because it's hard to access both given the possible complexity of a // because it's hard to access both given the possible complexity of a
    // schema. Since this is a small non critical DX improvement error // schema. Since this is a small non critical DX improvement error
    ...@@ -217,11 +217,17 @@ static function (array $error): string { ...@@ -217,11 +217,17 @@ static function (array $error): string {
    $error['message'] .= '. This may be because the property is empty instead of having data present. If possible fix the source data, use the |default() twig filter, or update the schema to allow multiple types.'; $error['message'] .= '. This may be because the property is empty instead of having data present. If possible fix the source data, use the |default() twig filter, or update the schema to allow multiple types.';
    } }
    return sprintf("[%s] %s", $error['property'], $error['message']); // If the property value has been set, print it out for easier
    // debugging.
    if (isset($context[$error['property']]) && \is_scalar($context[$error['property']])) {
    $error['message'] .= \sprintf('. The provided value is: "%s"', $context[$error['property']]);
    }
    return sprintf('[%s/%s] %s.', $component_id, $error['property'], $error['message']);
    }, },
    $errors $errors
    ); );
    $message = implode("/n", $message_parts); $message = implode("\n", $message_parts);
    throw new InvalidComponentException($message); throw new InvalidComponentException($message);
    } }
    ...@@ -276,7 +282,7 @@ private function validateClassProps(array $props_schema, array $props_raw, strin ...@@ -276,7 +282,7 @@ private function validateClassProps(array $props_schema, array $props_raw, strin
    } }
    $props_schema = $this->nullifyClassPropsSchema($props_schema, $classes_per_prop); $props_schema = $this->nullifyClassPropsSchema($props_schema, $classes_per_prop);
    if (!empty($error_messages)) { if (!empty($error_messages)) {
    $message = implode("/n", $error_messages); $message = implode("\n", $error_messages);
    throw new InvalidComponentException($message); throw new InvalidComponentException($message);
    } }
    return [$props_schema, $props_raw]; return [$props_schema, $props_raw];
    ......
    ...@@ -159,13 +159,14 @@ public static function dataProviderValidatePropsValid(): array { ...@@ -159,13 +159,14 @@ public static function dataProviderValidatePropsValid(): array {
    * *
    * @throws \Drupal\Core\Render\Component\Exception\InvalidComponentException * @throws \Drupal\Core\Render\Component\Exception\InvalidComponentException
    */ */
    public function testValidatePropsInvalid(array $context, string $component_id, array $definition): void { public function testValidatePropsInvalid(array $context, string $component_id, array $definition, string $expected_exception_message): void {
    $component = new Component( $component = new Component(
    ['app_root' => '/fake/path/root'], ['app_root' => '/fake/path/root'],
    'sdc_test:' . $component_id, 'sdc_test:' . $component_id,
    $definition $definition
    ); );
    $this->expectException(InvalidComponentException::class); $this->expectException(InvalidComponentException::class);
    $this->expectExceptionMessage($expected_exception_message);
    $component_validator = new ComponentValidator(); $component_validator = new ComponentValidator();
    $component_validator->setValidator(); $component_validator->setValidator();
    $component_validator->validateProps($context, $component); $component_validator->validateProps($context, $component);
    ...@@ -175,7 +176,7 @@ public function testValidatePropsInvalid(array $context, string $component_id, a ...@@ -175,7 +176,7 @@ public function testValidatePropsInvalid(array $context, string $component_id, a
    * Data provider with invalid component props. * Data provider with invalid component props.
    * *
    * @return array * @return array
    * The data. * Returns the generator with the invalid properties.
    */ */
    public static function dataProviderValidatePropsInvalid(): array { public static function dataProviderValidatePropsInvalid(): array {
    return [ return [
    ...@@ -187,6 +188,7 @@ public static function dataProviderValidatePropsInvalid(): array { ...@@ -187,6 +188,7 @@ public static function dataProviderValidatePropsInvalid(): array {
    ], ],
    'my-cta', 'my-cta',
    static::loadComponentDefinitionFromFs('my-cta'), static::loadComponentDefinitionFromFs('my-cta'),
    '[sdc_test:my-cta/text] The property text is required.',
    ], ],
    'attributes with invalid object class' => [ 'attributes with invalid object class' => [
    [ [
    ...@@ -197,11 +199,13 @@ public static function dataProviderValidatePropsInvalid(): array { ...@@ -197,11 +199,13 @@ public static function dataProviderValidatePropsInvalid(): array {
    ], ],
    'my-cta', 'my-cta',
    static::loadComponentDefinitionFromFs('my-cta'), static::loadComponentDefinitionFromFs('my-cta'),
    'Data provided to prop "attributes" for component "sdc_test:my-cta" is not a valid instance of "Drupal\Core\Template\Attribute"',
    ], ],
    'ctaTarget violates the allowed properties in the enum' => [ 'ctaTarget violates the allowed properties in the enum' => [
    ['ctaTarget' => 'foo'], ['ctaTarget' => 'foo'],
    'my-banner', 'my-banner',
    static::loadComponentDefinitionFromFs('my-banner'), static::loadComponentDefinitionFromFs('my-banner'),
    '[sdc_test:my-banner/ctaTarget] Does not have a value in the enumeration ["","_blank"]. The provided value is: "foo".',
    ], ],
    ]; ];
    } }
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment