function SimpleConfigValidationTest::testSpecialCharacters

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Config/SimpleConfigValidationTest.php \Drupal\KernelTests\Core\Config\SimpleConfigValidationTest::testSpecialCharacters()

Tests that special characters are not allowed in labels or text data.

@dataProvider providerSpecialCharacters

Parameters

string $config_name: The name of the simple config to test with.

string $property: The config property in which to embed a control character.

string $character: A special character to embed.

string|null $expected_error_message: The expected validation error message, if any.

File

core/tests/Drupal/KernelTests/Core/Config/SimpleConfigValidationTest.php, line 134

Class

SimpleConfigValidationTest
Tests validation of certain elements common to all config.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testSpecialCharacters(string $config_name, string $property, string $character, ?string $expected_error_message) : void {
    $config = $this->config($config_name)
        ->set($property, "This has a special character: {$character}");
    $violations = $this->container
        ->get('config.typed')
        ->createFromNameAndData($config->getName(), $config->get())
        ->validate();
    if ($expected_error_message === NULL) {
        $this->assertCount(0, $violations);
    }
    else {
        $code_point = mb_ord($character);
        $this->assertCount(1, $violations, "Character {$code_point} did not raise a constraint violation.");
        $this->assertSame($property, $violations[0]->getPropertyPath());
        $this->assertSame($expected_error_message, (string) $violations[0]->getMessage());
    }
}

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