You are here

private function MetatagHelperTrait::createVocabulary in Metatag 8

Create a vocabulary.

Parameters

array $values: Items passed to the vocabulary. If the 'vid' item is not present it will be automatically generated. If the 'name' item is not present the 'vid' will be used.

Return value

\Drupal\taxonomy\Entity\Vocabulary A fully formatted vocabulary object.

2 calls to MetatagHelperTrait::createVocabulary()
DefaultTags::testTerm in tests/src/Functional/DefaultTags.php
Test the default values for a Term entity.
MetatagAdminTest::testListPager in tests/src/Functional/MetatagAdminTest.php
Test that metatag list page pager works as expected.

File

tests/src/Functional/MetatagHelperTrait.php, line 97

Class

MetatagHelperTrait
Misc helper functions for the automated tests.

Namespace

Drupal\Tests\metatag\Functional

Code

private function createVocabulary(array $values = []) {

  // Find a non-existent random type name.
  if (!isset($values['vid'])) {
    do {
      $id = strtolower($this
        ->randomMachineName(8));
    } while (Vocabulary::load($id));
  }
  else {
    $id = $values['vid'];
  }
  $values += [
    'vid' => $id,
    'name' => $id,
  ];
  $vocab = Vocabulary::create($values);
  $status = $vocab
    ->save();
  if ($this instanceof \PHPUnit_Framework_TestCase) {
    $this
      ->assertSame($status, SAVED_NEW, (new FormattableMarkup('Created vocabulary %type.', [
      '%type' => $vocab
        ->id(),
    ]))
      ->__toString());
  }
  else {
    self::assertEquals($status, SAVED_NEW, (new FormattableMarkup('Created vocabulary %type.', [
      '%type' => $vocab
        ->id(),
    ]))
      ->__toString());
  }
  return $vocab;
}