You are here

protected function TaxonomyTestBase::createTerm in Drupal 8

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

3 calls to TaxonomyTestBase::createTerm()
ArgumentTransformTermTest::testTermArgumentTransformation in core/modules/taxonomy/tests/src/Kernel/Views/ArgumentTransformTermTest.php
Tests term argument transformation of hyphens and spaces.
ArgumentValidatorTermTest::setUp in core/modules/taxonomy/tests/src/Kernel/Views/ArgumentValidatorTermTest.php
TaxonomyTestBase::setUp in core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php

File

core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php, line 171

Class

TaxonomyTestBase
Base class for views kernel taxonomy tests.

Namespace

Drupal\Tests\taxonomy\Kernel\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;
}