You are here

public function FieldTypePluginManagerTest::testMainProperty in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php \Drupal\Tests\field\Kernel\FieldTypePluginManagerTest::testMainProperty()
  2. 9 core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php \Drupal\Tests\field\Kernel\FieldTypePluginManagerTest::testMainProperty()

Tests all field items provide an existing main property.

File

core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php, line 91

Class

FieldTypePluginManagerTest
Tests the field type manager.

Namespace

Drupal\Tests\field\Kernel

Code

public function testMainProperty() {

  // Let's enable all Drupal modules in Drupal core, so we test any field
  // type plugin.
  $this
    ->enableAllCoreModules();

  /** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager */
  $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
  foreach ($field_type_manager
    ->getDefinitions() as $plugin_id => $definition) {
    $class = $definition['class'];
    $property = $class::mainPropertyName();
    if ($property === NULL) {
      continue;
    }
    $storage_definition = BaseFieldDefinition::create($plugin_id);
    $property_definitions = $class::propertyDefinitions($storage_definition);
    $properties = implode(', ', array_keys($property_definitions));
    if (!empty($property_definitions)) {
      $message = sprintf("%s property %s found in %s", $plugin_id, $property, $properties);
      $this
        ->assertArrayHasKey($property, $class::propertyDefinitions($storage_definition), $message);
    }
  }
}