function FieldableEntityDefinitionUpdateTest::setUp

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\FieldableEntityDefinitionUpdateTest::setUp()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\FieldableEntityDefinitionUpdateTest::setUp()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\FieldableEntityDefinitionUpdateTest::setUp()

Overrides EntityKernelTestBase::setUp

File

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

Class

FieldableEntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager's fieldable entity update functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function setUp() : void {
    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);
}

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