You are here

class FieldableEntityDefinitionUpdateTest in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\FieldableEntityDefinitionUpdateTest
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\FieldableEntityDefinitionUpdateTest

Tests EntityDefinitionUpdateManager's fieldable entity update functionality.

@coversDefaultClass \Drupal\Core\Entity\EntityDefinitionUpdateManager

@group Entity

Hierarchy

Expanded class hierarchy of FieldableEntityDefinitionUpdateTest

File

core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php, line 18

Namespace

Drupal\KernelTests\Core\Entity
View source
class FieldableEntityDefinitionUpdateTest extends EntityKernelTestBase {
  use EntityDefinitionTestTrait;

  /**
   * The entity definition update manager.
   *
   * @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
   */
  protected $entityDefinitionUpdateManager;

  /**
   * The last installed schema repository service.
   *
   * @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
   */
  protected $lastInstalledSchemaRepository;

  /**
   * The key-value collection for tracking installed storage schema.
   *
   * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
   */
  protected $installedStorageSchema;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The entity field manager.
   *
   * @var \Drupal\Core\Entity\EntityFieldManagerInterface
   */
  protected $entityFieldManager;

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $database;

  /**
   * The ID of the entity type used in this test.
   *
   * @var string
   */
  protected $entityTypeId = 'entity_test_update';

  /**
   * An array of entities are created during the test.
   *
   * @var \Drupal\entity_test_update\Entity\EntityTestUpdate[]
   */
  protected $testEntities = [];

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = [
    'content_translation',
    'entity_test_update',
    'language',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->entityDefinitionUpdateManager = $this->container
      ->get('entity.definition_update_manager');
    $this->lastInstalledSchemaRepository = $this->container
      ->get('entity.last_installed_schema.repository');
    $this->installedStorageSchema = $this->container
      ->get('keyvalue')
      ->get('entity.storage_schema.sql');
    $this->entityTypeManager = $this->container
      ->get('entity_type.manager');
    $this->entityFieldManager = $this->container
      ->get('entity_field.manager');
    $this->database = $this->container
      ->get('database');

    // Add a non-revisionable bundle field to test revision field table
    // handling.
    $this
      ->addBundleField('string', FALSE, TRUE);

    // The 'changed' field type has a special behavior because it updates itself
    // automatically if any of the other field values of an entity have been
    // updated, so add it to the entity type that is being tested in order to
    // provide test coverage for this special case.
    $fields['changed'] = BaseFieldDefinition::create('changed')
      ->setLabel(t('Changed'))
      ->setDescription(t('The time that the custom block was last edited.'))
      ->setTranslatable(TRUE)
      ->setRevisionable(TRUE);
    $this->state
      ->set('entity_test_update.additional_base_field_definitions', $fields);
    $this
      ->installEntitySchema($this->entityTypeId);
    $this
      ->installEntitySchema('configurable_language');

    // Enable an additional language.
    ConfigurableLanguage::createFromLangcode('ro')
      ->save();

    // Force the update function to convert one entity at a time.
    $settings = Settings::getAll();
    $settings['entity_update_batch_size'] = 1;
    new Settings($settings);
  }

  /**
   * @covers ::updateFieldableEntityType
   * @dataProvider providerTestFieldableEntityTypeUpdates
   */
  public function testFieldableEntityTypeUpdates($initial_rev, $initial_mul, $new_rev, $new_mul, $data_migration_supported) {

    // The 'entity_test_update' entity type is neither revisionable nor
    // translatable by default, so we need to get it into the initial testing
    // state. This also covers the "no existing data" scenario for fieldable
    // entity type updates.
    if ($initial_rev || $initial_mul) {
      $entity_type = $this
        ->getUpdatedEntityTypeDefinition($initial_rev, $initial_mul);
      $field_storage_definitions = $this
        ->getUpdatedFieldStorageDefinitions($initial_rev, $initial_mul);
      $this->entityDefinitionUpdateManager
        ->updateFieldableEntityType($entity_type, $field_storage_definitions);
      $this
        ->assertEntityTypeSchema($initial_rev, $initial_mul);
    }

    // Add a few entities so we can test the data copying step.
    $this
      ->insertData($initial_rev, $initial_mul);
    $updated_entity_type = $this
      ->getUpdatedEntityTypeDefinition($new_rev, $new_mul);
    $updated_field_storage_definitions = $this
      ->getUpdatedFieldStorageDefinitions($new_rev, $new_mul);
    if (!$data_migration_supported) {
      $this
        ->expectException(EntityStorageException::class);
      $this
        ->expectExceptionMessage('Converting an entity type from revisionable to non-revisionable or from translatable to non-translatable is not supported.');
    }

    // Check that existing data can be retrieved from the storage before the
    // entity schema is updated.
    if ($data_migration_supported) {
      $this
        ->assertEntityData($initial_rev, $initial_mul);
    }

    // Enable the creation of a new base field during a fieldable entity type
    // update.
    $this->state
      ->set('entity_test_update.install_new_base_field_during_update', TRUE);

    // Simulate a batch run since we are converting the entities one by one.
    $sandbox = [];
    do {
      $this->entityDefinitionUpdateManager
        ->updateFieldableEntityType($updated_entity_type, $updated_field_storage_definitions, $sandbox);
    } while ($sandbox['#finished'] != 1);
    $this
      ->assertEntityTypeSchema($new_rev, $new_mul, TRUE);
    $this
      ->assertEntityData($initial_rev, $initial_mul);
    $change_list = $this->entityDefinitionUpdateManager
      ->getChangeList();
    $this
      ->assertArrayNotHasKey('entity_test_update', $change_list, "There are no remaining updates for the 'entity_test_update' entity type.");

    // Check that we can still save new entities after the schema has been
    // updated.
    $this
      ->insertData($new_rev, $new_mul);

    // Check that the backup tables have been kept in place.
    $this
      ->assertBackupTables();
  }

