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