public function EntityDefinitionUpdateTest::testCreateFieldAndIndexOnSharedTable in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateTest::testCreateFieldAndIndexOnSharedTable()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateTest::testCreateFieldAndIndexOnSharedTable()
Ensures that a new field and index on a shared table are created.
See also
Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::createSharedTableSchema
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDefinitionUpdateTest.php, line 1087
Class
- EntityDefinitionUpdateTest
- Tests EntityDefinitionUpdateManager functionality.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testCreateFieldAndIndexOnSharedTable() {
$this
->addBaseField();
$this
->addBaseFieldIndex();
$this
->applyEntityUpdates();
$this
->assertTrue($this->database
->schema()
->fieldExists('entity_test_update', 'new_base_field'), "New field 'new_base_field' has been created on the 'entity_test_update' table.");
$this
->assertTrue($this->database
->schema()
->indexExists('entity_test_update', 'entity_test_update_field__new_base_field'), "New index 'entity_test_update_field__new_base_field' has been created on the 'entity_test_update' table.");
// Check index size in for MySQL.
if (Database::getConnection()
->driver() == 'mysql') {
$result = Database::getConnection()
->query('SHOW INDEX FROM {entity_test_update} WHERE key_name = \'entity_test_update_field__new_base_field\' and column_name = \'new_base_field\'')
->fetchObject();
$this
->assertEquals(191, $result->Sub_part, 'The index length has been restricted to 191 characters for UTF8MB4 compatibility.');
}
}