protected function TermAutocompleteTest::setUp in Drupal 10
Same name and namespace in other branches
- 8 core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php \Drupal\Tests\taxonomy\Functional\TermAutocompleteTest::setUp()
- 9 core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php \Drupal\Tests\taxonomy\Functional\TermAutocompleteTest::setUp()
File
- core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php, line 69
Class
- TermAutocompleteTest
- Tests the autocomplete implementation of the taxonomy class.
Namespace
Drupal\Tests\taxonomy\Functional
Code
protected function setUp() : void {
parent::setUp();
$this->vocabulary = $this
->createVocabulary();
$termNames = [
'aaa 20 bbb',
'aaa 70 bbb',
'aaa 10 bbb',
'aaa 12 bbb',
'aaa 40 bbb',
'aaa 11 bbb',
'aaa 30 bbb',
'aaa 50 bbb',
'aaa 80',
'aaa 90',
'bbb 60 aaa',
];
foreach ($termNames as $termName) {
$term = $this
->createTerm($this->vocabulary, [
'name' => $termName,
]);
$this->termIds[$termName] = $term
->id();
}
$this->fieldName = mb_strtolower($this
->randomMachineName());
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'target_type' => 'taxonomy_term',
],
])
->save();
FieldConfig::create([
'field_name' => $this->fieldName,
'bundle' => 'article',
'entity_type' => 'node',
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$this->vocabulary
->id() => $this->vocabulary
->id(),
],
],
],
])
->save();
EntityFormDisplay::load('node.article.default')
->setComponent($this->fieldName, [
'type' => 'entity_reference_autocomplete',
])
->save();
EntityViewDisplay::load('node.article.default')
->setComponent($this->fieldName, [
'type' => 'entity_reference_label',
])
->save();
$this->adminUser = $this
->drupalCreateUser([
'create article content',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('node/add/article');
$field = $this
->assertSession()
->fieldExists("{$this->fieldName}[0][target_id]");
$this->autocompleteUrl = $this
->getAbsoluteUrl($field
->getAttribute('data-autocomplete-path'));
}