function TaxonomyTestTrait::createTerm in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php \Drupal\taxonomy\Tests\TaxonomyTestTrait::createTerm()
Returns a new term with random properties in vocabulary $vid.
Parameters
\Drupal\taxonomy\Entity\Vocabulary $vocabulary: The vocabulary object.
array $values: (optional) An array of values to set, keyed by property name. If the entity type has bundles, the bundle key has to be specified.
Return value
\Drupal\taxonomy\Entity\Term The new taxonomy term object.
26 calls to TaxonomyTestTrait::createTerm()
- EfqTest::testTaxonomyEfq in core/
modules/ taxonomy/ src/ Tests/ EfqTest.php - Tests that a basic taxonomy entity query works.
- EntityReferenceFieldAttributesTest::testNodeTeaser in core/
modules/ rdf/ src/ Tests/ EntityReferenceFieldAttributesTest.php - Tests if file fields in teasers have correct resources.
- LoadMultipleTest::testTaxonomyTermMultipleLoad in core/
modules/ taxonomy/ src/ Tests/ LoadMultipleTest.php - Create a vocabulary and some taxonomy terms, ensuring they're loaded correctly using entity_load_multiple().
- RssTest::testTaxonomyRss in core/
modules/ taxonomy/ src/ Tests/ RssTest.php - Tests that terms added to nodes are displayed in core RSS feed.
- TaxonomyAttributesTest::testTaxonomyTermRdfaAttributes in core/
modules/ rdf/ src/ Tests/ TaxonomyAttributesTest.php - Creates a random term and ensures the RDF output is correct.
File
- core/
modules/ taxonomy/ src/ Tests/ TaxonomyTestTrait.php, line 47 - Contains \Drupal\taxonomy\Tests\TaxonomyTestTrait.
Class
- TaxonomyTestTrait
- Provides common helper methods for Taxonomy module tests.
Namespace
Drupal\taxonomy\TestsCode
function createTerm(Vocabulary $vocabulary, $values = array()) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', $values + array(
'name' => $this
->randomMachineName(),
'description' => array(
'value' => $this
->randomMachineName(),
// Use the first available text format.
'format' => $format
->id(),
),
'vid' => $vocabulary
->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$term
->save();
return $term;
}