You are here

protected function TaxonomyFieldFilterTest::createTermWithProperties in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyFieldFilterTest::createTermWithProperties()
  2. 10 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyFieldFilterTest::createTermWithProperties()

Creates a taxonomy term with specified name and other properties.

Parameters

array $properties: Array of properties and field values to set.

Return value

\Drupal\taxonomy\TermInterface The created taxonomy term.

1 call to TaxonomyFieldFilterTest::createTermWithProperties()
TaxonomyFieldFilterTest::setUp in core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php

File

core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php, line 172

Class

TaxonomyFieldFilterTest
Tests taxonomy field filters with translations.

Namespace

Drupal\Tests\taxonomy\Functional\Views

Code

protected function createTermWithProperties($properties) {

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