1919use Illuminate \Foundation \Testing \RefreshDatabase ;
2020use Orchestra \Testbench \Concerns \WithWorkbench ;
2121use Orchestra \Testbench \TestCase ;
22+ use Workbench \Database \Factories \Issue7648CommentFactory ;
2223
2324class ValidationTest extends TestCase
2425{
@@ -34,6 +35,7 @@ protected function defineEnvironment($app): void
3435 tap ($ app ['config ' ], static function (Repository $ config ): void {
3536 $ config ->set ('api-platform.formats ' , ['jsonld ' => ['application/ld+json ' ]]);
3637 $ config ->set ('api-platform.docs_formats ' , ['jsonld ' => ['application/ld+json ' ]]);
38+ $ config ->set ('api-platform.partial_patch_validation ' , true );
3739 });
3840 }
3941
@@ -76,6 +78,29 @@ public function testRouteWithRequirements(): void
7678 $ response ->assertStatus (200 );
7779 }
7880
81+ /**
82+ * @see https://github.com/api-platform/core/issues/7648
83+ */
84+ public function testPatchDoesNotRequireRelationshipFields (): void
85+ {
86+ $ comment = Issue7648CommentFactory::new ()->create ();
87+ $ iri = $ this ->getIriFromResource ($ comment );
88+
89+ // PATCH with empty body should not fail on 'required' for relationship fields
90+ $ response = $ this ->patchJson ($ iri , [], ['accept ' => 'application/ld+json ' , 'content-type ' => 'application/merge-patch+json ' ]);
91+ $ response ->assertStatus (200 );
92+ }
93+
94+ /**
95+ * @see https://github.com/api-platform/core/issues/7648
96+ */
97+ public function testPostStillRequiresRelationshipFields (): void
98+ {
99+ $ response = $ this ->postJson ('/api/issue7648_comments ' , ['content ' => 'test ' ], ['accept ' => 'application/ld+json ' , 'content-type ' => 'application/ld+json ' ]);
100+ $ response ->assertStatus (422 );
101+ $ response ->assertJsonFragment (['propertyPath ' => 'article ' , 'message ' => 'The article field is required. ' ]);
102+ }
103+
79104 public function testGetCollectionWithFormRequestValidation (): void
80105 {
81106 $ response = $ this ->get ('/api/slots/dropoff ' , ['accept ' => 'application/ld+json ' ]);
0 commit comments