You are here

protected function TermTest::createEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/TermTest.php \Drupal\Tests\jsonapi\Functional\TermTest::createEntity()

Creates the entity to be tested.

Return value

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

Overrides ResourceTestBase::createEntity

File

core/modules/jsonapi/tests/src/Functional/TermTest.php, line 88

Class

TermTest
JSON:API integration test for the "Term" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

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