  /**
   * Data provider for testFieldableEntityTypeUpdates().
   */
  public function providerTestFieldableEntityTypeUpdates() {
    return [
      'no change' => [
        'initial_rev' => FALSE,
        'initial_mul' => FALSE,
        'new_rev' => FALSE,
        'new_mul' => FALSE,
        'data_migration_supported' => TRUE,
      ],
      'non_rev non_mul to rev non_mul' => [
        'initial_rev' => FALSE,
        'initial_mul' => FALSE,
        'new_rev' => TRUE,
        'new_mul' => FALSE,
        'data_migration_supported' => TRUE,
      ],
      'non_rev non_mul to rev mul' => [
        'initial_rev' => FALSE,
        'initial_mul' => FALSE,
        'new_rev' => TRUE,
        'new_mul' => TRUE,
        'data_migration_supported' => TRUE,
      ],
      'non_rev non_mul to non_rev mul' => [
        'initial_rev' => FALSE,
        'initial_mul' => FALSE,
        'new_rev' => FALSE,
        'new_mul' => TRUE,
        'data_migration_supported' => TRUE,
      ],
      'rev non_mul to non_rev non_mul' => [
        'initial_rev' => TRUE,
        'initial_mul' => FALSE,
        'new_rev' => FALSE,
        'new_mul' => FALSE,
        'data_migration_supported' => FALSE,
      ],
      'rev non_mul to non_rev mul' => [
        'initial_rev' => TRUE,
        'initial_mul' => FALSE,
        'new_rev' => FALSE,
        'new_mul' => TRUE,
        'data_migration_supported' => FALSE,
      ],
      'rev non_mul to rev mul' => [
        'initial_rev' => TRUE,
        'initial_mul' => FALSE,
        'new_rev' => TRUE,
        'new_mul' => TRUE,
        'data_migration_supported' => TRUE,
      ],
      'non_rev mul to non_rev non_mul' => [
        'initial_rev' => FALSE,
        'initial_mul' => TRUE,
        'new_rev' => FALSE,
        'new_mul' => FALSE,
        'data_migration_supported' => FALSE,
      ],
      'non_rev mul to rev non_mul' => [
        'initial_rev' => FALSE,
        'initial_mul' => TRUE,
        'new_rev' => TRUE,
        'new_mul' => FALSE,
        'data_migration_supported' => FALSE,
      ],
      'non_rev mul to rev mul' => [
        'initial_rev' => FALSE,
        'initial_mul' => TRUE,
        'new_rev' => TRUE,
        'new_mul' => TRUE,
        'data_migration_supported' => TRUE,
      ],
      'rev mul to non_rev non_mul' => [
        'initial_rev' => TRUE,
        'initial_mul' => TRUE,
        'new_rev' => FALSE,
        'new_mul' => FALSE,
        'data_migration_supported' => FALSE,
      ],
      'rev mul to rev non_mul' => [
        'initial_rev' => TRUE,
        'initial_mul' => TRUE,
        'new_rev' => TRUE,
        'new_mul' => FALSE,
        'data_migration_supported' => FALSE,
      ],
      'rev mul to non_rev mul' => [
        'initial_rev' => TRUE,
        'initial_mul' => TRUE,
        'new_rev' => FALSE,
        'new_mul' => TRUE,
        'data_migration_supported' => FALSE,
      ],
    ];
  }

  /**
   * Generates test entities for the 'entity_test_update' entity type.
   *
   * @param bool $revisionable
   *   Whether the entity type is revisionable or not.
   * @param bool $translatable
   *   Whether the entity type is translatable or not.
   */
  protected function insertData($revisionable, $translatable) {

    // Add three test entities in order to make the "data copy" step run at
    // least three times.

    /** @var \Drupal\Core\Entity\TranslatableRevisionableStorageInterface|\Drupal\Core\Entity\EntityStorageInterface $storage */
    $storage = $this->entityTypeManager
      ->getStorage($this->entityTypeId);
    $next_id = $storage
      ->getQuery()
      ->count()
      ->execute() + 1;

    // Create test entities with two translations and two revisions.

    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    for ($i = $next_id; $i <= $next_id + 2; $i++) {
      $entity = $storage
        ->create([
        'id' => $i,
        'type' => 'test_bundle',
        'name' => 'test entity - ' . $i . ' - en',
        'new_bundle_field' => 'bundle field - ' . $i . ' - en',
        'test_multiple_properties' => [
          'value1' => 'shared table - ' . $i . ' - value 1 - en',
          'value2' => 'shared table - ' . $i . ' - value 2 - en',
        ],
        'test_multiple_properties_multiple_values' => [
          [
            'value1' => 'dedicated table - ' . $i . ' - delta 0 - value 1 - en',
            'value2' => 'dedicated table - ' . $i . ' - delta 0 - value 2 - en',
          ],
          [
            'value1' => 'dedicated table - ' . $i . ' - delta 1 - value 1 - en',
            'value2' => 'dedicated table - ' . $i . ' - delta 1 - value 2 - en',
          ],
        ],
      ]);
      $entity
        ->save();
      if ($translatable) {
        $translation = $entity
          ->addTranslation('ro', [
          'name' => 'test entity - ' . $i . ' - ro',
          'new_bundle_field' => 'bundle field - ' . $i . ' - ro',
          'test_multiple_properties' => [
            'value1' => 'shared table - ' . $i . ' - value 1 - ro',
            'value2' => 'shared table - ' . $i . ' - value 2 - ro',
          ],
          'test_multiple_properties_multiple_values' => [
            [
              'value1' => 'dedicated table - ' . $i . ' - delta 0 - value 1 - ro',
              'value2' => 'dedicated table - ' . $i . ' - delta 0 - value 2 - ro',
            ],
            [
              'value1' => 'dedicated table - ' . $i . ' - delta 1 - value 1 - ro',
              'value2' => 'dedicated table - ' . $i . ' - delta 1 - value 2 - ro',
            ],
          ],
        ]);
        $translation
          ->save();
      }
      $this->testEntities[$entity
        ->id()] = $entity;
      if ($revisionable) {

        // Create a new pending revision.
        $revision_2 = $storage
          ->createRevision($entity, FALSE);
        $revision_2->name = 'test entity - ' . $i . ' - en - rev2';
        $revision_2->new_bundle_field = 'bundle field - ' . $i . ' - en - rev2';
        $revision_2->test_multiple_properties->value1 = 'shared table - ' . $i . ' - value 1 - en - rev2';
        $revision_2->test_multiple_properties->value2 = 'shared table - ' . $i . ' - value 2 - en - rev2';
        $revision_2->test_multiple_properties_multiple_values[0]->value1 = 'dedicated table - ' . $i . ' - delta 0 - value 1 - en - rev2';
        $revision_2->test_multiple_properties_multiple_values[0]->value2 = 'dedicated table - ' . $i . ' - delta 0 - value 2 - en - rev2';
        $revision_2->test_multiple_properties_multiple_values[1]->value1 = 'dedicated table - ' . $i . ' - delta 1 - value 1 - en - rev2';
        $revision_2->test_multiple_properties_multiple_values[1]->value2 = 'dedicated table - ' . $i . ' - delta 1 - value 2 - en - rev2';
        $revision_2
          ->save();
        if ($translatable) {
          $revision_2_translation = $storage
            ->createRevision($entity
            ->getTranslation('ro'), FALSE);
          $revision_2_translation->name = 'test entity - ' . $i . ' - ro - rev2';
          $revision_2->new_bundle_field = 'bundle field - ' . $i . ' - ro - rev2';
          $revision_2->test_multiple_properties->value1 = 'shared table - ' . $i . ' - value 1 - ro - rev2';
          $revision_2->test_multiple_properties->value2 = 'shared table - ' . $i . ' - value 2 - ro - rev2';
          $revision_2_translation->test_multiple_properties_multiple_values[0]->value1 = 'dedicated table - ' . $i . ' - delta 0 - value 1 - ro - rev2';
          $revision_2_translation->test_multiple_properties_multiple_values[0]->value2 = 'dedicated table - ' . $i . ' - delta 0 - value 2 - ro - rev2';
          $revision_2_translation->test_multiple_properties_multiple_values[1]->value1 = 'dedicated table - ' . $i . ' - delta 1 - value 1 - ro - rev2';
          $revision_2_translation->test_multiple_properties_multiple_values[1]->value2 = 'dedicated table - ' . $i . ' - delta 1 - value 2 - ro - rev2';
          $revision_2_translation
            ->save();
        }
      }
    }
  }

