function JsonApiRegressionTest::testBundleSpecificTargetEntityTypeFromIssue2953207

Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/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/drupal/issues/2953207

File

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

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->getAccountName(),
            $user->pass_raw,
        ],
    ]);
    $this->assertSame(200, $response->getStatusCode());
}

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