function FieldStorageCrudTest::testUpdateForbid

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

Tests field type modules forbidding an update.

File

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

Class

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

Namespace

Drupal\Tests\field\Kernel

Code

public function testUpdateForbid() : void {
    $field_storage = FieldStorageConfig::create([
        'field_name' => 'forbidden',
        'entity_type' => 'entity_test',
        'type' => 'test_field',
        'settings' => [
            'changeable' => 0,
            'unchangeable' => 0,
        ],
    ]);
    $field_storage->save();
    $field_storage->setSetting('changeable', $field_storage->getSetting('changeable') + 1);
    try {
        $field_storage->save();
    } catch (FieldStorageDefinitionUpdateForbiddenException $e) {
        $this->fail('An unchangeable setting cannot be updated.');
    }
    $field_storage->setSetting('unchangeable', $field_storage->getSetting('unchangeable') + 1);
    try {
        $field_storage->save();
        $this->fail('An unchangeable setting can be updated.');
    } catch (\Exception $e) {
        $this->assertInstanceOf(FieldStorageDefinitionUpdateForbiddenException::class, $e);
    }
}

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