function FieldDefinitionIntegrityTest::testFieldPluginDefinitionAvailability

Same name in other branches
  1. 9 core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php \Drupal\Tests\field\Kernel\FieldDefinitionIntegrityTest::testFieldPluginDefinitionAvailability()
  2. 8.9.x core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php \Drupal\Tests\field\Kernel\FieldDefinitionIntegrityTest::testFieldPluginDefinitionAvailability()
  3. 10 core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php \Drupal\Tests\field\Kernel\FieldDefinitionIntegrityTest::testFieldPluginDefinitionAvailability()

Tests to load field plugin definitions used in core's existing entities.

File

core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php, line 95

Class

FieldDefinitionIntegrityTest
Tests the integrity of field API plugin definitions.

Namespace

Drupal\Tests\field\Kernel

Code

public function testFieldPluginDefinitionAvailability() : void {
    $this->enableModules($this->modulesWithSubdirectory('src' . DIRECTORY_SEPARATOR . 'Entity'));
    
    /** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
    $field_formatter_manager = $this->container
        ->get('plugin.manager.field.formatter');
    
    /** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
    $field_widget_manager = $this->container
        ->get('plugin.manager.field.widget');
    
    /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
    $entity_field_manager = $this->container
        ->get('entity_field.manager');
    
    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
    $entity_type_manager = $this->container
        ->get('entity_type.manager');
    
    /** @var \Drupal\Core\Field\BaseFieldDefinition[][] $field_definitions */
    $field_definitions = [];
    
    /** @var \Drupal\Core\Entity\EntityTypeInterface[] $content_entity_types */
    $content_entity_types = array_filter($entity_type_manager->getDefinitions(), function (EntityTypeInterface $entity_type) {
        return $entity_type instanceof ContentEntityTypeInterface;
    });
    foreach ($content_entity_types as $entity_type_id => $entity_type_definition) {
        $field_definitions[$entity_type_id] = $entity_field_manager->getBaseFieldDefinitions($entity_type_id);
    }
    foreach ($field_definitions as $entity_type_id => $definitions) {
        foreach ($definitions as $field_id => $field_definition) {
            $this->checkDisplayOption($entity_type_id, $field_id, $field_definition, $field_formatter_manager, 'view');
            $this->checkDisplayOption($entity_type_id, $field_id, $field_definition, $field_widget_manager, 'form');
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.