function ConfigEntityValidationTestBase::testImmutableProperties

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase::testImmutableProperties()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase::testImmutableProperties()

Tests that immutable properties cannot be changed.

Parameters

mixed[] $valid_values: (optional) The values to set for the immutable properties, keyed by name. This should be used if the immutable properties can only accept certain values, e.g. valid plugin IDs.

6 methods override ConfigEntityValidationTestBase::testImmutableProperties()
ActionValidationTest::testImmutableProperties in core/modules/system/tests/src/Kernel/Entity/ActionValidationTest.php
Tests that immutable properties cannot be changed.
ContentLanguageSettingsValidationTest::testImmutableProperties in core/modules/language/tests/src/Kernel/ContentLanguageSettingsValidationTest.php
Tests that immutable properties cannot be changed.
FieldConfigValidationTest::testImmutableProperties in core/modules/field/tests/src/Kernel/Entity/FieldConfigValidationTest.php
Tests that immutable properties cannot be changed.
FieldStorageConfigValidationTest::testImmutableProperties in core/modules/field/tests/src/Kernel/Entity/FieldStorageConfigValidationTest.php
Tests that immutable properties cannot be changed.
LayoutBuilderEntityViewDisplayValidationTest::testImmutableProperties in core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayValidationTest.php
Tests that immutable properties cannot be changed.

... See full list

File

core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php, line 469

Class

ConfigEntityValidationTestBase
Base class for testing validation of config entities.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testImmutableProperties(array $valid_values = []) : void {
  $constraints = $this->entity
    ->getEntityType()
    ->getConstraints();
  $this->assertNotEmpty($constraints['ImmutableProperties']['properties'], 'All config entities should have at least one immutable ID property.');
  foreach ($constraints['ImmutableProperties']['properties'] as $property_name) {
    $original_value = $this->entity
      ->get($property_name);
    $this->entity
      ->set($property_name, $valid_values[$property_name] ?? $this->randomMachineName());
    $this->assertValidationErrors([
      '' => "The '{$property_name}' property cannot be changed.",
    ]);
    $this->entity
      ->set($property_name, $original_value);
  }
}

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