You are here

protected function TaxonomyTestBase::createTerm in Drupal 9

Same name in this branch
  1. 9 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTestBase::createTerm()
  2. 9 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTestBase::createTerm()
Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTestBase::createTerm()
  2. 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
TaxonomyTermFilterDepthTest::setUp in core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermFilterDepthTest.php
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
TaxonomyVocabularyArgumentTest::setUp in core/modules/taxonomy/tests/src/Functional/Views/TaxonomyVocabularyArgumentTest.php

File

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

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