public function EntityReferenceAdminTest::testAvailableFormatters in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php \Drupal\field\Tests\EntityReference\EntityReferenceAdminTest::testAvailableFormatters()
Tests the formatters for the Entity References.
File
- core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceAdminTest.php, line 329 - Contains \Drupal\field\Tests\EntityReference\EntityReferenceAdminTest.
Class
- EntityReferenceAdminTest
- Tests for the administrative UI.
Namespace
Drupal\field\Tests\EntityReferenceCode
public function testAvailableFormatters() {
// Create a new vocabulary.
Vocabulary::create(array(
'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]', array(
'entity_reference_label',
'entity_reference_entity_id',
'entity_reference_rss_category',
'entity_reference_entity_view',
'hidden',
));
// 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]', array(
'author',
'entity_reference_entity_id',
'entity_reference_entity_view',
'entity_reference_label',
'hidden',
));
// 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]', array(
'entity_reference_label',
'entity_reference_entity_id',
'entity_reference_entity_view',
'hidden',
));
// 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]', array(
'entity_reference_label',
'entity_reference_entity_id',
'hidden',
));
}