function JsonApiRegressionTest::testLeakedCacheMetadataViaRdfFromIssue3053827

Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/JsonApiRegressionTest.php \Drupal\Tests\jsonapi\Functional\JsonApiRegressionTest::testLeakedCacheMetadataViaRdfFromIssue3053827()

Ensure that child comments can be retrieved via JSON:API.

File

core/modules/rdf/tests/src/Functional/Jsonapi/JsonApiRegressionTest.php, line 35

Class

JsonApiRegressionTest
JSON:API regression tests.

Namespace

Drupal\Tests\rdf\Functional\Jsonapi

Code

public function testLeakedCacheMetadataViaRdfFromIssue3053827() : void {
  $this->addDefaultCommentField('node', 'article');
  $this->rebuildAll();
  Node::create([
    'title' => 'Commented Node',
    'type' => 'article',
  ])->save();
  $default_values = [
    'entity_id' => 1,
    'entity_type' => 'node',
    'field_name' => 'comment',
    'status' => 1,
  ];
  $parent = Comment::create([
    'subject' => 'Marlin',
  ] + $default_values);
  $parent->save();
  $child = Comment::create([
    'subject' => 'Nemo',
    'pid' => $parent->id(),
  ] + $default_values);
  $child->save();
  $user = $this->drupalCreateUser([
    'access comments',
  ]);
  $request_options = [
    RequestOptions::AUTH => [
      $user->getAccountName(),
      $user->pass_raw,
    ],
  ];
  // Requesting the comment collection should succeed.
  $response = $this->request('GET', Url::fromUri('internal:/jsonapi/comment/comment'), $request_options);
  $this->assertSame(200, $response->getStatusCode());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.