You are here

public function JsonApiRegressionTest::testBundleSpecificTargetEntityTypeFromIssue2953207 in JSON:API 8

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

Ensure filtering on relationships works with bundle-specific target types.

See also

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

File

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

Class

JsonApiRegressionTest
JSON API regression tests.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testBundleSpecificTargetEntityTypeFromIssue2953207() {

  // Set up data model.
  $this
    ->assertTrue($this->container
    ->get('module_installer')
    ->install([
    'comment',
  ], TRUE), 'Installed modules.');
  $this
    ->addDefaultCommentField('taxonomy_term', 'tags', 'comment', CommentItemInterface::OPEN, 'tcomment');
  $this
    ->rebuildAll();

  // Create data.
  Term::create([
    'name' => 'foobar',
    'vid' => 'tags',
  ])
    ->save();
  Comment::create([
    'subject' => 'Llama',
    'entity_id' => 1,
    'entity_type' => 'taxonomy_term',
    'field_name' => 'comment',
  ])
    ->save();

  // Test.
  $user = $this
    ->drupalCreateUser([
    'access comments',
  ]);
  $response = $this
    ->request('GET', Url::fromUri('internal:/jsonapi/comment/tcomment?include=entity_id&filter[entity_id.name]=foobar'), [
    RequestOptions::AUTH => [
      $user
        ->getUsername(),
      $user->pass_raw,
    ],
  ]);
  $this
    ->assertSame(200, $response
    ->getStatusCode());
}