You are here

protected function TermIndexTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/TermIndexTest.php \Drupal\Tests\taxonomy\Functional\TermIndexTest::setUp()
  2. 9 core/modules/taxonomy/tests/src/Functional/TermIndexTest.php \Drupal\Tests\taxonomy\Functional\TermIndexTest::setUp()

File

core/modules/taxonomy/tests/src/Functional/TermIndexTest.php, line 49

Class

TermIndexTest
Tests the hook implementations that maintain the taxonomy index.

Namespace

Drupal\Tests\taxonomy\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Create an administrative user.
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'administer taxonomy',
    'bypass node access',
  ]));

  // Create a vocabulary and add two term reference fields to article nodes.
  $this->vocabulary = $this
    ->createVocabulary();
  $this->fieldName1 = mb_strtolower($this
    ->randomMachineName());
  $handler_settings = [
    'target_bundles' => [
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ],
    'auto_create' => TRUE,
  ];
  $this
    ->createEntityReferenceField('node', 'article', $this->fieldName1, 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->fieldName1, [
    'type' => 'options_select',
  ])
    ->save();
  $display_repository
    ->getViewDisplay('node', 'article')
    ->setComponent($this->fieldName1, [
    'type' => 'entity_reference_label',
  ])
    ->save();
  $this->fieldName2 = mb_strtolower($this
    ->randomMachineName());
  $this
    ->createEntityReferenceField('node', 'article', $this->fieldName2, 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->fieldName2, [
    'type' => 'options_select',
  ])
    ->save();
  $display_repository
    ->getViewDisplay('node', 'article')
    ->setComponent($this->fieldName2, [
    'type' => 'entity_reference_label',
  ])
    ->save();
}