function EntityDefinitionUpdateMultipleTypesTest::testCreateFieldAndIndexOnSharedTable

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateMultipleTypesTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateMultipleTypesTest::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/EntityDefinitionUpdateMultipleTypesTest.php, line 769

Class

EntityDefinitionUpdateMultipleTypesTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testCreateFieldAndIndexOnSharedTable() : void {
  $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 (in_array(Database::getConnection()->driver(), [
    'mysql',
    'mysqli',
  ])) {
    $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.');
  }
}

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