function TaxonomyTestTrait::createTerm

Same name and namespace in other branches
  1. 11.x core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait::createTerm()

Returns a new term with random properties given a vocabulary.

Parameters

\Drupal\taxonomy\VocabularyInterface $vocabulary: The vocabulary object.

array $values: (optional) An array of values to set, keyed by property name.

Return value

\Drupal\taxonomy\TermInterface The new taxonomy term object.

2 calls to TaxonomyTestTrait::createTerm()
TaxonomyDeprecationTest::testTaxonomyDeprecations in core/modules/taxonomy/tests/src/Kernel/TaxonomyDeprecationTest.php
TokenReplaceTest::testTaxonomyTokenReplacement in core/modules/taxonomy/tests/src/Functional/TokenReplaceTest.php
Creates some terms and a node, then tests the tokens generated from them.

File

core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php, line 44

Class

TaxonomyTestTrait
Provides common helper methods for Taxonomy module tests.

Namespace

Drupal\Tests\taxonomy\Traits

Code

public function createTerm(VocabularyInterface $vocabulary, $values = []) {
  $term = Term::create($values + [
    'name' => $this->randomMachineName(),
    'description' => [
      'value' => $this->randomMachineName(),
      // Use the fallback text format.
'format' => filter_fallback_format(),
    ],
    'vid' => $vocabulary->id(),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $term->save();
  return $term;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.