function TaxonomyTestTrait::createTerm

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait::createTerm()
  2. 8.9.x core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php \Drupal\taxonomy\Tests\TaxonomyTestTrait::createTerm()
  3. 8.9.x core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait::createTerm()
  4. 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.

40 calls to TaxonomyTestTrait::createTerm()
CommentEntityTest::testEntityChanges in core/modules/comment/tests/src/Functional/CommentEntityTest.php
Tests CSS classes on comments.
DefaultValueWidgetTest::testDefaultValueOptionsForChangingBundles in core/modules/field_ui/tests/src/FunctionalJavascript/DefaultValueWidgetTest.php
Tests default value options on field config change.
LoadMultipleTest::testTaxonomyTermMultipleLoad in core/modules/taxonomy/tests/src/Kernel/LoadMultipleTest.php
Tests loading multiple taxonomy terms by term ID and vocabulary.
LocalTasksTest::testLocalTaskBlockUrl in core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php
Tests local task block URLs for entities with path aliases.
PrepareUninstallTest::setUp in core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php

... See full list

File

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

Class

TaxonomyTestTrait
Provides common helper methods for Taxonomy module tests.

Namespace

Drupal\Tests\taxonomy\Traits

Code

protected 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.