Skip to content

Commit 5b7bb79

Browse files
Merge pull request #337 from api-platform/fix/formats
fix: tests and formats option
2 parents 515be20 + a34ac7f commit 5b7bb79

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

api/config/packages/api_platform.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ api_platform:
1212
graphql_playground: false
1313
formats:
1414
jsonld: ['application/ld+json']
15-
json: ['application/json']
1615
docs_formats:
1716
jsonld: ['application/ld+json']
1817
jsonopenapi: ['application/vnd.openapi+json']

api/tests/Api/Admin/BookTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ public function testAsNonAdminUserICannotCreateABook(int $expectedCode, string $
245245
'book' => 'https://openlibrary.org/books/OL28346544M.json',
246246
'condition' => BookCondition::NewCondition->value,
247247
],
248+
'headers' => [
249+
'Content-Type' => 'application/ld+json',
250+
'Accept' => 'application/ld+json',
251+
],
248252
]);
249253

250254
self::assertResponseStatusCodeSame($expectedCode);
@@ -269,6 +273,10 @@ public function testAsAdminUserICannotCreateABookWithInvalidData(array $data, in
269273
$this->client->request('POST', '/admin/books', [
270274
'auth_bearer' => $token,
271275
'json' => $data,
276+
'headers' => [
277+
'Content-Type' => 'application/ld+json',
278+
'Accept' => 'application/ld+json',
279+
],
272280
]);
273281

274282
self::assertResponseStatusCodeSame($statusCode);
@@ -389,6 +397,10 @@ public function testAsAdminUserICanCreateABook(): void
389397
'book' => 'https://openlibrary.org/books/OL28346544M.json',
390398
'condition' => BookCondition::NewCondition->value,
391399
],
400+
'headers' => [
401+
'Content-Type' => 'application/ld+json',
402+
'Accept' => 'application/ld+json',
403+
],
392404
]);
393405

394406
self::assertResponseStatusCodeSame(Response::HTTP_CREATED);
@@ -448,6 +460,10 @@ public function testAsNonAdminUserICannotUpdateBook(int $expectedCode, string $h
448460
'book' => 'https://openlibrary.org/books/OL28346544M.json',
449461
'condition' => BookCondition::NewCondition->value,
450462
],
463+
'headers' => [
464+
'Content-Type' => 'application/ld+json',
465+
'Accept' => 'application/ld+json',
466+
],
451467
]);
452468

453469
self::assertResponseStatusCodeSame($expectedCode);
@@ -473,6 +489,10 @@ public function testAsAdminUserICannotUpdateAnInvalidBook(): void
473489
'json' => [
474490
'condition' => BookCondition::DamagedCondition->value,
475491
],
492+
'headers' => [
493+
'Content-Type' => 'application/ld+json',
494+
'Accept' => 'application/ld+json',
495+
],
476496
]);
477497

478498
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
@@ -492,6 +512,10 @@ public function testAsAdminUserICannotUpdateABookWithInvalidData(array $data, in
492512
$this->client->request('PUT', '/admin/books/'.$book->getId(), [
493513
'auth_bearer' => $token,
494514
'json' => $data,
515+
'headers' => [
516+
'Content-Type' => 'application/ld+json',
517+
'Accept' => 'application/ld+json',
518+
],
495519
]);
496520

497521
self::assertResponseStatusCodeSame($statusCode);
@@ -518,12 +542,15 @@ public function testAsAdminUserICanUpdateABook(): void
518542
$this->client->request('PUT', '/admin/books/'.$book->getId(), [
519543
'auth_bearer' => $token,
520544
'json' => [
521-
/* @see https://github.com/api-platform/core/blob/main/src/Serializer/ItemNormalizer.php */
522-
'id' => '/books/'.$book->getId(),
545+
'@id' => '/books/'.$book->getId(),
523546
// Must set all data because of standard PUT
524547
'book' => 'https://openlibrary.org/books/OL28346544M.json',
525548
'condition' => BookCondition::DamagedCondition->value,
526549
],
550+
'headers' => [
551+
'Content-Type' => 'application/ld+json',
552+
'Accept' => 'application/ld+json',
553+
],
527554
]);
528555

529556
self::assertResponseStatusCodeSame(Response::HTTP_OK);

api/tests/Api/Admin/ReviewTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ public function testAsNonAdminUserICannotUpdateAReview(int $expectedCode, string
216216
'body' => 'Very good book!',
217217
'rating' => 5,
218218
],
219+
'headers' => [
220+
'Content-Type' => 'application/ld+json',
221+
'Accept' => 'application/ld+json',
222+
],
219223
]);
220224

