You are here

function FieldStorageCrudTest::testUpdateForbid in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/FieldStorageCrudTest.php \Drupal\field\Tests\FieldStorageCrudTest::testUpdateForbid()

Test field type modules forbidding an update.

File

core/modules/field/src/Tests/FieldStorageCrudTest.php, line 433
Contains \Drupal\field\Tests\FieldStorageCrudTest.

Class

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

Namespace

Drupal\field\Tests

Code

function testUpdateForbid() {
  $field_storage = entity_create('field_storage_config', array(
    'field_name' => 'forbidden',
    'entity_type' => 'entity_test',
    'type' => 'test_field',
    'settings' => array(
      'changeable' => 0,
      'unchangeable' => 0,
    ),
  ));
  $field_storage
    ->save();
  $field_storage
    ->setSetting('changeable', $field_storage
    ->getSetting('changeable') + 1);
  try {
    $field_storage
      ->save();
    $this
      ->pass(t("A changeable setting can be updated."));
  } catch (FieldStorageDefinitionUpdateForbiddenException $e) {
    $this
      ->fail(t("An unchangeable setting cannot be updated."));
  }
  $field_storage
    ->setSetting('unchangeable', $field_storage
    ->getSetting('unchangeable') + 1);
  try {
    $field_storage
      ->save();
    $this
      ->fail(t("An unchangeable setting can be updated."));
  } catch (FieldStorageDefinitionUpdateForbiddenException $e) {
    $this
      ->pass(t("An unchangeable setting cannot be updated."));
  }
}