You are here

public function TaxonomyTestTrait::createVocabulary in Drupal 8

Same name in this branch
  1. 8 core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php \Drupal\taxonomy\Tests\TaxonomyTestTrait::createVocabulary()
  2. 8 core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait::createVocabulary()

Returns a new vocabulary with random properties.

File

core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php, line 22

Class

TaxonomyTestTrait
Provides common helper methods for Taxonomy module tests.

Namespace

Drupal\taxonomy\Tests

Code

public function createVocabulary() {

  // Create a vocabulary.
  $vocabulary = Vocabulary::create([
    'name' => $this
      ->randomMachineName(),
    'description' => $this
      ->randomMachineName(),
    'vid' => mb_strtolower($this
      ->randomMachineName()),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'weight' => mt_rand(0, 10),
  ]);
  $vocabulary
    ->save();
  return $vocabulary;
}