diff --git a/features/relation.feature b/features/relation.feature index c172e9b94bc..f52ad0c964c 100644 --- a/features/relation.feature +++ b/features/relation.feature @@ -249,16 +249,15 @@ Feature: Relations support } """ - @wip Scenario: Create an existing relation When I send a "POST" request to "/relation_embedders" with body: """ - { - "anotherRelated": { - "symfony": "laravel" - } + { + "anotherRelated": { + "symfony": "laravel" } - """ + } + """ Then the response status code should be 201 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json" @@ -279,16 +278,31 @@ Feature: Relations support } """ + Scenario: Post a wrong relation + When I send a "POST" request to "/relation_embedders" with body: + """ + { + "anotherRelated": { + "@id": "/related_dummies/123", + "@type": "https://schema.org/Product", + "symfony": "phalcon" + } + } + """ + Then the response status code should be 400 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json" + Scenario: Update an embedded relation When I send a "PUT" request to "/relation_embedders/2" with body: """ - { - "anotherRelated": { - "@id": "/related_dummies/2", - "symfony": "API Platform" - } + { + "anotherRelated": { + "@id": "/related_dummies/2", + "symfony": "API Platform" } - """ + } + """ Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json" @@ -313,14 +327,14 @@ Feature: Relations support Scenario: Update an existing relation When I send a "POST" request to "/relation_embedders" with body: """ - { - "anotherRelated": { - "@id": "/related_dummies/2", - "@type": "https://schema.org/Product", - "symfony": "phalcon" - } + { + "anotherRelated": { + "@id": "/related_dummies/2", + "@type": "https://schema.org/Product", + "symfony": "phalcon" } - """ + } + """ Then the response status code should be 201 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json" diff --git a/src/JsonLd/Serializer/ItemNormalizer.php b/src/JsonLd/Serializer/ItemNormalizer.php index 801f51f4c9e..5809beeda23 100644 --- a/src/JsonLd/Serializer/ItemNormalizer.php +++ b/src/JsonLd/Serializer/ItemNormalizer.php @@ -125,7 +125,7 @@ public function denormalize($data, $class, $format = null, array $context = []) $overrideClass = isset($data['@id']) && !isset($context['object_to_populate']); if ($overrideClass) { - $context['object_to_populate'] = $this->iriConverter->getItemFromIri($data['@id']); + $context['object_to_populate'] = $this->iriConverter->getItemFromIri($data['@id'], true); } return parent::denormalize($data, $class, $format, $context); @@ -295,7 +295,7 @@ private function denormalizeRelation(string $resourceClass, string $attributeNam { if (is_string($value)) { try { - return $this->iriConverter->getItemFromIri($value); + return $this->iriConverter->getItemFromIri($value, true); } catch (InvalidArgumentException $e) { // Give a chance to other normalizers (e.g.: DateTimeNormalizer) }