You are here

public function JsonApiRegressionTest::testPostToIncludeUrlDoesNotReturnIncludeFromIssue3026030 in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/JsonApiRegressionTest.php \Drupal\Tests\jsonapi\Functional\JsonApiRegressionTest::testPostToIncludeUrlDoesNotReturnIncludeFromIssue3026030()
  2. 10 core/modules/jsonapi/tests/src/Functional/JsonApiRegressionTest.php \Drupal\Tests\jsonapi\Functional\JsonApiRegressionTest::testPostToIncludeUrlDoesNotReturnIncludeFromIssue3026030()

Ensure includes are respected even when POSTing.

See also

https://www.drupal.org/project/drupal/issues/3026030

File

core/modules/jsonapi/tests/src/Functional/JsonApiRegressionTest.php, line 796

Class

JsonApiRegressionTest
JSON:API regression tests.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testPostToIncludeUrlDoesNotReturnIncludeFromIssue3026030() {
  $this
    ->config('jsonapi.settings')
    ->set('read_only', FALSE)
    ->save(TRUE);

  // Set up data model.
  $this
    ->drupalCreateContentType([
    'type' => 'page',
  ]);
  $this
    ->rebuildAll();

  // Test.
  $user = $this
    ->drupalCreateUser([
    'bypass node access',
  ]);
  $url = Url::fromUri('internal:/jsonapi/node/page?include=uid');
  $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',
        'attributes' => [
          'title' => 'test',
        ],
      ],
    ],
  ];
  $response = $this
    ->request('POST', $url, $request_options);
  $this
    ->assertSame(201, $response
    ->getStatusCode());
  $doc = Json::decode((string) $response
    ->getBody());
  $this
    ->assertArrayHasKey('included', $doc);
  $this
    ->assertSame($user
    ->label(), $doc['included'][0]['attributes']['name']);
}