  /**
   * Asserts test entity data after a fieldable entity type update.
   *
   * @param bool $revisionable
   *   Whether the entity type was revisionable prior to the update.
   * @param bool $translatable
   *   Whether the entity type was translatable prior to the update.
   */
  protected function assertEntityData($revisionable, $translatable) {
    $entities = $this->entityTypeManager
      ->getStorage($this->entityTypeId)
      ->loadMultiple();
    $this
      ->assertCount(3, $entities);
    foreach ($entities as $entity_id => $entity) {

      /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
      $this
        ->assertEquals("test entity - {$entity->id()} - en", $entity
        ->label());
      $this
        ->assertEquals("bundle field - {$entity->id()} - en", $entity->new_bundle_field->value);
      $this
        ->assertEquals("shared table - {$entity->id()} - value 1 - en", $entity->test_multiple_properties->value1);
      $this
        ->assertEquals("shared table - {$entity->id()} - value 2 - en", $entity->test_multiple_properties->value2);
      $this
        ->assertEquals("dedicated table - {$entity->id()} - delta 0 - value 1 - en", $entity->test_multiple_properties_multiple_values[0]->value1);
      $this
        ->assertEquals("dedicated table - {$entity->id()} - delta 0 - value 2 - en", $entity->test_multiple_properties_multiple_values[0]->value2);
      $this
        ->assertEquals("dedicated table - {$entity->id()} - delta 1 - value 1 - en", $entity->test_multiple_properties_multiple_values[1]->value1);
      $this
        ->assertEquals("dedicated table - {$entity->id()} - delta 1 - value 2 - en", $entity->test_multiple_properties_multiple_values[1]->value2);
      if ($translatable) {
        $translation = $entity
          ->getTranslation('ro');
        $this
          ->assertEquals("test entity - {$translation->id()} - ro", $translation
          ->label());
        $this
          ->assertEquals("bundle field - {$entity->id()} - ro", $translation->new_bundle_field->value);
        $this
          ->assertEquals("shared table - {$translation->id()} - value 1 - ro", $translation->test_multiple_properties->value1);
        $this
          ->assertEquals("shared table - {$translation->id()} - value 2 - ro", $translation->test_multiple_properties->value2);
        $this
          ->assertEquals("dedicated table - {$translation->id()} - delta 0 - value 1 - ro", $translation->test_multiple_properties_multiple_values[0]->value1);
        $this
          ->assertEquals("dedicated table - {$translation->id()} - delta 0 - value 2 - ro", $translation->test_multiple_properties_multiple_values[0]->value2);
        $this
          ->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 1 - ro", $translation->test_multiple_properties_multiple_values[1]->value1);
        $this
          ->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 2 - ro", $translation->test_multiple_properties_multiple_values[1]->value2);
      }
    }
    if ($revisionable) {
      $revisions_result = $this->entityTypeManager
        ->getStorage($this->entityTypeId)
        ->getQuery()
        ->allRevisions()
        ->execute();
      $revisions = $this->entityTypeManager
        ->getStorage($this->entityTypeId)
        ->loadMultipleRevisions(array_keys($revisions_result));
      $this
        ->assertCount(6, $revisions);
      foreach ($revisions as $revision) {

        /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
        $revision_label = $revision
          ->isDefaultRevision() ? NULL : ' - rev2';
        $this
          ->assertEquals("test entity - {$revision->id()} - en{$revision_label}", $revision
          ->label());
        $this
          ->assertEquals("bundle field - {$revision->id()} - en{$revision_label}", $revision->new_bundle_field->value);
        $this
          ->assertEquals("shared table - {$revision->id()} - value 1 - en{$revision_label}", $revision->test_multiple_properties->value1);
        $this
          ->assertEquals("shared table - {$revision->id()} - value 2 - en{$revision_label}", $revision->test_multiple_properties->value2);
        $this
          ->assertEquals("dedicated table - {$revision->id()} - delta 0 - value 1 - en{$revision_label}", $revision->test_multiple_properties_multiple_values[0]->value1);
        $this
          ->assertEquals("dedicated table - {$revision->id()} - delta 0 - value 2 - en{$revision_label}", $revision->test_multiple_properties_multiple_values[0]->value2);
        $this
          ->assertEquals("dedicated table - {$revision->id()} - delta 1 - value 1 - en{$revision_label}", $revision->test_multiple_properties_multiple_values[1]->value1);
        $this
          ->assertEquals("dedicated table - {$revision->id()} - delta 1 - value 2 - en{$revision_label}", $revision->test_multiple_properties_multiple_values[1]->value2);
        if ($translatable) {
          $translation = $revision
            ->getTranslation('ro');
          $this
            ->assertEquals("test entity - {$translation->id()} - ro{$revision_label}", $translation
            ->label());
          $this
            ->assertEquals("bundle field - {$entity->id()} - ro{$revision_label}", $translation->new_bundle_field->value);
          $this
            ->assertEquals("shared table - {$revision->id()} - value 1 - ro{$revision_label}", $translation->test_multiple_properties->value1);
          $this
            ->assertEquals("shared table - {$revision->id()} - value 2 - ro{$revision_label}", $translation->test_multiple_properties->value2);
          $this
            ->assertEquals("dedicated table - {$translation->id()} - delta 0 - value 1 - ro{$revision_label}", $translation->test_multiple_properties_multiple_values[0]->value1);
          $this
            ->assertEquals("dedicated table - {$translation->id()} - delta 0 - value 2 - ro{$revision_label}", $translation->test_multiple_properties_multiple_values[0]->value2);
          $this
            ->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 1 - ro{$revision_label}", $translation->test_multiple_properties_multiple_values[1]->value1);
          $this
            ->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 2 - ro{$revision_label}", $translation->test_multiple_properties_multiple_values[1]->value2);
        }
      }
    }
  }

