function TermResourceTestBase::testGetTermWithParent

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::testGetTermWithParent()
  2. 8.9.x core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::testGetTermWithParent()
  3. 10 core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::testGetTermWithParent()

Tests GETting a term with a parent term other than the default <root> (0).

@dataProvider providerTestGetTermWithParent

See also

::getExpectedNormalizedEntity()

File

core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php, line 335

Class

TermResourceTestBase

Namespace

Drupal\Tests\taxonomy\Functional\Rest

Code

public function testGetTermWithParent(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();
    $this->initAuthentication();
    $url = $this->getEntityResourceUrl();
    $url->setOption('query', [
        '_format' => static::$format,
    ]);
    $request_options = $this->getAuthenticationRequestOptions('GET');
    $this->provisionEntityResource();
    $this->setUpAuthorization('GET');
    $response = $this->request('GET', $url, $request_options);
    $expected = $this->getExpectedNormalizedEntity();
    static::recursiveKSort($expected);
    $actual = $this->serializer
        ->decode((string) $response->getBody(), static::$format);
    static::recursiveKSort($actual);
    $this->assertSame($expected, $actual);
}

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