You are here

protected function ScannerHelperTrait::createTerm in Search and Replace Scanner 8

Create a taxonomy term.

Parameters

array $values: Items passed to the term. Requires the 'vid' element.

Return value

\Drupal\taxonomy\TermInterface|\Drupal\Core\Entity\EntityInterface A fully formatted term object.

Throws

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Functional/ScannerHelperTrait.php, line 104

Class

ScannerHelperTrait
Misc helper functions for the automated tests.

Namespace

Drupal\Tests\scanner\Functional

Code

protected function createTerm(array $values = []) {

  // Populate defaults array.
  $values += [
    'description' => [
      [
        'value' => $this
          ->randomMachineName(32),
        'format' => filter_default_format(),
      ],
    ],
    'name' => $this
      ->randomMachineName(8),
  ];
  $term = Term::create($values);
  $status = $term
    ->save();
  if ($this instanceof \PHPUnit_Framework_TestCase) {
    $this
      ->assertSame($status, SAVED_NEW, (new FormattableMarkup('Created term %name.', [
      '%name' => $term
        ->label(),
    ]))
      ->__toString());
  }
  else {
    $this
      ->assertEqual($status, SAVED_NEW, (new FormattableMarkup('Created term %name.', [
      '%name' => $term
        ->label(),
    ]))
      ->__toString());
  }
  return $term;
}