You are here

protected function MultipleSelectsWidgetUiTest::setUp in Multiple Selects 8

Overrides BrowserTestBase::setUp

File

tests/src/Functional/MultipleSelectsWidgetUiTest.php, line 56

Class

MultipleSelectsWidgetUiTest
Tests the multiple select widget.

Namespace

Drupal\Tests\multiple_selects\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalCreateContentType([
    'type' => 'page',
  ]);

  // Create a new vocabulary.
  $vocabulary = Vocabulary::create([
    'vid' => 'tags',
    'name' => 'tags',
  ]);
  $vocabulary
    ->save();
  for ($i = 0; $i < 10; $i++) {
    $this->tags[] = $this
      ->createTerm($vocabulary);
  }

  // Create entity reference field with taxonomy term as a target.
  $handler_settings = [
    'target_bundles' => [
      $vocabulary
        ->id() => $vocabulary
        ->id(),
    ],
    'auto_create' => TRUE,
    'auto_create_bundle' => $vocabulary
      ->id(),
  ];
  $this
    ->createEntityReferenceField('node', 'page', 'field_tags', 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $this->container
    ->get('entity_display.repository')
    ->getFormDisplay('node', 'page')
    ->setComponent('field_tags', [
    'type' => 'multiple_options_select',
  ])
    ->save();
  $this->moduleInstaller = $this->container
    ->get('module_installer');
}