You are here

protected function TokenReplaceTest::setUp in Drupal 8

Same name in this branch
  1. 8 core/modules/views/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\views\Kernel\TokenReplaceTest::setUp()
  2. 8 core/modules/taxonomy/tests/src/Functional/TokenReplaceTest.php \Drupal\Tests\taxonomy\Functional\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()

Overrides TaxonomyTestBase::setUp

File

core/modules/taxonomy/tests/src/Functional/TokenReplaceTest.php, line 36

Class

TokenReplaceTest
Generates text using placeholders for dummy content to check taxonomy token replacement.

Namespace

Drupal\Tests\taxonomy\Functional

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'administer taxonomy',
    'bypass node access',
  ]));
  $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();
}