function TermTest::setUp

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::setUp()
  2. 8.9.x core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::setUp()
  3. 10 core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::setUp()

Overrides TaxonomyTestBase::setUp

File

core/modules/taxonomy/tests/src/Functional/TermTest.php, line 51

Class

TermTest
Tests load, save and delete for taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

protected function setUp() : void {
    parent::setUp();
    $this->drupalPlaceBlock('local_actions_block');
    $this->drupalPlaceBlock('local_tasks_block');
    $this->drupalPlaceBlock('page_title_block');
    $this->drupalLogin($this->drupalCreateUser([
        'administer taxonomy',
        'access taxonomy overview',
        'bypass node access',
    ]));
    $this->vocabulary = $this->createVocabulary();
    $field_name = 'taxonomy_' . $this->vocabulary
        ->id();
    $handler_settings = [
        'target_bundles' => [
            $this->vocabulary
                ->id() => $this->vocabulary
                ->id(),
        ],
        'auto_create' => TRUE,
    ];
    $this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $this->field = FieldConfig::loadByName('node', 'article', $field_name);
    
    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    $display_repository->getFormDisplay('node', 'article')
        ->setComponent($field_name, [
        'type' => 'options_select',
    ])
        ->save();
    $display_repository->getViewDisplay('node', 'article')
        ->setComponent($field_name, [
        'type' => 'entity_reference_label',
    ])
        ->save();
}

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