You are here

protected function QuickEditAutocompleteTermTest::setUp in Drupal 10

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

File

core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditAutocompleteTermTest.php, line 84

Class

QuickEditAutocompleteTermTest
Tests in-place editing of autocomplete tags.

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->drupalCreateContentType([
    'type' => 'article',
  ]);
  $this->vocabulary = Vocabulary::create([
    'name' => 'quickedit testing tags',
    'vid' => 'quickedit_testing_tags',
  ]);
  $this->vocabulary
    ->save();
  $this->fieldName = 'field_' . $this->vocabulary
    ->id();
  $handler_settings = [
    'target_bundles' => [
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ],
    'auto_create' => TRUE,
  ];
  $this
    ->createEntityReferenceField('node', 'article', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  \Drupal::service('entity_display.repository')
    ->getFormDisplay('node', 'article')
    ->setComponent($this->fieldName, [
    'type' => 'entity_reference_autocomplete_tags',
    'weight' => -4,
  ])
    ->save();
  \Drupal::service('entity_display.repository')
    ->getViewDisplay('node', 'article')
    ->setComponent($this->fieldName, [
    'type' => 'entity_reference_label',
    'weight' => 10,
  ])
    ->save();
  \Drupal::service('entity_display.repository')
    ->getViewDisplay('node', 'article', 'teaser')
    ->setComponent($this->fieldName, [
    'type' => 'entity_reference_label',
    'weight' => 10,
  ])
    ->save();
  $this->term1 = $this
    ->createTerm();
  $this->term2 = $this
    ->createTerm();
  $node = [];
  $node['type'] = 'article';
  $node[$this->fieldName][]['target_id'] = $this->term1
    ->id();
  $node[$this->fieldName][]['target_id'] = $this->term2
    ->id();
  $this->node = $this
    ->drupalCreateNode($node);
  $this->editorUser = $this
    ->drupalCreateUser([
    'access content',
    'create article content',
    'edit any article content',
    'administer nodes',
    'access contextual links',
    'access in-place editing',
  ]);
}