  /**
   * Asserts revisionable and/or translatable characteristics of an entity type.
   *
   * @param bool $revisionable
   *   Whether the entity type is revisionable or not.
   * @param bool $translatable
   *   Whether the entity type is translatable or not.
   * @param bool $new_base_field
   *   (optional) Whether a new base field was added as part of the update.
   *   Defaults to FALSE.
   */
  protected function assertEntityTypeSchema($revisionable, $translatable, $new_base_field = FALSE) {

    // Check whether the 'new_base_field' field has been installed correctly.
    $field_storage_definition = $this->entityDefinitionUpdateManager
      ->getFieldStorageDefinition('new_base_field', $this->entityTypeId);
    if ($new_base_field) {
      $this
        ->assertNotNull($field_storage_definition);
    }
    else {
      $this
        ->assertNull($field_storage_definition);
    }
    if ($revisionable && $translatable) {
      $this
        ->assertRevisionableAndTranslatable();
    }
    elseif ($revisionable) {
      $this
        ->assertRevisionable();
    }
    elseif ($translatable) {
      $this
        ->assertTranslatable();
    }
    else {
      $this
        ->assertNonRevisionableAndNonTranslatable();
    }
    $this
      ->assertBundleFieldSchema($revisionable);
  }

  /**
   * Asserts the revisionable characteristics of an entity type.
   */
  protected function assertRevisionable() {

    /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
    $entity_type = $this->entityDefinitionUpdateManager
      ->getEntityType($this->entityTypeId);
    $this
      ->assertTrue($entity_type
      ->isRevisionable());

    // Check that the required field definitions of a revisionable entity type
    // exists and are stored in the correct tables.
    $revision_key = $entity_type
      ->getKey('revision');
    $revision_default_key = $entity_type
      ->getRevisionMetadataKey('revision_default');
    $revision_field = $this->entityDefinitionUpdateManager
      ->getFieldStorageDefinition($revision_key, $entity_type
      ->id());
    $revision_default_field = $this->entityDefinitionUpdateManager
      ->getFieldStorageDefinition($revision_default_key, $entity_type
      ->id());
    $this
      ->assertNotNull($revision_field);
    $this
      ->assertNotNull($revision_default_field);
    $database_schema = $this->database
      ->schema();
    $base_table = $entity_type
      ->getBaseTable();
    $revision_table = $entity_type
      ->getRevisionTable();
    $this
      ->assertTrue($database_schema
      ->tableExists($revision_table));
    $this
      ->assertTrue($database_schema
      ->fieldExists($base_table, $revision_key));
    $this
      ->assertTrue($database_schema
      ->fieldExists($revision_table, $revision_key));
    $this
      ->assertFalse($database_schema
      ->fieldExists($base_table, $revision_default_key));
    $this
      ->assertTrue($database_schema
      ->fieldExists($revision_table, $revision_default_key));

    // Also check the revision metadata keys, if they exist.
    foreach ([
      'revision_log_message',
      'revision_user',
      'revision_created',
    ] as $key) {
      if ($revision_metadata_key = $entity_type
        ->getRevisionMetadataKey($key)) {
        $revision_metadata_field = $this->entityDefinitionUpdateManager
          ->getFieldStorageDefinition($revision_metadata_key, $entity_type
          ->id());
        $this
          ->assertNotNull($revision_metadata_field);
        $this
          ->assertFalse($database_schema
          ->fieldExists($base_table, $revision_metadata_key));
        $this
          ->assertTrue($database_schema
          ->fieldExists($revision_table, $revision_metadata_key));
      }
    }
  }

  /**
   * Asserts the translatable characteristics of an entity type.
   */
  protected function assertTranslatable() {

    /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
    $entity_type = $this->entityDefinitionUpdateManager
      ->getEntityType($this->entityTypeId);
    $this
      ->assertTrue($entity_type
      ->isTranslatable());

    // Check that the required field definitions of a translatable entity type
    // exists and are stored in the correct tables.
    $langcode_key = $entity_type
      ->getKey('langcode');
    $default_langcode_key = $entity_type
      ->getKey('default_langcode');
    $langcode_field = $this->entityDefinitionUpdateManager
      ->getFieldStorageDefinition($langcode_key, $entity_type
      ->id());
    $default_langcode_field = $this->entityDefinitionUpdateManager
      ->getFieldStorageDefinition($default_langcode_key, $entity_type
      ->id());
    $this
      ->assertNotNull($langcode_field);
    $this
      ->assertNotNull($default_langcode_field);
    $database_schema = $this->database
      ->schema();
    $base_table = $entity_type
      ->getBaseTable();
    $data_table = $entity_type
      ->getDataTable();
    $this
      ->assertTrue($database_schema
      ->tableExists($data_table));
    $this
      ->assertTrue($database_schema
      ->fieldExists($base_table, $langcode_key));
    $this
      ->assertTrue($database_schema
      ->fieldExists($data_table, $langcode_key));
    $this
      ->assertFalse($database_schema
      ->fieldExists($base_table, $default_langcode_key));
    $this
      ->assertTrue($database_schema
      ->fieldExists($data_table, $default_langcode_key));
  }

  /**
   * Asserts the revisionable / translatable characteristics of an entity type.
   */
  protected function assertRevisionableAndTranslatable() {
    $this
      ->assertRevisionable();
    $this
      ->assertTranslatable();

    // Check that the required field definitions of a revisionable and
    // translatable entity type exists and are stored in the correct tables.

    /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
    $entity_type = $this->entityDefinitionUpdateManager
      ->getEntityType($this->entityTypeId);
    $langcode_key = $entity_type
      ->getKey('langcode');
    $revision_translation_affected_key = $entity_type
      ->getKey('revision_translation_affected');
    $revision_translation_affected_field = $this->entityDefinitionUpdateManager
      ->getFieldStorageDefinition($revision_translation_affected_key, $entity_type
      ->id());
    $this
      ->assertNotNull($revision_translation_affected_field);
    $database_schema = $this->database
      ->schema();
    $base_table = $entity_type
      ->getBaseTable();
    $data_table = $entity_type
      ->getDataTable();
    $revision_table = $entity_type
      ->getRevisionTable();
    $revision_data_table = $entity_type
      ->getRevisionDataTable();
    $this
      ->assertTrue($database_schema
      ->tableExists($revision_data_table));
    $this
      ->assertTrue($database_schema
      ->fieldExists($base_table, $langcode_key));
    $this
      ->assertTrue($database_schema
      ->fieldExists($data_table, $langcode_key));
    $this
      ->assertTrue($database_schema
      ->fieldExists($revision_table, $langcode_key));
    $this
      ->assertTrue($database_schema
      ->fieldExists($revision_data_table, $langcode_key));
    $this
      ->assertFalse($database_schema
      ->fieldExists($base_table, $revision_translation_affected_key));
    $this
      ->assertFalse($database_schema
      ->fieldExists($revision_table, $revision_translation_affected_key));
    $this
      ->assertTrue($database_schema
      ->fieldExists($data_table, $revision_translation_affected_key));
    $this
      ->assertTrue($database_schema
      ->fieldExists($revision_data_table, $revision_translation_affected_key));

    // Also check the revision metadata keys, if they exist.
    foreach ([
      'revision_log_message',
      'revision_user',
      'revision_created',
    ] as $key) {
      if ($revision_metadata_key = $entity_type
        ->getRevisionMetadataKey($key)) {
        $revision_metadata_field = $this->entityDefinitionUpdateManager
          ->getFieldStorageDefinition($revision_metadata_key, $entity_type
          ->id());
        $this
          ->assertNotNull($revision_metadata_field);
        $this
          ->assertFalse($database_schema
          ->fieldExists($base_table, $revision_metadata_key));
        $this
          ->assertTrue($database_schema
          ->fieldExists($revision_table, $revision_metadata_key));
        $this
          ->assertFalse($database_schema
          ->fieldExists($data_table, $revision_metadata_key));
        $this
          ->assertFalse($database_schema
          ->fieldExists($revision_data_table, $revision_metadata_key));
      }
    }
  }

