You are here

public function DefaultViewsTest::createTerm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/DefaultViewsTest.php \Drupal\Tests\views\Functional\DefaultViewsTest::createTerm()

Returns a new term with random properties in vocabulary $vid.

1 call to DefaultViewsTest::createTerm()
DefaultViewsTest::setUp in core/modules/views/tests/src/Functional/DefaultViewsTest.php

File

core/modules/views/tests/src/Functional/DefaultViewsTest.php, line 167

Class

DefaultViewsTest
Tests the default views provided by views.

Namespace

Drupal\Tests\views\Functional

Code

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