function ConfigEntityValidationTestBase::testConfigDependenciesValidation

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

Tests validation of config dependencies.

@dataProvider providerConfigDependenciesValidation

Parameters

array[] $dependencies: The dependencies that should be added to the config entity under test.

array<string, string|string[]> $expected_messages: The expected validation error messages. Keys are property paths, values are the expected messages: a string if a single message is expected, an array of strings if multiple are expected.

File

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

Class

ConfigEntityValidationTestBase
Base class for testing validation of config entities.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testConfigDependenciesValidation(array $dependencies, array $expected_messages) : void {
    // Add the dependencies we were given to the dependencies that may already
    // exist in the entity.
    $dependencies = NestedArray::mergeDeep($dependencies, $this->entity
        ->getDependencies());
    $this->entity
        ->set('dependencies', $dependencies);
    $this->assertValidationErrors($expected_messages);
    // Enforce these dependencies, and ensure we get the same results.
    $this->entity
        ->set('dependencies', [
        'enforced' => $dependencies,
    ]);
    // We now expect validation errors not at `dependencies.module.0`, but at
    // `dependencies.enforced.module.0`. So reuse the same messages, but perform
    // string replacement in the keys.
    $expected_enforced_messages = array_combine(str_replace('dependencies', 'dependencies.enforced', array_keys($expected_messages)), array_values($expected_messages));
    $this->assertValidationErrors($expected_enforced_messages);
}

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