function TaxonomyTestTrait::createVocabulary

Same name and namespace in other branches
  1. 8.9.x core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php \Drupal\taxonomy\Tests\TaxonomyTestTrait::createVocabulary()
  2. 11.x core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait::createVocabulary()
  3. 10 core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait::createVocabulary()
  4. 8.9.x 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.

5 calls to TaxonomyTestTrait::createVocabulary()
TaxonomyTermIndentationTest::setUp in core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php
VocabularyPermissionsTest::testTaxonomyVocabularyOverviewPermissions in core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php
Tests the vocabulary overview permission.
VocabularyPermissionsTest::testVocabularyPermissionsTaxonomyTerm in core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php
Create, edit and delete a taxonomy term via the user interface.
VocabularyUiTest::setUp in core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php
VocabularyUiTest::testTaxonomyAdminChangingWeights in core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php
Changing weights on the vocabulary overview with two or more vocabularies.

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.