public function TermTest::testGetIndividualTermWithParent in JSON:API 8
Same name and namespace in other branches
- 8.2 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
- tests/
src/ Functional/ TermTest.php, line 457
Class
- TermTest
- JSON API integration test for the "Term" content entity type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testGetIndividualTermWithParent(array $parent_term_ids) {
if (floatval(\Drupal::VERSION) < 8.6) {
$this
->markTestSkipped('The "parent" field on terms is only available for normalization in Drupal 8.6 and later.');
return;
}
// Create all possible parent terms.
Term::create([
'vid' => Vocabulary::load('camelids')
->id(),
])
->setName('Lamoids')
->save();
Term::create([
'vid' => Vocabulary::load('camelids')
->id(),
])
->setName('Wimoids')
->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/jsonapi/issues/2878463.
$url = Url::fromRoute(sprintf('jsonapi.%s.individual', static::$resourceTypeName), [
static::$entityTypeId => $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()));
}