You are here

public function TaxonomyTestTrait::createTerm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait::createTerm()
  2. 10 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.

36 calls to TaxonomyTestTrait::createTerm()
CommentEntityTest::testEntityChanges in core/modules/comment/tests/src/Functional/CommentEntityTest.php
Tests CSS classes on comments.
EntityReferenceFieldAttributesTest::testNodeTeaser in core/modules/rdf/tests/src/Functional/EntityReferenceFieldAttributesTest.php
Tests if file fields in teasers have correct resources.
LoadMultipleTest::testTaxonomyTermMultipleLoad in core/modules/taxonomy/tests/src/Functional/LoadMultipleTest.php
Create a vocabulary and some taxonomy terms, ensuring they're loaded correctly using entity_load_multiple().
PrepareUninstallTest::setUp in core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php
RssTest::testTaxonomyRss in core/modules/taxonomy/tests/src/Functional/RssTest.php
Tests that terms added to nodes are displayed in core RSS feed.

... See full list

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