function SchemaCheckTraitTest::testCheckConfigSchema

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

Tests \Drupal\Core\Config\Schema\SchemaCheckTrait.

@dataProvider providerCheckConfigSchema

File

core/tests/Drupal/KernelTests/Core/Config/SchemaCheckTraitTest.php, line 45

Class

SchemaCheckTraitTest
Tests the functionality of SchemaCheckTrait.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testCheckConfigSchema(string $type_to_validate_against, bool $validate_constraints, array|bool $nulled_expectations, array|bool $no_data_expectations, array $expectations) : void {
    // Test a non existing schema.
    $ret = $this->checkConfigSchema($this->typedConfig, 'config_schema_test.no_schema', $this->config('config_schema_test.no_schema')
        ->get());
    $this->assertFalse($ret);
    // Test an existing schema with valid data.
    $config_data = $this->config('config_test.types')
        ->get();
    $ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data);
    $this->assertTrue($ret);
    // Test it is possible to mark any schema type as required (not nullable).
    $nulled_config_data = array_fill_keys(array_keys($config_data), NULL);
    $ret = $this->checkConfigSchema($this->typedConfig, $type_to_validate_against, $nulled_config_data, $validate_constraints);
    $this->assertSame($nulled_expectations, $ret);
    // Add a new key, a new array and overwrite boolean with array to test the
    // error messages.
    $config_data = [
        'new_key' => 'new_value',
        'new_array' => [],
    ] + $config_data;
    $config_data['boolean'] = [];
    $ret = $this->checkConfigSchema($this->typedConfig, $type_to_validate_against, $config_data, $validate_constraints);
    $this->assertEquals($expectations, $ret);
    // Omit all data, this should trigger validation errors for required keys
    // missing.
    $config_data = [];
    $ret = $this->checkConfigSchema($this->typedConfig, $type_to_validate_against, $config_data, $validate_constraints);
    $this->assertEquals($no_data_expectations, $ret);
}

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