You are here

public function JsonApiRegressionTest::testDeepNestedIncludeMultiTargetEntityTypeFieldFromIssue2973681 in JSON:API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Functional/JsonApiRegressionTest.php \Drupal\Tests\jsonapi\Functional\JsonApiRegressionTest::testDeepNestedIncludeMultiTargetEntityTypeFieldFromIssue2973681()

Ensure deep nested include works on multi target entity type field.

See also

https://www.drupal.org/project/jsonapi/issues/2973681

File

tests/src/Functional/JsonApiRegressionTest.php, line 85

Class

JsonApiRegressionTest
JSON:API regression tests.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testDeepNestedIncludeMultiTargetEntityTypeFieldFromIssue2973681() {

  // Set up data model.
  $this
    ->assertTrue($this->container
    ->get('module_installer')
    ->install([
    'comment',
  ], TRUE), 'Installed modules.');
  $this
    ->addDefaultCommentField('node', 'article');
  $this
    ->addDefaultCommentField('taxonomy_term', 'tags', 'comment', CommentItemInterface::OPEN, 'tcomment');
  $this
    ->drupalCreateContentType([
    'type' => 'page',
  ]);
  $this
    ->createEntityReferenceField('node', 'page', 'field_comment', NULL, 'comment', 'default', [
    'target_bundles' => [
      'comment' => 'comment',
      'tcomment' => 'tcomment',
    ],
  ], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $this
    ->rebuildAll();

  // Create data.
  $node = Node::create([
    'title' => 'test article',
    'type' => 'article',
  ]);
  $node
    ->save();
  $comment = Comment::create([
    'subject' => 'Llama',
    'entity_id' => 1,
    'entity_type' => 'node',
    'field_name' => 'comment',
  ]);
  $comment
    ->save();
  $page = Node::create([
    'title' => 'test node',
    'type' => 'page',
    'field_comment' => [
      'entity' => $comment,
    ],
  ]);
  $page
    ->save();

  // Test.
  $user = $this
    ->drupalCreateUser([
    'access content',
    'access comments',
  ]);
  $response = $this
    ->request('GET', Url::fromUri('internal:/jsonapi/node/page?include=field_comment,field_comment.entity_id,field_comment.entity_id.uid'), [
    RequestOptions::AUTH => [
      $user
        ->getUsername(),
      $user->pass_raw,
    ],
  ]);
  $this
    ->assertSame(200, $response
    ->getStatusCode());
}