You are here

protected function TermResourceTestBase::createEntity in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::createEntity()
  2. 9 core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::createEntity()

Creates the entity to be tested.

Return value

\Drupal\Core\Entity\EntityInterface The entity to be tested.

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;
}