public function EntityReferenceAdminTest::testAvailableFormatters in Drupal 9
Same name and namespace in other branches
- 8 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::testAvailableFormatters()
- 10 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest::testAvailableFormatters()
Tests the formatters for the Entity References.
File
- core/
modules/ field/ tests/ src/ Functional/ EntityReference/ EntityReferenceAdminTest.php, line 246
Class
- EntityReferenceAdminTest
- Tests for the administrative UI.
Namespace
Drupal\Tests\field\Functional\EntityReferenceCode
public function testAvailableFormatters() {
// Create a new vocabulary.
Vocabulary::create([
'vid' => 'tags',
'name' => 'tags',
])
->save();
// Create entity reference field with taxonomy term as a target.
$taxonomy_term_field_name = $this
->createEntityReferenceField('taxonomy_term', [
'tags',
]);
// Create entity reference field with user as a target.
$user_field_name = $this
->createEntityReferenceField('user');
// Create entity reference field with node as a target.
$node_field_name = $this
->createEntityReferenceField('node', [
$this->type,
]);
// Create entity reference field with date format as a target.
$date_format_field_name = $this
->createEntityReferenceField('date_format');
// Display all newly created Entity Reference configuration.
$this
->drupalGet('admin/structure/types/manage/' . $this->type . '/display');
// Check for Taxonomy Term select box values.
// Test if Taxonomy Term Entity Reference Field has the correct formatters.
$this
->assertFieldSelectOptions('fields[field_' . $taxonomy_term_field_name . '][type]', [
'entity_reference_label',
'entity_reference_entity_id',
'entity_reference_rss_category',
'entity_reference_entity_view',
]);
// Test if User Reference Field has the correct formatters.
// Author should be available for this field.
// RSS Category should not be available for this field.
$this
->assertFieldSelectOptions('fields[field_' . $user_field_name . '][type]', [
'author',
'entity_reference_entity_id',
'entity_reference_entity_view',
'entity_reference_label',
]);
// Test if Node Entity Reference Field has the correct formatters.
// RSS Category should not be available for this field.
$this
->assertFieldSelectOptions('fields[field_' . $node_field_name . '][type]', [
'entity_reference_label',
'entity_reference_entity_id',
'entity_reference_entity_view',
]);
// Test if Date Format Reference Field has the correct formatters.
// RSS Category & Entity View should not be available for this field.
// This could be any field without a ViewBuilder.
$this
->assertFieldSelectOptions('fields[field_' . $date_format_field_name . '][type]', [
'entity_reference_label',
'entity_reference_entity_id',
]);
}