  /**
   * Asserts that an entity type is neither revisionable nor translatable.
   */
  protected function assertNonRevisionableAndNonTranslatable() {

    /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
    $entity_type = $this->entityDefinitionUpdateManager
      ->getEntityType($this->entityTypeId);
    $this
      ->assertFalse($entity_type
      ->isRevisionable());
    $this
      ->assertFalse($entity_type
      ->isTranslatable());
    $database_schema = $this->database
      ->schema();
    $this
      ->assertTrue($database_schema
      ->tableExists($entity_type
      ->getBaseTable()));
    $this
      ->assertFalse($database_schema
      ->tableExists($entity_type
      ->getDataTable()));
    $this
      ->assertFalse($database_schema
      ->tableExists($entity_type
      ->getRevisionTable()));
    $this
      ->assertFalse($database_schema
      ->tableExists($entity_type
      ->getRevisionDataTable()));
  }

  /**
   * Asserts that the bundle field schema is correct.
   *
   * @param bool $revisionable
   *   Whether the entity type is revisionable or not.
   */
  protected function assertBundleFieldSchema($revisionable) {
    $entity_type_id = 'entity_test_update';
    $field_storage_definition = $this->entityFieldManager
      ->getFieldStorageDefinitions($entity_type_id)['new_bundle_field'];
    $database_schema = $this->database
      ->schema();

    /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
    $table_mapping = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->getTableMapping();
    $this
      ->assertTrue($database_schema
      ->tableExists($table_mapping
      ->getDedicatedDataTableName($field_storage_definition)));
    if ($revisionable) {
      $this
        ->assertTrue($database_schema
        ->tableExists($table_mapping
        ->getDedicatedRevisionTableName($field_storage_definition)));
    }
  }

  /**
   * Asserts that the backup tables have been kept after a successful update.
   */
  protected function assertBackupTables() {
    $backups = \Drupal::keyValue('entity.update_backup')
      ->getAll();
    $backup = reset($backups);
    $schema = $this->database
      ->schema();
    foreach ($backup['table_mapping']
      ->getTableNames() as $table_name) {
      $this
        ->assertTrue($schema
        ->tableExists($table_name));
    }
  }

