function TaxonomyTestBase::createTerm

Same name in this branch
  1. 11.x core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTestBase::createTerm()
Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTestBase::createTerm()
  2. 9 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTestBase::createTerm()
  3. 8.9.x core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTestBase::createTerm()
  4. 8.9.x core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTestBase::createTerm()
  5. 10 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTestBase::createTerm()
  6. 10 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTestBase::createTerm()

Creates and returns a taxonomy term.

Parameters

array $settings: (optional) An array of values to override the following default properties of the term:

  • name: A random string.
  • description: A random string.
  • format: First available text format.
  • vid: Vocabulary ID of self::$vocabulary object.
  • langcode: LANGCODE_NOT_SPECIFIED.

Defaults to an empty array.

Return value

\Drupal\taxonomy\Entity\Term The created taxonomy term.

5 calls to TaxonomyTestBase::createTerm()
TaxonomyTermArgumentDepthTest::setUp in core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermArgumentDepthTest.php
Sets up the test.
TaxonomyTermViewTest::testTaxonomyTermView in core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermViewTest.php
Tests that the taxonomy term view is working properly.
TaxonomyTestBase::setUp in core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php
Sets up the test.
TaxonomyVocabularyArgumentTest::setUp in core/modules/taxonomy/tests/src/Functional/Views/TaxonomyVocabularyArgumentTest.php
Sets up the test.
TermTranslationViewsTest::setUpTerms in core/modules/taxonomy/tests/src/Functional/Views/TermTranslationViewsTest.php
Setup translated terms in a hierarchy.

File

core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php, line 148

Class

TaxonomyTestBase
Base class for all taxonomy tests.

Namespace

Drupal\Tests\taxonomy\Functional\Views

Code

protected function createTerm(array $settings = []) {
    $filter_formats = filter_formats();
    $format = array_pop($filter_formats);
    $settings += [
        'name' => $this->randomMachineName(),
        'description' => $this->randomMachineName(),
        // Use the first available text format.
'format' => $format->id(),
        'vid' => $this->vocabulary
            ->id(),
        'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ];
    $term = Term::create($settings);
    $term->save();
    return $term;
}

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