function FieldStorageCrudTest::testUpdateEntityTargetType

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testUpdateEntityTargetType()
  2. 8.9.x core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testUpdateEntityTargetType()
  3. 10 core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testUpdateEntityTargetType()

Tests changing a field storage entity type.

File

core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php, line 416

Class

FieldStorageCrudTest
Tests field storage create, read, update, and delete.

Namespace

Drupal\Tests\field\Kernel

Code

public function testUpdateEntityTargetType() : void {
    $field_storage = FieldStorageConfig::create([
        'field_name' => 'field_type',
        'entity_type' => 'entity_test',
        'type' => 'decimal',
    ]);
    $field_storage->save();
    $this->expectException(FieldException::class);
    $this->expectExceptionMessage('Cannot change the entity type for an existing field storage. The field storage foobar.field_type has the type entity_test.');
    $field_storage->set('entity_type', 'foobar');
    $field_storage->save();
}

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