  /**
   * Tests that a failed entity schema update preserves the existing data.
   */
  public function testFieldableEntityTypeUpdatesErrorHandling() {
    $schema = $this->database
      ->schema();

    // First, convert the entity type to be translatable for better coverage and
    // insert some initial data.
    $entity_type = $this
      ->getUpdatedEntityTypeDefinition(FALSE, TRUE);
    $field_storage_definitions = $this
      ->getUpdatedFieldStorageDefinitions(FALSE, TRUE);
    $this->entityDefinitionUpdateManager
      ->updateFieldableEntityType($entity_type, $field_storage_definitions);
    $this
      ->assertEntityTypeSchema(FALSE, TRUE);
    $this
      ->insertData(FALSE, TRUE);
    $tables = $schema
      ->findTables('old_%');
    $this
      ->assertCount(4, $tables);
    foreach ($tables as $table) {
      $schema
        ->dropTable($table);
    }
    $original_entity_type = $this->lastInstalledSchemaRepository
      ->getLastInstalledDefinition('entity_test_update');
    $original_storage_definitions = $this->lastInstalledSchemaRepository
      ->getLastInstalledFieldStorageDefinitions('entity_test_update');
    $original_entity_schema_data = $this->installedStorageSchema
      ->get('entity_test_update.entity_schema_data', []);
    $original_field_schema_data = [];
    foreach ($original_storage_definitions as $storage_definition) {
      $original_field_schema_data[$storage_definition
        ->getName()] = $this->installedStorageSchema
        ->get('entity_test_update.field_schema_data.' . $storage_definition
        ->getName(), []);
    }

    // Check that entity type is not revisionable prior to running the update
    // process.
    $this
      ->assertFalse($entity_type
      ->isRevisionable());

    // Make the update throw an exception during the entity save process.
    \Drupal::state()
      ->set('entity_test_update.throw_exception', TRUE);
    $this
      ->expectException(EntityStorageException::class);
    $this
      ->expectExceptionMessage('The entity update process failed while processing the entity type entity_test_update, ID: 1.');
    try {
      $updated_entity_type = $this
        ->getUpdatedEntityTypeDefinition(TRUE, TRUE);
      $updated_field_storage_definitions = $this
        ->getUpdatedFieldStorageDefinitions(TRUE, TRUE);

      // Simulate a batch run since we are converting the entities one by one.
      $sandbox = [];
      do {
        $this->entityDefinitionUpdateManager
          ->updateFieldableEntityType($updated_entity_type, $updated_field_storage_definitions, $sandbox);
      } while ($sandbox['#finished'] != 1);
    } catch (EntityStorageException $e) {
      throw $e;
    } finally {
      $this
        ->assertSame('Peekaboo!', $e
        ->getPrevious()
        ->getMessage());

      // Check that the last installed entity type definition is kept as
      // non-revisionable.
      $new_entity_type = $this->lastInstalledSchemaRepository
        ->getLastInstalledDefinition('entity_test_update');
      $this
        ->assertFalse($new_entity_type
        ->isRevisionable(), 'The entity type is kept unchanged.');

      // Check that the last installed field storage definitions did not change by
      // looking at the 'langcode' field, which is updated automatically.
      $new_storage_definitions = $this->lastInstalledSchemaRepository
        ->getLastInstalledFieldStorageDefinitions('entity_test_update');
      $langcode_key = $original_entity_type
        ->getKey('langcode');
      $this
        ->assertEquals($original_storage_definitions[$langcode_key]
        ->isRevisionable(), $new_storage_definitions[$langcode_key]
        ->isRevisionable(), "The 'langcode' field is kept unchanged.");

      /** @var \Drupal\Core\Entity\Sql\SqlEntityStorageInterface $storage */
      $storage = $this->entityTypeManager
        ->getStorage('entity_test_update');
      $table_mapping = $storage
        ->getTableMapping();

      // Check that installed storage schema did not change.
      $new_entity_schema_data = $this->installedStorageSchema
        ->get('entity_test_update.entity_schema_data', []);
      $this
        ->assertEquals($original_entity_schema_data, $new_entity_schema_data);
      foreach ($new_storage_definitions as $storage_definition) {
        $new_field_schema_data[$storage_definition
          ->getName()] = $this->installedStorageSchema
          ->get('entity_test_update.field_schema_data.' . $storage_definition
          ->getName(), []);
      }
      $this
        ->assertEquals($original_field_schema_data, $new_field_schema_data);

      // Check that temporary tables have been removed.
      $tables = $schema
        ->findTables('tmp_%');
      $this
        ->assertCount(0, $tables);
      $current_table_names = $storage
        ->getCustomTableMapping($original_entity_type, $original_storage_definitions)
        ->getTableNames();
      foreach ($current_table_names as $table_name) {
        $this
          ->assertTrue($schema
          ->tableExists($table_name));
      }

      // Check that backup tables do not exist anymore, since they were
      // restored/renamed.
      $tables = $schema
        ->findTables('old_%');
      $this
        ->assertCount(0, $tables);

      // Check that the original tables still exist and their data is intact.
      $this
        ->assertTrue($schema
        ->tableExists('entity_test_update'));
      $this
        ->assertTrue($schema
        ->tableExists('entity_test_update_data'));

      // Check that the revision tables have not been created.
      $this
        ->assertFalse($schema
        ->tableExists('entity_test_update_revision'));
      $this
        ->assertFalse($schema
        ->tableExists('entity_test_update_revision_data'));
      $base_table_count = $this->database
        ->select('entity_test_update')
        ->countQuery()
        ->execute()
        ->fetchField();
      $this
        ->assertEquals(3, $base_table_count);
      $data_table_count = $this->database
        ->select('entity_test_update_data')
        ->countQuery()
        ->execute()
        ->fetchField();

      // There are two records for each entity, one for English and one for
      // Romanian.
      $this
        ->assertEquals(6, $data_table_count);
      $base_table_row = $this->database
        ->select('entity_test_update')
        ->fields('entity_test_update')
        ->condition('id', 1, '=')
        ->condition('langcode', 'en', '=')
        ->execute()
        ->fetchAllAssoc('id');
      $this
        ->assertEquals($this->testEntities[1]
        ->uuid(), $base_table_row[1]->uuid);
      $data_table_row = $this->database
        ->select('entity_test_update_data')
        ->fields('entity_test_update_data')
        ->condition('id', 1, '=')
        ->condition('langcode', 'en', '=')
        ->execute()
        ->fetchAllAssoc('id');
      $this
        ->assertEquals('test entity - 1 - en', $data_table_row[1]->name);
      $this
        ->assertEquals('shared table - 1 - value 1 - en', $data_table_row[1]->test_multiple_properties__value1);
      $this
        ->assertEquals('shared table - 1 - value 2 - en', $data_table_row[1]->test_multiple_properties__value2);
      $data_table_row = $this->database
        ->select('entity_test_update_data')
        ->fields('entity_test_update_data')
        ->condition('id', 1, '=')
        ->condition('langcode', 'ro', '=')
        ->execute()
        ->fetchAllAssoc('id');
      $this
        ->assertEquals('test entity - 1 - ro', $data_table_row[1]->name);
      $this
        ->assertEquals('shared table - 1 - value 1 - ro', $data_table_row[1]->test_multiple_properties__value1);
      $this
        ->assertEquals('shared table - 1 - value 2 - ro', $data_table_row[1]->test_multiple_properties__value2);
      $dedicated_table_name = $table_mapping
        ->getFieldTableName('test_multiple_properties_multiple_values');
      $dedicated_table_row = $this->database
        ->select($dedicated_table_name)
        ->fields($dedicated_table_name)
        ->condition('entity_id', 1, '=')
        ->condition('langcode', 'en', '=')
        ->execute()
        ->fetchAllAssoc('delta');
      $this
        ->assertEquals('dedicated table - 1 - delta 0 - value 1 - en', $dedicated_table_row[0]->test_multiple_properties_multiple_values_value1);
      $this
        ->assertEquals('dedicated table - 1 - delta 0 - value 2 - en', $dedicated_table_row[0]->test_multiple_properties_multiple_values_value2);
      $this
        ->assertEquals('dedicated table - 1 - delta 1 - value 1 - en', $dedicated_table_row[1]->test_multiple_properties_multiple_values_value1);
      $this
        ->assertEquals('dedicated table - 1 - delta 1 - value 2 - en', $dedicated_table_row[1]->test_multiple_properties_multiple_values_value2);
      $dedicated_table_row = $this->database
        ->select($dedicated_table_name)
        ->fields($dedicated_table_name)
        ->condition('entity_id', 1, '=')
        ->condition('langcode', 'ro', '=')
        ->execute()
        ->fetchAllAssoc('delta');
      $this
        ->assertEquals('dedicated table - 1 - delta 0 - value 1 - ro', $dedicated_table_row[0]->test_multiple_properties_multiple_values_value1);
      $this
        ->assertEquals('dedicated table - 1 - delta 0 - value 2 - ro', $dedicated_table_row[0]->test_multiple_properties_multiple_values_value2);
      $this
        ->assertEquals('dedicated table - 1 - delta 1 - value 1 - ro', $dedicated_table_row[1]->test_multiple_properties_multiple_values_value1);
      $this
        ->assertEquals('dedicated table - 1 - delta 1 - value 2 - ro', $dedicated_table_row[1]->test_multiple_properties_multiple_values_value2);
    }
  }

