function TermResourceTestBase::createEntity

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

Overrides EntityResourceTestBase::createEntity

File

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

Class

TermResourceTestBase

Namespace

Drupal\Tests\taxonomy\Functional\Rest

Code

protected function createEntity() {
    $vocabulary = Vocabulary::load('camelids');
    if (!$vocabulary) {
        // Create a "Camelids" vocabulary.
        $vocabulary = Vocabulary::create([
            'name' => 'Camelids',
            'vid' => 'camelids',
        ]);
        $vocabulary->save();
    }
    // Create a "Llama" taxonomy term.
    $term = Term::create([
        'vid' => $vocabulary->id(),
    ])
        ->setName('Llama')
        ->setDescription("It is a little known fact that llamas cannot count higher than seven.")
        ->setChangedTime(123456789)
        ->set('path', '/llama');
    $term->save();
    return $term;
}

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