Skip to content

Commit 1691273

Browse files
committed
Update test suite
1 parent ae123d4 commit 1691273

File tree

6 files changed

+37
-6
lines changed

6 files changed

+37
-6
lines changed

features/main/crud.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Feature: Create-Retrieve-Update-Delete
2222
Then the response status code should be 201
2323
And the response should be in JSON
2424
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
25+
And the header "Content-Location" should be equal to "/dummies/1"
26+
And the header "Location" should be equal to "/dummies/1"
2527
And the JSON should be equal to:
2628
"""
2729
{
@@ -420,6 +422,7 @@ Feature: Create-Retrieve-Update-Delete
420422
Then the response status code should be 200
421423
And the response should be in JSON
422424
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
425+
And the header "Content-Location" should be equal to "/dummies/1"
423426
And the JSON should be equal to:
424427
"""
425428
{
@@ -457,6 +460,7 @@ Feature: Create-Retrieve-Update-Delete
457460
Then the response status code should be 200
458461
And the response should be in JSON
459462
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
463+
And the header "Content-Location" should be equal to "/dummies/1"
460464
And the JSON should be equal to:
461465
"""
462466
{

features/main/crud_abstract.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Feature: Create-Retrieve-Update-Delete on abstract resource
1616
Then the response status code should be 201
1717
And the response should be in JSON
1818
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
19+
And the header "Content-Location" should be equal to "/concrete_dummies/1"
20+
And the header "Location" should be equal to "/concrete_dummies/1"
1921
And the JSON should be equal to:
2022
"""
2123
{
@@ -90,6 +92,8 @@ Feature: Create-Retrieve-Update-Delete on abstract resource
9092
Then the response status code should be 200
9193
And the response should be in JSON
9294
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
95+
And the header "Content-Location" should be equal to "/concrete_dummies/1"
96+
And the header "Location" should be equal to "/concrete_dummies/1"
9397
And the JSON should be equal to:
9498
"""
9599
{

features/main/custom_normalized.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Feature: Using custom normalized entity
1616
Then the response status code should be 201
1717
And the response should be in JSON
1818
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
19+
And the header "Content-Location" should be equal to "/custom_normalized_dummies/1"
20+
And the header "Location" should be equal to "/custom_normalized_dummies/1"
1921
And the JSON should be equal to:
2022
"""
2123
{
@@ -40,6 +42,8 @@ Feature: Using custom normalized entity
4042
Then the response status code should be 201
4143
And the response should be in JSON
4244
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
45+
And the header "Content-Location" should be equal to "/related_normalized_dummies/1"
46+
And the header "Location" should be equal to "/related_normalized_dummies/1"
4347
And the JSON should be equal to:
4448
"""
4549
{
@@ -68,6 +72,7 @@ Feature: Using custom normalized entity
6872
Then the response status code should be 200
6973
And the response should be in JSON
7074
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
75+
And the header "Content-Location" should be equal to "/related_normalized_dummies/1"
7176
And the JSON should be equal to:
7277
"""
7378
{
@@ -134,6 +139,7 @@ Feature: Using custom normalized entity
134139
Then the response status code should be 200
135140
And the response should be in JSON
136141
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
142+
And the header "Content-Location" should be equal to "/custom_normalized_dummies/1"
137143
And the JSON should be equal to:
138144
"""
139145
{

features/main/custom_writable_identifier.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Feature: Using custom writable identifier on resource
1616
Then the response status code should be 201
1717
And the response should be in JSON
1818
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
19+
And the header "Content-Location" should be equal to "/custom_writable_identifier_dummies/my_slug"
20+
And the header "Location" should be equal to "/custom_writable_identifier_dummies/my_slug"
1921
And the JSON should be equal to:
2022
"""
2123
{
@@ -78,6 +80,7 @@ Feature: Using custom writable identifier on resource
7880
Then the response status code should be 200
7981
And the response should be in JSON
8082
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
83+
And the header "Content-Location" should be equal to "/custom_writable_identifier_dummies/slug_modified"
8184
And the JSON should be equal to:
8285
"""
8386
{

features/main/uuid.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Feature: Using uuid identifier on resource
1616
Then the response status code should be 201
1717
And the response should be in JSON
1818
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
19+
And the header "Content-Location" should be equal to "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78"
20+
And the header "Location" should be equal to "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78"
1921

2022
Scenario: Get a resource
2123
When I send a "GET" request to "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78"
@@ -67,6 +69,7 @@ Feature: Using uuid identifier on resource
6769
Then the response status code should be 200
6870
And the response should be in JSON
6971
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
72+
And the header "Content-Location" should be equal to "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78"
7073
And the JSON should be equal to:
7174
"""
7275
{
@@ -87,6 +90,7 @@ Feature: Using uuid identifier on resource
8790
Then the response status code should be 201
8891
And the response should be in JSON
8992
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
93+
And the header "Content-Location" should be equal to "/custom_generated_identifiers/foo"
9094
And the JSON should be equal to:
9195
"""
9296
{

src/EventListener/RespondListener.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,25 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
4242
return;
4343
}
4444

45+
$headers = [
46+
'Content-Type' => sprintf('%s; charset=utf-8', $request->getMimeType($request->getRequestFormat())),
47+
'Vary' => 'Accept',
48+
'X-Content-Type-Options' => 'nosniff',
49+
'X-Frame-Options' => 'deny',
50+
];
51+
52+
if($request->isMethod('POST') || $request->isMethod('PUT')){
53+
$headers['Content-Location'] = $request->attributes->get('_iri_item');
54+
}
55+
56+
if($request->isMethod('POST')){
57+
$headers['Location'] = $request->attributes->get('_iri_item');
58+
}
59+
4560
$event->setResponse(new Response(
4661
$controllerResult,
4762
self::METHOD_TO_CODE[$request->getMethod()] ?? Response::HTTP_OK,
48-
[
49-
'Content-Type' => sprintf('%s; charset=utf-8', $request->getMimeType($request->getRequestFormat())),
50-
'Vary' => 'Accept',
51-
'X-Content-Type-Options' => 'nosniff',
52-
'X-Frame-Options' => 'deny',
53-
]
63+
$headers
5464
));
5565
}
5666
}

0 commit comments

Comments
 (0)