You are here

protected function FarmEntityBundleFieldTest::assertFieldStorageDefinitionExists in farmOS 2.x

Helper function to check the existence of field storage definitions.

Parameters

string $entity_type: The entity type to check.

string $field_name: The field name to check.

bool $exists: If the field should exists, defaults to TRUE.

2 calls to FarmEntityBundleFieldTest::assertFieldStorageDefinitionExists()
FarmEntityBundleFieldTest::testBundleFieldPostponedInstall in modules/core/entity/tests/src/Functional/FarmEntityBundleFieldTest.php
Test installing the farm_entity_contrib_test module after farm_entity_test.
FarmEntityBundleFieldTest::testBundlePluginModuleUninstallation in modules/core/entity/tests/src/Functional/FarmEntityBundleFieldTest.php
Test that bundle fields can be reused across bundles.

File

modules/core/entity/tests/src/Functional/FarmEntityBundleFieldTest.php, line 138

Class

FarmEntityBundleFieldTest
Tests that bundle fields are created during a postponed install.

Namespace

Drupal\Tests\farm_entity\Functional

Code

protected function assertFieldStorageDefinitionExists(string $entity_type, string $field_name, bool $exists = TRUE) {
  $field_storage_definitions = $this->entityFieldManager
    ->getFieldStorageDefinitions($entity_type);

  // Test the field storage definition existence.
  $this
    ->assertEquals($exists, array_key_exists($field_name, $field_storage_definitions));

  // Test that the database table exists if the field storage definition
  // exists.
  if ($exists) {

    /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
    $table_mapping = $this->entityTypeManager
      ->getStorage($entity_type)
      ->getTableMapping();
    $table = $table_mapping
      ->getDedicatedDataTableName($field_storage_definitions[$field_name]);
    $this
      ->assertTrue($this->database
      ->schema()
      ->tableExists($table));
  }
}