trait SchemaCheckTestTrait

Same name in other branches
  1. 9 core/tests/Drupal/Tests/SchemaCheckTestTrait.php \Drupal\Tests\SchemaCheckTestTrait
  2. 8.9.x core/modules/config/src/Tests/SchemaCheckTestTrait.php \Drupal\config\Tests\SchemaCheckTestTrait
  3. 8.9.x core/tests/Drupal/Tests/SchemaCheckTestTrait.php \Drupal\Tests\SchemaCheckTestTrait
  4. 11.x core/tests/Drupal/Tests/SchemaCheckTestTrait.php \Drupal\Tests\SchemaCheckTestTrait

Provides a class for checking configuration schema.

Hierarchy

44 files declare their use of SchemaCheckTestTrait
BlockConfigSchemaTest.php in core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
BlockConfigSchemaTest.php in core/modules/book/tests/src/Kernel/Block/BlockConfigSchemaTest.php
CKEditor5PluginManagerTest.php in core/modules/ckeditor5/tests/src/Kernel/CKEditor5PluginManagerTest.php
ConfigImportAllTest.php in core/modules/config/tests/src/Functional/ConfigImportAllTest.php
DateTimeSchemaTest.php in core/modules/datetime/tests/src/Kernel/Views/DateTimeSchemaTest.php

... See full list

File

core/tests/Drupal/Tests/SchemaCheckTestTrait.php, line 13

Namespace

Drupal\Tests
View source
trait SchemaCheckTestTrait {
    use SchemaCheckTrait;
    
    /**
     * Asserts the TypedConfigManager has a valid schema for the configuration.
     *
     * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
     *   The TypedConfigManager.
     * @param string $config_name
     *   The configuration name.
     * @param array $config_data
     *   The configuration data.
     */
    public function assertConfigSchema(TypedConfigManagerInterface $typed_config, $config_name, $config_data) {
        $check = $this->checkConfigSchema($typed_config, $config_name, $config_data);
        $message = '';
        if ($check === FALSE) {
            $message = 'Error: No schema exists.';
        }
        elseif ($check !== TRUE) {
            $this->assertIsArray($check, "The config schema check errors should be in the form of an array.");
            $message = "Errors:\n";
            foreach ($check as $key => $error) {
                $message .= "Schema key {$key} failed with: {$error}\n";
            }
        }
        $this->assertTrue($check, "There should be no errors in configuration '{$config_name}'. {$message}");
    }
    
    /**
     * Asserts configuration, specified by name, has a valid schema.
     *
     * @param string $config_name
     *   The configuration name.
     */
    public function assertConfigSchemaByName($config_name) {
        $config = $this->config($config_name);
        $this->assertConfigSchema(\Drupal::service('config.typed'), $config->getName(), $config->get());
    }

}

Members

Title Sort descending Modifiers Object type Summary
SchemaCheckTestTrait::assertConfigSchema public function Asserts the TypedConfigManager has a valid schema for the configuration.
SchemaCheckTestTrait::assertConfigSchemaByName public function Asserts configuration, specified by name, has a valid schema.
SchemaCheckTrait::$configName protected property The configuration object name under test.
SchemaCheckTrait::$ignoredPropertyPaths protected static property The ignored property paths.
SchemaCheckTrait::$schema protected property The config schema wrapper object for the configuration object under test.
SchemaCheckTrait::checkConfigSchema public function Checks the TypedConfigManager has a valid schema for the configuration.
SchemaCheckTrait::checkValue protected function Helper method to check data type.
SchemaCheckTrait::isViolationForIgnoredPropertyPath protected static function Determines whether this violation is for an ignored Config property path.

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