Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions features/relation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/JsonLd/Serializer/ItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
}
Expand Down