function TermTest::testGetIndividualTermWithParent
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/TermTest.php \Drupal\Tests\jsonapi\Functional\TermTest::testGetIndividualTermWithParent()
- 8.9.x core/modules/jsonapi/tests/src/Functional/TermTest.php \Drupal\Tests\jsonapi\Functional\TermTest::testGetIndividualTermWithParent()
- 11.x core/modules/jsonapi/tests/src/Functional/TermTest.php \Drupal\Tests\jsonapi\Functional\TermTest::testGetIndividualTermWithParent()
Tests GETting a term with a parent term other than the default <root> (0).
@dataProvider providerTestGetIndividualTermWithParent
See also
::getExpectedNormalizedEntity()
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ TermTest.php, line 463
Class
- TermTest
- JSON:API integration test for the "Term" content entity type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testGetIndividualTermWithParent(array $parent_term_ids) : void {
// Create all possible parent terms.
Term::create([
'vid' => Vocabulary::load('camelids')->id(),
])
->setName('Lamoids')
->save();
Term::create([
'vid' => Vocabulary::load('camelids')->id(),
])
->setName('Camels')
->save();
// Modify the entity under test to use the provided parent terms.
$this->entity
->set('parent', $parent_term_ids)
->save();
// @todo Remove line below in favor of commented line in https://www.drupal.org/project/drupal/issues/2878463.
$url = Url::fromRoute(sprintf('jsonapi.%s.individual', static::$resourceTypeName), [
'entity' => $this->entity
->uuid(),
]);
// $url = $this->entity->toUrl('jsonapi');
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$request_options = NestedArray::mergeDeep($request_options, $this->getAuthenticationRequestOptions());
$this->setUpAuthorization('GET');
$response = $this->request('GET', $url, $request_options);
$this->assertSameDocument($this->getExpectedDocument(), Json::decode($response->getBody()));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.