function TokenReplaceTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/TokenReplaceTest.php \Drupal\Tests\taxonomy\Functional\TokenReplaceTest::setUp()
  2. 8.9.x core/modules/views/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\views\Kernel\TokenReplaceTest::setUp()
  3. 8.9.x core/modules/taxonomy/tests/src/Functional/TokenReplaceTest.php \Drupal\Tests\taxonomy\Functional\TokenReplaceTest::setUp()
  4. 11.x core/modules/taxonomy/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\taxonomy\Kernel\TokenReplaceTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/taxonomy/tests/src/Kernel/TokenReplaceTest.php, line 56

Class

TokenReplaceTest
Tests taxonomy token replacement.

Namespace

Drupal\Tests\taxonomy\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this->installEntitySchema('user');
  $this->installEntitySchema('node');
  $this->installEntitySchema('taxonomy_term');
  $this->installSchema('node', 'node_access');
  $this->installConfig([
    'filter',
  ]);
  $this->installConfig([
    'taxonomy',
  ]);
  $type = NodeType::create([
    'type' => 'article',
    'name' => 'Article',
  ]);
  $type->save();
  $this->vocabulary = $this->createVocabulary();
  $this->fieldName = 'taxonomy_' . $this->vocabulary
    ->id();
  $handler_settings = [
    'target_bundles' => [
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ],
    'auto_create' => TRUE,
  ];
  $this->createEntityReferenceField('node', 'article', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
  $display_repository = \Drupal::service('entity_display.repository');
  $display_repository->getFormDisplay('node', 'article')
    ->setComponent($this->fieldName, [
    'type' => 'options_select',
  ])
    ->save();
  $display_repository->getViewDisplay('node', 'article')
    ->setComponent($this->fieldName, [
    'type' => 'entity_reference_label',
  ])
    ->save();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.