Score:1

Functional Testing - Schema Incomplete Exception missing schema

id flag

I am working on my first functional test for a custom module. Each time I run the functional test I get errors dealing with configuration schema issues. However, I'm confused by the error message.

Command

phpunit modules/custom/worx_blog

Error Message

Schema errors for editor.editor.full_html with the following errors:

editor.editor.full_html:settings.plugins.linkit missing schema

My Module Conifg - Module Conifg File

If you look at the file you can see that the linkit entry is there. So I don't know what it means by it's missing.

miststudent2011 avatar
fr flag
You need to add schema.yml file something like this https://git.drupalcode.org/sandbox/Bhanu951-3103712/-/blob/8.x-dev/testing_examples/config/schema/testing_examples.schema.yml
Score:1
us flag

As Configuration API says, each module needs to define its configuration schema in files in the config/schema directory under the top-level module directory. That is used by Drupal core to validate the configuration file and verify it's not corrupted.

For example, the Book module uses the following schema, for its configuration object (core/modules/book/config/schema/book.schema.yml).

# Schema for the configuration files of the book module.

book.settings:
  type: config_object
  label: 'Book settings'
  mapping:
    allowed_types:
      type: sequence
      label: 'Content types allowed in book outlines'
      sequence:
        type: string
        label: 'Content type'
    block:
      type: mapping
      label: 'Block'
      mapping:
        navigation:
          type: mapping
          label: 'Navigation'
          mapping:
            mode:
              type: string
              label: 'Mode'
    child_type:
      type: string
      label: 'Content type for child pages'

block.settings.book_navigation:
  type: block_settings
  label: 'Book navigation block'
  mapping:
    block_mode:
      type: string
      label: 'Block display mode'

That is different from its configuration file, which is located in core/modules/book/config/installbook.settings.yml.

allowed_types:
  - book
block:
  navigation:
    mode: 'all pages'
child_type: book

The code that throws that exception is contained in the ConfigSchemaChecker class, used to implement an event subscriber that is invoked when a configuration object is saved.

  public function onConfigSave(ConfigCrudEvent $event) {
    // Only validate configuration if in the default collection. Other
    // collections may have incomplete configuration (for example language
    // overrides only). These are not valid in themselves.
    $saved_config = $event->getConfig();
    if ($saved_config->getStorage()->getCollectionName() != StorageInterface::DEFAULT_COLLECTION) {
      return;
    }
    $name = $saved_config->getName();
    $data = $saved_config->get();
    $checksum = Crypt::hashBase64(serialize($data));
    if (!in_array($name, $this->exclude) && !isset($this->checked[$name . ':' . $checksum])) {
      $this->checked[$name . ':' . $checksum] = TRUE;
      $errors = $this->checkConfigSchema($this->typedManager, $name, $data);
      if ($errors === FALSE) {
        throw new SchemaIncompleteException("No schema for {$name}");
      }
      elseif (is_array($errors)) {
        $text_errors = [];
        foreach ($errors as $key => $error) {
          $text_errors[] = new FormattableMarkup('@key @error', [
            '@key' => $key,
            '@error' => $error,
          ]);
        }
        throw new SchemaIncompleteException("Schema errors for {$name} with the following errors: " . implode(', ', $text_errors));
      }
    }
  }
id flag
With this being the case, then how come I only get a missing schema on certain entries in the config/install/ ymls and not on every entry?
apaderno avatar
us flag
Because the [`ConfigSchemaChecker`](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Config%21Development%21ConfigSchemaChecker.php/class/ConfigSchemaChecker/9.3.x) class doesn't check every entry and its event handler is invoked only when a configuration object is saved.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.