public function JsonApiRegressionTest::testPatchToIncludeUrlDoesNotReturnIncludeFromIssue3026030 in Drupal 10
Same name and namespace in other branches
- 8 core/modules/jsonapi/tests/src/Functional/JsonApiRegressionTest.php \Drupal\Tests\jsonapi\Functional\JsonApiRegressionTest::testPatchToIncludeUrlDoesNotReturnIncludeFromIssue3026030()
- 9 core/modules/jsonapi/tests/src/Functional/JsonApiRegressionTest.php \Drupal\Tests\jsonapi\Functional\JsonApiRegressionTest::testPatchToIncludeUrlDoesNotReturnIncludeFromIssue3026030()
Ensure includes are respected even when PATCHing.
See also
https://www.drupal.org/project/drupal/issues/3026030
File
- core/
modules/ jsonapi/ tests/ src/ Functional/ JsonApiRegressionTest.php, line 838
Class
- JsonApiRegressionTest
- JSON:API regression tests.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testPatchToIncludeUrlDoesNotReturnIncludeFromIssue3026030() {
$this
->config('jsonapi.settings')
->set('read_only', FALSE)
->save(TRUE);
// Set up data model.
$this
->drupalCreateContentType([
'type' => 'page',
]);
$this
->rebuildAll();
// Create data.
$user = $this
->drupalCreateUser([
'bypass node access',
]);
$page = Node::create([
'title' => 'original',
'type' => 'page',
'uid' => $user
->id(),
]);
$page
->save();
// Test.
$url = Url::fromUri(sprintf('internal:/jsonapi/node/page/%s/?include=uid', $page
->uuid()));
$request_options = [
RequestOptions::HEADERS => [
'Content-Type' => 'application/vnd.api+json',
'Accept' => 'application/vnd.api+json',
],
RequestOptions::AUTH => [
$user
->getAccountName(),
$user->pass_raw,
],
RequestOptions::JSON => [
'data' => [
'type' => 'node--page',
'id' => $page
->uuid(),
'attributes' => [
'title' => 'modified',
],
],
],
];
$response = $this
->request('PATCH', $url, $request_options);
$this
->assertSame(200, $response
->getStatusCode());
$doc = Json::decode((string) $response
->getBody());
$this
->assertArrayHasKey('included', $doc);
$this
->assertSame($user
->label(), $doc['included'][0]['attributes']['name']);
}