function SqlContentEntityStorageSchemaConverterTest::testConvertToRevisionable

@covers ::convertToRevisionable

@expectedDeprecation \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter is deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::updateFieldableEntityType() instead. See https://www.drupal.org/node/3029997.

File

core/tests/Drupal/KernelTests/Core/Entity/SqlContentEntityStorageSchemaConverterTest.php, line 25

Class

SqlContentEntityStorageSchemaConverterTest
Tests the SqlContentEntityStorageSchemaConverter class.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testConvertToRevisionable() {
    $schema = \Drupal::database()->schema();
    $this->assertFalse($schema->tableExists('entity_test_new'), 'Schema for the "entity_test_new" entity type does not exist.');
    // Check that the "entity_test_new" schema has been created.
    $this->enableNewEntityType();
    $this->assertTrue($schema->tableExists('entity_test_new'), 'Schema for the "entity_test_new" entity type has been created.');
    // Update the entity type definition to revisionable.
    $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_new');
    $keys = $entity_type->getKeys();
    $keys['revision'] = 'revision_id';
    $entity_type->set('entity_keys', $keys);
    $entity_type->set('revision_table', 'entity_test_new_revision');
    $this->state
        ->set('entity_test_new.entity_type', $entity_type);
    \Drupal::entityTypeManager()->clearCachedDefinitions();
    $revisionable_schema_converter = new SqlContentEntityStorageSchemaConverter('entity_test_new', \Drupal::entityTypeManager(), \Drupal::entityDefinitionUpdateManager());
    $sandbox = [];
    $revisionable_schema_converter->convertToRevisionable($sandbox, []);
    $this->assertTrue($schema->tableExists('entity_test_new_revision'), 'Schema for the "entity_test_new" entity type has been created.');
}

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