function ConfigEntityValidationTestBase::testImmutableProperties

Same name in other branches
  1. 11.x 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.

11 calls to ConfigEntityValidationTestBase::testImmutableProperties()
BaseFieldOverrideValidationTest::testImmutableProperties in core/tests/Drupal/KernelTests/Core/Entity/BaseFieldOverrideValidationTest.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.
EditorValidationTest::testImmutableProperties in core/modules/editor/tests/src/Kernel/EditorValidationTest.php
Tests that immutable properties cannot be changed.
EntityFormDisplayValidationTest::testImmutableProperties in core/tests/Drupal/KernelTests/Core/Entity/EntityFormDisplayValidationTest.php
Tests that immutable properties cannot be changed.
EntityFormModeValidationTest::testImmutableProperties in core/tests/Drupal/KernelTests/Core/Entity/EntityFormModeValidationTest.php
Tests that immutable properties cannot be changed.

... See full list

11 methods override ConfigEntityValidationTestBase::testImmutableProperties()
BaseFieldOverrideValidationTest::testImmutableProperties in core/tests/Drupal/KernelTests/Core/Entity/BaseFieldOverrideValidationTest.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.
EditorValidationTest::testImmutableProperties in core/modules/editor/tests/src/Kernel/EditorValidationTest.php
Tests that immutable properties cannot be changed.
EntityFormDisplayValidationTest::testImmutableProperties in core/tests/Drupal/KernelTests/Core/Entity/EntityFormDisplayValidationTest.php
Tests that immutable properties cannot be changed.
EntityFormModeValidationTest::testImmutableProperties in core/tests/Drupal/KernelTests/Core/Entity/EntityFormModeValidationTest.php
Tests that immutable properties cannot be changed.

... See full list

File

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

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'], 'All config entities should have at least one immutable ID property.');
    foreach ($constraints['ImmutableProperties'] 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.