You are here

protected function TermTest::createEntity in JSON:API 8.2

Same name and namespace in other branches
  1. 8 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

tests/src/Functional/TermTest.php, line 83

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