You are here

function SchemaMetatagTestHelper::createTerm in Schema.org 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/schema_metatag.helper.test, line 148

Class

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

Code

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;
}