You are here

public function TaxonomyTestTrait::createVocabulary in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait::createVocabulary()
  2. 9 core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait::createVocabulary()

Returns a new vocabulary with random properties.

Return value

\Drupal\taxonomy\VocabularyInterface A vocabulary used for testing.

4 calls to TaxonomyTestTrait::createVocabulary()
PrepareUninstallTest::setUp in core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php
TaxonomyFieldTidTest::setUp in core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldTidTest.php
TaxonomyFieldVidTest::setUp in core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldVidTest.php
TermContextTest::testGetRuntimeContexts in core/modules/taxonomy/tests/src/Kernel/ContextProvider/TermContextTest.php
@covers ::getRuntimeContexts

File

core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php, line 21

Class

TaxonomyTestTrait
Provides common helper methods for Taxonomy module tests.

Namespace

Drupal\Tests\taxonomy\Traits

Code

public function createVocabulary() {
  $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;
}