  /**
   * Tests the removal of the backup tables after a successful update.
   */
  public function testFieldableEntityTypeUpdatesRemoveBackupTables() {
    $schema = $this->database
      ->schema();

    // Convert the entity type to be revisionable.
    $entity_type = $this
      ->getUpdatedEntityTypeDefinition(TRUE, FALSE);
    $field_storage_definitions = $this
      ->getUpdatedFieldStorageDefinitions(TRUE, FALSE);
    $this->entityDefinitionUpdateManager
      ->updateFieldableEntityType($entity_type, $field_storage_definitions);

    // Check that backup tables are kept by default.
    $tables = $schema
      ->findTables('old_%');
    $this
      ->assertCount(4, $tables);
    foreach ($tables as $table) {
      $schema
        ->dropTable($table);
    }

    // Make the entity update process drop the backup tables after a successful
    // update.
    $settings = Settings::getAll();
    $settings['entity_update_backup'] = FALSE;
    new Settings($settings);
    $entity_type = $this
      ->getUpdatedEntityTypeDefinition(TRUE, TRUE);
    $field_storage_definitions = $this
      ->getUpdatedFieldStorageDefinitions(TRUE, TRUE);
    $this->entityDefinitionUpdateManager
      ->updateFieldableEntityType($entity_type, $field_storage_definitions);

    // Check that backup tables have been dropped.
    $tables = $schema
      ->findTables('old_%');
    $this
      ->assertCount(0, $tables);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertContentTrait::$content protected property The current raw content.
AssertContentTrait::$drupalSettings protected property The drupalSettings value from the current raw $content.
AssertContentTrait::$elements protected property The XML structure parsed from the current raw $content. 1
AssertContentTrait::$plainTextContent protected property The plain-text content of raw $content (text nodes).
AssertContentTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertContentTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertContentTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertContentTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertContentTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertContentTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertContentTrait::assertLink protected function Passes if a link with the specified label is found.
AssertContentTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertContentTrait::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
AssertContentTrait::assertNoEscaped protected function Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertNoField protected function Asserts that a field does not exist with the given name or ID.
AssertContentTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertContentTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertContentTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertContentTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertContentTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertContentTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertContentTrait::assertNoLinkByHrefInMainRegion protected function Passes if a link containing a given href is not found in the main region.
AssertContentTrait::assertNoOption protected function Asserts that a select option in the current page does not exist.
AssertContentTrait::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
AssertContentTrait::assertNoPattern protected function Triggers a pass if the perl regex pattern is not found in raw content.
AssertContentTrait::assertNoRaw protected function Passes if the raw text is NOT found on the loaded page, fail otherwise.
AssertContentTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text.
AssertContentTrait::assertNoTitle protected function Pass if the page title is not the given string.
AssertContentTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertContentTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertContentTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionSelectedWithDrupalSelector protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionWithDrupalSelector protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertContentTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise.
AssertContentTrait::assertText protected function Passes if the page (with HTML stripped) contains the text.
AssertContentTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertContentTrait::assertTextPattern protected function Asserts that a Perl regex pattern is found in the plain-text content.
AssertContentTrait::assertThemeOutput protected function Asserts themed output.
AssertContentTrait::assertTitle protected function Pass if the page title is the given string.
AssertContentTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertContentTrait::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
AssertContentTrait::buildXPathQuery protected function Builds an XPath query.
AssertContentTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertContentTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
AssertContentTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertContentTrait::getDrupalSettings protected function Gets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::getRawContent protected function Gets the current raw content.
AssertContentTrait::getSelectedItem protected function Get the selected value from a select field.
AssertContentTrait::getTextContent protected function Retrieves the plain-text content from the current raw content.
AssertContentTrait::getUrl protected function Get the current URL from the cURL handler. 1
AssertContentTrait::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
AssertContentTrait::removeWhiteSpace protected function Removes all white-space between HTML tags from the raw content.
AssertContentTrait::setDrupalSettings protected function Sets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::setRawContent protected function Sets the raw content (e.g. HTML).
AssertContentTrait::xpath protected function Performs an xpath search on the contents of the internal browser.
AssertHelperTrait::castSafeStrings protected static function Casts MarkupInterface objects into strings.
AssertLegacyTrait::assert protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::assertEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead.
AssertLegacyTrait::assertIdenticalObject protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertNotEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead.
AssertLegacyTrait::assertNotIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead.
AssertLegacyTrait::pass protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::verbose protected function
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
EntityDefinitionTestTrait::addBaseField protected function Adds a new base field to the 'entity_test_update' entity type.
EntityDefinitionTestTrait::addBaseFieldIndex protected function Adds a single-field index to the base field.
EntityDefinitionTestTrait::addBundleField protected function Adds a new bundle field to the 'entity_test_update' entity type.
EntityDefinitionTestTrait::addEntityIndex protected function Adds an index to the 'entity_test_update' entity type's base table.
EntityDefinitionTestTrait::addLongNameBaseField protected function Adds a long-named base field to the 'entity_test_update' entity type.
EntityDefinitionTestTrait::addRevisionableBaseField protected function Adds a new revisionable base field to the 'entity_test_update' entity type.
EntityDefinitionTestTrait::applyEntityUpdates protected function Applies all the detected valid changes.
EntityDefinitionTestTrait::deleteEntityType protected function Removes the entity type.
EntityDefinitionTestTrait::doEntityUpdate protected function Performs an entity type definition update.
EntityDefinitionTestTrait::doFieldUpdate protected function Performs a field storage definition update.
EntityDefinitionTestTrait::enableNewEntityType protected function Enables a new entity type definition.
EntityDefinitionTestTrait::getUpdatedEntityTypeDefinition protected function Returns an entity type definition, possibly updated to be rev or mul.
EntityDefinitionTestTrait::getUpdatedFieldStorageDefinitions protected function Returns the required rev / mul field definitions for an entity type.
EntityDefinitionTestTrait::makeBaseFieldEntityKey protected function Promotes a field to an entity key.
EntityDefinitionTestTrait::modifyBaseField protected function Modifies the new base field from 'string' to 'text'.
EntityDefinitionTestTrait::modifyBundleField protected function Modifies the new bundle field from 'string' to 'text'.
EntityDefinitionTestTrait::removeBaseField protected function Removes the new base field from the 'entity_test_update' entity type.
EntityDefinitionTestTrait::removeBaseFieldIndex protected function Removes the index added in addBaseFieldIndex().
EntityDefinitionTestTrait::removeBundleField protected function Removes the new bundle field from the 'entity_test_update' entity type.
EntityDefinitionTestTrait::removeEntityIndex protected function Removes the index added in addEntityIndex().
EntityDefinitionTestTrait::renameBaseTable protected function Renames the base table to 'entity_test_update_new'.
EntityDefinitionTestTrait::renameDataTable protected function Renames the data table to 'entity_test_update_data_new'.
EntityDefinitionTestTrait::renameRevisionBaseTable protected function Renames the revision table to 'entity_test_update_revision_new'.
EntityDefinitionTestTrait::renameRevisionDataTable protected function Renames the revision data table to 'entity_test_update_revision_data_new'.
EntityDefinitionTestTrait::resetEntityType protected function Resets the entity type definition.
EntityDefinitionTestTrait::updateEntityTypeToNotRevisionable protected function Updates the 'entity_test_update' entity type not revisionable.
EntityDefinitionTestTrait::updateEntityTypeToNotTranslatable protected function Updates the 'entity_test_update' entity type to not translatable.
EntityDefinitionTestTrait::updateEntityTypeToRevisionable protected function Updates the 'entity_test_update' entity type to revisionable.
EntityDefinitionTestTrait::updateEntityTypeToRevisionableAndTranslatable protected function Updates the 'entity_test_update' entity type to revisionable and translatable.
EntityDefinitionTestTrait::updateEntityTypeToTranslatable protected function Updates the 'entity_test_update' entity type to translatable.
EntityKernelTestBase::$deprecatedProperties protected property The list of deprecated services.
EntityKernelTestBase::$generatedIds protected property A list of generated identifiers.
EntityKernelTestBase::$state protected property The state service.
EntityKernelTestBase::createUser protected function Creates a user.
EntityKernelTestBase::generateRandomEntityId protected function Generates a random ID avoiding collisions.
EntityKernelTestBase::getHooksInfo protected function Returns the entity_test hook invocation info.
EntityKernelTestBase::installModule protected function Installs a module and refreshes services.
EntityKernelTestBase::refreshServices protected function Refresh services. 1
EntityKernelTestBase::reloadEntity protected function Reloads the given entity from the storage and returns it.
EntityKernelTestBase::uninstallModule protected function Uninstalls a module and refreshes services.
FieldableEntityDefinitionUpdateTest::$database protected property The database connection.
FieldableEntityDefinitionUpdateTest::$entityDefinitionUpdateManager protected property The entity definition update manager.
FieldableEntityDefinitionUpdateTest::$entityFieldManager protected property The entity field manager.
FieldableEntityDefinitionUpdateTest::$entityTypeId protected property The ID of the entity type used in this test.
FieldableEntityDefinitionUpdateTest::$entityTypeManager protected property The entity type manager. Overrides EntityKernelTestBase::$entityTypeManager
FieldableEntityDefinitionUpdateTest::$installedStorageSchema protected property The key-value collection for tracking installed storage schema.
FieldableEntityDefinitionUpdateTest::$lastInstalledSchemaRepository protected property The last installed schema repository service.
FieldableEntityDefinitionUpdateTest::$modules public static property Modules to enable. Overrides EntityKernelTestBase::$modules
FieldableEntityDefinitionUpdateTest::$testEntities protected property An array of entities are created during the test.
FieldableEntityDefinitionUpdateTest::assertBackupTables protected function Asserts that the backup tables have been kept after a successful update.
FieldableEntityDefinitionUpdateTest::assertBundleFieldSchema protected function Asserts that the bundle field schema is correct.
FieldableEntityDefinitionUpdateTest::assertEntityData protected function Asserts test entity data after a fieldable entity type update.
FieldableEntityDefinitionUpdateTest::assertEntityTypeSchema protected function Asserts revisionable and/or translatable characteristics of an entity type.
FieldableEntityDefinitionUpdateTest::assertNonRevisionableAndNonTranslatable protected function Asserts that an entity type is neither revisionable nor translatable.
FieldableEntityDefinitionUpdateTest::assertRevisionable protected function Asserts the revisionable characteristics of an entity type.
FieldableEntityDefinitionUpdateTest::assertRevisionableAndTranslatable protected function Asserts the revisionable / translatable characteristics of an entity type.
FieldableEntityDefinitionUpdateTest::assertTranslatable protected function Asserts the translatable characteristics of an entity type.
FieldableEntityDefinitionUpdateTest::insertData protected function Generates test entities for the 'entity_test_update' entity type.
FieldableEntityDefinitionUpdateTest::providerTestFieldableEntityTypeUpdates public function Data provider for testFieldableEntityTypeUpdates().
FieldableEntityDefinitionUpdateTest::setUp protected function Overrides EntityKernelTestBase::setUp
FieldableEntityDefinitionUpdateTest::testFieldableEntityTypeUpdates public function @covers ::updateFieldableEntityType @dataProvider providerTestFieldableEntityTypeUpdates
FieldableEntityDefinitionUpdateTest::testFieldableEntityTypeUpdatesErrorHandling public function Tests that a failed entity schema update preserves the existing data.
FieldableEntityDefinitionUpdateTest::testFieldableEntityTypeUpdatesRemoveBackupTables public function Tests the removal of the backup tables after a successful update.
KernelTestBase::$backupGlobals protected property Back up and restore any global variables that may be changed by tests.
KernelTestBase::$backupStaticAttributes protected property Back up and restore static class properties that may be changed by tests.
KernelTestBase::$backupStaticAttributesBlacklist protected property Contains a few static class properties for performance.
KernelTestBase::$classLoader protected property
KernelTestBase::$configImporter protected property @todo Move into Config test base class. 7
KernelTestBase::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
KernelTestBase::$container protected property
KernelTestBase::$databasePrefix protected property
KernelTestBase::$preserveGlobalState protected property Do not forward any global state from the parent process to the processes that run the actual tests.
KernelTestBase::$root protected property The app root.
KernelTestBase::$runTestInSeparateProcess protected property Kernel tests are run in separate processes because they allow autoloading of code from extensions. Running the test in a separate process isolates this behavior from other tests. Subclasses should not override this property.
KernelTestBase::$siteDirectory protected property
KernelTestBase::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 6
KernelTestBase::$vfsRoot protected property The virtual filesystem root directory.
KernelTestBase::assertPostConditions protected function 1
KernelTestBase::bootEnvironment protected function Bootstraps a basic test environment.
KernelTestBase::bootKernel private function Bootstraps a kernel for a test.
KernelTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
KernelTestBase::disableModules protected function Disables modules for this test.
KernelTestBase::enableModules protected function Enables modules for this test.
KernelTestBase::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
KernelTestBase::getDatabaseConnectionInfo protected function Returns the Database connection info to be used for this test. 1
KernelTestBase::getDatabasePrefix public function
KernelTestBase::getExtensionsForModules private function Returns Extension objects for $modules to enable.
KernelTestBase::getModulesToEnable private static function Returns the modules to enable for this test.
KernelTestBase::initFileCache protected function Initializes the FileCache component.
KernelTestBase::installConfig protected function Installs default configuration for a given list of modules.
KernelTestBase::installEntitySchema protected function Installs the storage schema for a specific entity type.
KernelTestBase::installSchema protected function Installs database tables from a module schema definition.
KernelTestBase::isTestInIsolation Deprecated protected function Returns whether the current test method is running in a separate process.
KernelTestBase::prepareTemplate protected function
KernelTestBase::register public function Registers test-specific services. Overrides ServiceProviderInterface::register 26
KernelTestBase::render protected function Renders a render array. 1
KernelTestBase::setInstallProfile protected function Sets the install profile and rebuilds the container to update it.
KernelTestBase::setSetting protected function Sets an in-memory Settings variable.
KernelTestBase::setUpBeforeClass public static function 1
KernelTestBase::setUpFilesystem protected function Sets up the filesystem, so things like the file directory. 2
KernelTestBase::stop protected function Stops test execution.
KernelTestBase::tearDown protected function 6
KernelTestBase::tearDownCloseDatabaseConnection public function @after
KernelTestBase::vfsDump protected function Dumps the current state of the virtual filesystem to STDOUT.
KernelTestBase::__sleep public function Prevents serializing any properties.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case. 1
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.
UserCreationTrait::checkPermissions protected function Checks whether a given list of permission names is valid. Aliased as: drupalCheckPermissions
UserCreationTrait::createAdminRole protected function Creates an administrative role. Aliased as: drupalCreateAdminRole
UserCreationTrait::createRole protected function Creates a role with specified permissions. Aliased as: drupalCreateRole
UserCreationTrait::createUser protected function Create a user with a given set of permissions. Aliased as: drupalCreateUser
UserCreationTrait::grantPermissions protected function Grant permissions to a user role. Aliased as: drupalGrantPermissions
UserCreationTrait::setCurrentUser protected function Switch the current logged in user. Aliased as: drupalSetCurrentUser
UserCreationTrait::setUpCurrentUser protected function Creates a random user account and sets it as current user. Aliased as: drupalSetUpCurrentUser