You are here

public function MetatagTestBase::createTerm in Metatag 7

Returns a new taxonomy term in a specific vocabulary.

Parameters

object $vocabulary: The vocabulary to add the term to.

string $term_name: The name to use for the new vocabulary. If none is provided one will be generated randomly.

Return value

object A taxonomy term object.

File

tests/MetatagTestBase.test, line 191
A base class for the Metatag tests, provides shared methods.

Class

MetatagTestBase
A base class for the Metatag tests, provides shared methods.

Code

public function createTerm($vocabulary, $term_name = NULL) {
  if (empty($term_name)) {
    $term_name = $this
      ->randomName();
  }

  // Create an object to save.
  $term = new stdClass();
  $term->name = $term_name;
  $term->description = $term_name;

  // Use the first available text format.
  $term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)
    ->fetchField();
  $term->vid = $vocabulary->vid;

  // Save the term.
  taxonomy_term_save($term);
  return $term;
}