221225
self::assertResponseStatusCodeSame($expectedCode);
@@ -240,6 +244,10 @@ public function testAsAdminUserICannotUpdateAnInvalidReview(): void
240244
'body' => 'Very good book!',
241245
'rating' => 5,
242246
],
247+
'headers' => [
248+
'Content-Type' => 'application/ld+json',
249+
'Accept' => 'application/ld+json',
250+
],
243251
]);
244252

245253
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
@@ -267,6 +275,10 @@ public function testAsAdminUserICanUpdateAReview(): void
267275
'body' => 'Very good book!',
268276
'rating' => 5,
269277
],
278+
'headers' => [
279+
'Content-Type' => 'application/ld+json',
280+
'Accept' => 'application/ld+json',
281+
],
270282
]);
271283

272284
self::assertResponseStatusCodeSame(Response::HTTP_OK);

api/tests/Api/BookmarkTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function testAsAnonymousICannotCreateABookmark(): void
8181
'json' => [
8282
'book' => '/books/'.$book->getId(),
8383
],
84+
'headers' => [
85+
'Content-Type' => 'application/ld+json',
86+
'Accept' => 'application/ld+json',
87+
],
8488
]);
8589

8690
self::assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED);
@@ -105,6 +109,10 @@ public function testAsAUserICannotCreateABookmarkWithInvalidData(): void
105109
'json' => [
106110
'book' => '/books/'.$uuid,
107111
],
112+
'headers' => [
113+
'Content-Type' => 'application/ld+json',
114+
'Accept' => 'application/ld+json',
115+
],
108116
'auth_bearer' => $token,
109117
]);
110118

@@ -149,6 +157,10 @@ public function testAsAUserICanCreateABookmark(): void
149157
'json' => [
150158
'book' => '/books/'.$book->getId(),
151159
],
160+
'headers' => [
161+
'Content-Type' => 'application/ld+json',
162+
'Accept' => 'application/ld+json',
163+
],
152164
'auth_bearer' => $token,
153165
]);
154166

@@ -190,6 +202,10 @@ public function testAsAUserICannotCreateADuplicateBookmark(): void
190202
'json' => [
191203
'book' => '/books/'.$book->getId(),
192204
],
205+
'headers' => [
206+
'Content-Type' => 'application/ld+json',
207+
'Accept' => 'application/ld+json',
208+
],
193209
'auth_bearer' => $token,
194210
]);
195211

api/tests/Api/ReviewTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ public function testAsAnonymousICannotAddAReviewOnABook(): void
137137
'body' => 'Very good book!',
138138
'rating' => 5,
139139
],
140+
'headers' => [
141+
'Content-Type' => 'application/ld+json',
142+
'Accept' => 'application/ld+json',
143+
],
140144
]);
141145

142146
self::assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED);
@@ -163,6 +167,10 @@ public function testAsAUserICannotAddAReviewOnABookWithInvalidData(array $data,
163167
$this->client->request('POST', '/books/'.$book->getId().'/reviews', [
164168
'auth_bearer' => $token,
165169
'json' => $data,
170+
'headers' => [
171+
'Content-Type' => 'application/ld+json',
172+
'Accept' => 'application/ld+json',
173+
],
166174
]);
167175

168176
self::assertResponseStatusCodeSame($statusCode);
@@ -209,6 +217,10 @@ public function testAsAUserICannotAddAReviewWithValidDataOnAnInvalidBook(): void
209217
'body' => 'Very good book!',
210218
'rating' => 5,
211219
],
220+
'headers' => [
221+
'Content-Type' => 'application/ld+json',
222+
'Accept' => 'application/ld+json',
223+
],
212224
]);
213225

214226
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
@@ -241,6 +253,10 @@ public function testAsAUserICanAddAReviewOnABook(): void
241253
'body' => 'Very good book!',
242254
'rating' => 5,
243255
],
256+
'headers' => [
257+
'Content-Type' => 'application/ld+json',
258+
'Accept' => 'application/ld+json',
259+
],
244260
]);
245261

246262
self::assertResponseStatusCodeSame(Response::HTTP_CREATED);
@@ -290,6 +306,10 @@ public function testAsAUserICannotAddADuplicateReviewOnABook(): void
290306
'body' => 'Very good book!',
291307
'rating' => 5,
292308
],
309+
'headers' => [
310+
'Content-Type' => 'application/ld+json',
311+
'Accept' => 'application/ld+json',
312+
],
293313
]);
294314

295315
self::assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);

0 commit comments

Comments
 (0)