function TaxonomyTestBase::createTerm

Same name in this branch

Returns a new term with random properties in vocabulary $vid.

21 calls to TaxonomyTestBase::createTerm()

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php, line 54
Definition of Drupal\taxonomy\Tests\TaxonomyTestBase.

Class

TaxonomyTestBase
Provides common helper methods for Taxonomy module tests.

Namespace

Drupal\taxonomy\Tests

Code

function createTerm($vocabulary) {
  $term = entity_create('taxonomy_term', array(
    'name' => $this
      ->randomName(),
    'description' => $this
      ->randomName(),
    // Use the first available text format.
    'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)
      ->fetchField(),
    'vid' => $vocabulary->vid,
    'langcode' => LANGUAGE_NOT_SPECIFIED,
  ));
  taxonomy_term_save($term);
  return $term;
}