protected function TaxonomyTestBase::createTerm

Same name in this branch
  1. 8.x drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php \Drupal\taxonomy\Tests\TaxonomyTestBase::createTerm()
  2. 8.x drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php \Drupal\taxonomy\Tests\Views\TaxonomyTestBase::createTerm()

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

Return value

Drupal\taxonomy\Term The created taxonomy term.

1 call to TaxonomyTestBase::createTerm()
TaxonomyTestBase::setUp in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php
Sets up a Drupal site for running functional and integration tests.

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php, line 134
Contains \Drupal\taxonomy\Tests\Views\TaxonomyTestBase.

Class

TaxonomyTestBase
Base class for all taxonomy tests.

Namespace

Drupal\taxonomy\Tests\Views

Code

protected function createTerm() {
  $filter_formats = filter_formats();
  $format = array_pop($filter_formats);
  $term = entity_create('taxonomy_term', array(
    'name' => $this
      ->randomName(),
    'description' => $this
      ->randomName(),
    // Use the first available text format.
    'format' => $format->format,
    'vid' => $this->vocabulary
      ->id(),
    'langcode' => Language::LANGCODE_NOT_SPECIFIED,
  ));
  $term
    ->save();
  return $term;
}