You are here

public function CivicrmFieldConfigTest::testCreateField in CiviCRM Entity 8.3

Make sure that creating a field does not explode the entity storage.

File

tests/src/Kernel/CivicrmFieldConfigTest.php, line 27

Class

CivicrmFieldConfigTest
Tests the storage.

Namespace

Drupal\Tests\civicrm_entity\Kernel

Code

public function testCreateField() {

  // Create a field.
  $field_name = mb_strtolower($this
    ->randomMachineName());
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'civicrm_event',
    'type' => 'string',
  ]);
  $field_storage
    ->save();
  FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'civicrm_event',
    'label' => $this
      ->randomMachineName() . '_label',
  ])
    ->save();

  /** @var \Drupal\civicrm_entity\CiviEntityStorage $civi_entity_storage */
  $civi_entity_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('civicrm_event');
  $table_mapping = $civi_entity_storage
    ->getTableMapping();
  $db_schema = $this->container
    ->get('database')
    ->schema();
  $this
    ->assertTrue($db_schema
    ->tableExists($table_mapping
    ->getDedicatedDataTableName($field_storage)));
}