You are here

trait SchemaCheckTestTrait in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/SchemaCheckTestTrait.php \Drupal\Tests\SchemaCheckTestTrait
  2. 9 core/tests/Drupal/Tests/SchemaCheckTestTrait.php \Drupal\Tests\SchemaCheckTestTrait

Provides a class for checking configuration schema.

Hierarchy

38 files declare their use of SchemaCheckTestTrait
BlockConfigSchemaTest.php in core/modules/block/tests/src/Kernel/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
DefaultConfigTest.php in core/tests/Drupal/KernelTests/Core/Config/DefaultConfigTest.php

... See full list

File

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

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

Namesort descending Modifiers Type Description Overrides
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::$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.