protected function TaxonomyTestBase::createTerm

Same name in this branch
  1. 9.x drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php \Drupal\taxonomy\Tests\TaxonomyTestBase::createTerm()
  2. 9.x drupal/core/modules/views/lib/Drupal/views/Tests/Taxonomy/TaxonomyTestBase.php \Drupal\views\Tests\Taxonomy\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/views/lib/Drupal/views/Tests/Taxonomy/TaxonomyTestBase.php
Sets up a Drupal site for running functional and integration tests.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Taxonomy/TaxonomyTestBase.php, line 124
Definition of Drupal\views\Tests\Taxonomy\TaxonomyTestBase.

Class

TaxonomyTestBase
Base class for all taxonomy tests.

Namespace

Drupal\views\Tests\Taxonomy

Code

protected function createTerm() {
  $term = entity_create('taxonomy_term', array(
    'name' => $this
      ->randomName(),
    'description' => $this
      ->randomName(),
    // Use the first available text format.
    'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)
      ->fetchField(),
    'vid' => $this->vocabulary->vid,
    'langcode' => LANGUAGE_NOT_SPECIFIED,
  ));
  $term
    ->save();
  return $term;
}