function TaxonomyTestTrait::createVocabulary

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

Returns a new vocabulary with random properties.

Parameters

array $values: (optional) Default values for the Vocabulary::create() method.

Return value

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

46 calls to TaxonomyTestTrait::createVocabulary()
AddModerationConfigActionTest::testAddEntityTypeAndBundle in core/modules/content_moderation/tests/src/Kernel/ConfigAction/AddModerationConfigActionTest.php
CommentEntityTest::setUp in core/modules/comment/tests/src/Functional/CommentEntityTest.php
ContentImportTest::setUp in core/tests/Drupal/FunctionalTests/DefaultContent/ContentImportTest.php
DefaultValueWidgetTest::testDefaultValueOptionsForChangingBundles in core/modules/field_ui/tests/src/FunctionalJavascript/DefaultValueWidgetTest.php
Tests default value options on field config change.
LoadMultipleTest::testTaxonomyTermMultipleLoad in core/modules/taxonomy/tests/src/Kernel/LoadMultipleTest.php
Tests loading multiple taxonomy terms by term ID and vocabulary.

... See full list

File

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

Class

TaxonomyTestTrait
Provides common helper methods for Taxonomy module tests.

Namespace

Drupal\Tests\taxonomy\Traits

Code

public function createVocabulary(array $values = []) {
    $values += [
        'name' => $this->randomMachineName(),
        'description' => $this->randomMachineName(),
        'vid' => $this->randomMachineName(),
        'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        'weight' => mt_rand(0, 10),
    ];
    $vocabulary = Vocabulary::create($values);
    $vocabulary->save();
    return $vocabulary;
}

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