trait SchemaCheckTestTrait in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/config/src/Tests/SchemaCheckTestTrait.php \Drupal\config\Tests\SchemaCheckTestTrait
Provides a class for checking configuration schema.
Hierarchy
- trait \Drupal\config\Tests\SchemaCheckTestTrait uses SchemaCheckTrait
30 files declare their use of SchemaCheckTestTrait
- BlockConfigSchemaTest.php in core/modules/ block/ src/ Tests/ BlockConfigSchemaTest.php 
- Contains \Drupal\block\Tests\BlockConfigSchemaTest.
- EntityReferenceFieldDefaultValueTest.php in core/modules/ field/ src/ Tests/ EntityReference/ EntityReferenceFieldDefaultValueTest.php 
- Contains \Drupal\field\Tests\EntityReference\EntityReferenceFieldDefaultValueTest.
- EntityReferenceFieldTest.php in core/modules/ system/ src/ Tests/ Entity/ EntityReferenceFieldTest.php 
- Contains \Drupal\system\Tests\Entity\EntityReferenceFieldTest.
- FilterNumericWebTest.php in core/modules/ views_ui/ src/ Tests/ FilterNumericWebTest.php 
- Contains \Drupal\views_ui\Tests\FilterNumericWebTest.
- LanguageConfigSchemaTest.php in core/modules/ language/ src/ Tests/ LanguageConfigSchemaTest.php 
- Contains \Drupal\language\Tests\LanguageConfigSchemaTest.
File
- core/modules/ config/ src/ Tests/ SchemaCheckTestTrait.php, line 17 
- Contains \Drupal\config\Tests\SchemaCheckTestTrait.
Namespace
Drupal\config\TestsView 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) {
    $errors = $this
      ->checkConfigSchema($typed_config, $config_name, $config_data);
    if ($errors === FALSE) {
      // @todo Since the use of this trait is under TestBase, it works.
      //   Can be fixed as part of https://www.drupal.org/node/2260053.
      $this
        ->fail(SafeMarkup::format('No schema for @config_name', array(
        '@config_name' => $config_name,
      )));
      return;
    }
    elseif ($errors === TRUE) {
      // @todo Since the use of this trait is under TestBase, it works.
      //   Can be fixed as part of https://www.drupal.org/node/2260053.
      $this
        ->pass(SafeMarkup::format('Schema found for @config_name and values comply with schema.', array(
        '@config_name' => $config_name,
      )));
    }
    else {
      foreach ($errors as $key => $error) {
        // @todo Since the use of this trait is under TestBase, it works.
        //   Can be fixed as part of https://www.drupal.org/node/2260053.
        $this
          ->fail(SafeMarkup::format('Schema key @key failed with: @error', array(
          '@key' => $key,
          '@error' => $error,
        )));
      }
    }
  }
  /**
   * 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
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| SchemaCheckTestTrait:: | public | function | Asserts the TypedConfigManager has a valid schema for the configuration. | |
| SchemaCheckTestTrait:: | public | function | Asserts configuration, specified by name, has a valid schema. | |
| SchemaCheckTrait:: | protected | property | The configuration object name under test. | |
| SchemaCheckTrait:: | protected | property | The config schema wrapper object for the configuration object under test. | |
| SchemaCheckTrait:: | public | function | Checks the TypedConfigManager has a valid schema for the configuration. | |
| SchemaCheckTrait:: | protected | function | Helper method to check data type. | 
