You are here

function TagadelicServiceTest::createTerm in Tagadelic 8.3

Creates and returns a taxonomy term.

Parameters

object $vocabulary: The vocabulary for the returned taxonomy term

Return value

\Drupal\taxonomy\Entity\Term The created taxonomy term.

1 call to TagadelicServiceTest::createTerm()
TagadelicServiceTest::testTagadelicService in src/Tests/TagadelicServiceTest.php
Test block placement.

File

src/Tests/TagadelicServiceTest.php, line 173

Class

TagadelicServiceTest
Tests for tagadelic service.

Namespace

Drupal\tagadelic\Tests

Code

function createTerm($vocabulary) {
  $filter_formats = filter_formats();
  $format = array_pop($filter_formats);
  $term = Term::create(array(
    'name' => $this
      ->randomMachineName(),
    'description' => array(
      'value' => $this
        ->randomMachineName(),
      // Use the first available text format.
      'format' => $format
        ->id(),
    ),
    'vid' => $vocabulary
      ->id(),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ));
  $term
    ->save();
  return $term;
}