You are here

public function MetatagTestBase::createVocabulary in Metatag 7

Returns a new vocabulary with random properties.

Parameters

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

string $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.

2 calls to MetatagTestBase::createVocabulary()
MetatagCoreTermTest::testEntityCreationWorkflow in tests/MetatagCoreTermTest.test
Tests creation of a standard entity.
MetatagCoreWithViewsTest::testTermViews in tests/MetatagCoreWithViewsTest.test
Test the taxonomy term page still works when displayed via Views.

File

tests/MetatagTestBase.test, line 156
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 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;
}