You are here

protected function SqlContentEntityStorageSchemaColumnTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php \Drupal\Tests\field\Kernel\Entity\Update\SqlContentEntityStorageSchemaColumnTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php, line 50

Class

SqlContentEntityStorageSchemaColumnTest
Tests that schema changes in fields with data are detected during updates.

Namespace

Drupal\Tests\field\Kernel\Entity\Update

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('entity_test_rev');
  $this
    ->installEntitySchema('user');
  $field_name = 'test';
  $this->fieldStorage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'entity_test_rev',
    'type' => 'string',
    'cardinality' => 1,
  ]);
  $this->fieldStorage
    ->save();
  $this->field = FieldConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'entity_test_rev',
    'bundle' => 'entity_test_rev',
    'required' => TRUE,
  ]);
  $this->field
    ->save();

  // Create an entity with field data.
  $this->entity = EntityTestRev::create([
    'user_id' => mt_rand(1, 10),
    'name' => $this
      ->randomMachineName(),
    $field_name => $this
      ->randomString(),
  ]);
  $this->entity
    ->save();
}