You are here

public function EntityDefinitionUpdateTest::testCreateFieldAndIndexOnSharedTable in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php \Drupal\system\Tests\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/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php, line 713
Contains \Drupal\system\Tests\Entity\EntityDefinitionUpdateTest.

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\system\Tests\Entity

Code

public function testCreateFieldAndIndexOnSharedTable() {
  $this
    ->addBaseField();
  $this
    ->addBaseFieldIndex();
  $this->entityDefinitionUpdateManager
    ->applyUpdates();
  $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
      ->assertEqual(191, $result->Sub_part, 'The index length has been restricted to 191 characters for UTF8MB4 compatibility.');
  }
}