You are here

function SchemaMetatagTestHelper::createVocabulary in Schema.org Metatag 7

Returns a new vocabulary with random properties.

Parameters

$vocab_name: If empty a random string will be used.

$content_type: Any content types listed will have a Taxonomy Term reference field added that points to the new vocabulary.

Return value

object A vocabulary object.

File

tests/schema_metatag.helper.test, line 113

Class

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

Code

function createVocabulary($vocab_name = NULL, $content_type = NULL) {
  if (empty($vocab_name)) {
    $vocab_name = $this
      ->randomName();
  }

  // Create a vocabulary.
  $vocabulary = new stdClass();
  $vocabulary->name = $vocab_name;
  $vocabulary->description = $vocab_name;
  $vocabulary->machine_name = drupal_strtolower($vocab_name);
  $vocabulary->help = '';
  $vocabulary->weight = mt_rand(0, 10);
  if (!empty($content_type)) {
    $vocabulary->nodes = array(
      $content_type => $content_type,
    );
  }
  taxonomy_vocabulary_save($vocabulary);

  // Enable meta tags for this new vocabulary.
  metatag_entity_type_enable('taxonomy_term', $vocab_name, TRUE);
  return $vocabulary;
}