function DefaultViewsTest::createTerm

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/DefaultViewsTest.php \Drupal\Tests\views\Functional\DefaultViewsTest::createTerm()
  2. 8.9.x core/modules/views/tests/src/Functional/DefaultViewsTest.php \Drupal\Tests\views\Functional\DefaultViewsTest::createTerm()
  3. 10 core/modules/views/tests/src/Functional/DefaultViewsTest.php \Drupal\Tests\views\Functional\DefaultViewsTest::createTerm()

Returns a new term with random properties in vocabulary $vid.

1 call to DefaultViewsTest::createTerm()
DefaultViewsTest::setUp in core/modules/views/tests/src/Functional/DefaultViewsTest.php
Sets up the test.

File

core/modules/views/tests/src/Functional/DefaultViewsTest.php, line 170

Class

DefaultViewsTest
Tests the default views provided by views.

Namespace

Drupal\Tests\views\Functional

Code

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

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