Verified Commit f13ad693 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3361534 by Wim Leers, borisson_, longwave, catch:...

Issue #3361534 by Wim Leers, borisson_, longwave, catch: KernelTestBase::$strictConfigSchema = TRUE and BrowserTestBase::$strictConfigSchema = TRUE do not actually strictly validate
parent 29dc14b2
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -99,7 +99,9 @@ machine_name:
  type: string
  label: 'Machine name'
  constraints:
    Regex: '/^[a-z0-9_]+$/'
    Regex:
      pattern: '/^[a-z0-9_]+$/'
      message: "The %value machine name is not valid."
    Length:
      # @see \Drupal\Core\Config\Entity\ConfigEntityStorage::MAX_ID_LENGTH
      max: 166
@@ -233,6 +235,7 @@ theme_settings:
          label: 'Logo path'
        url:
          type: uri
          nullable: true
          label: 'URL'
        use_default:
          type: boolean
+29 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
use Drupal\Core\TypedData\Type\StringInterface;
use Drupal\Core\TypedData\Type\FloatInterface;
use Drupal\Core\TypedData\Type\IntegerInterface;
use Symfony\Component\Validator\ConstraintViolation;

/**
 * Provides a trait for checking configuration schema.
@@ -57,6 +58,34 @@ public function checkConfigSchema(TypedConfigManagerInterface $typed_config, $co
      $errors[] = $this->checkValue($key, $value);
    }
    $errors = array_merge(...$errors);
    // Also perform explicit validation. Note this does NOT require every node
    // in the config schema tree to have validation constraints defined.
    $violations = $this->schema->validate();
    $ignored_validation_constraint_messages = [
      // @see \Drupal\Core\Config\Plugin\Validation\Constraint\ConfigExistsConstraint::$message
      // @todo Remove this in https://www.drupal.org/project/drupal/issues/3362453
      "The '.*' config does not exist.",
      // @see \Drupal\Core\Extension\Plugin\Validation\Constraint\ExtensionExistsConstraint::$moduleMessage
      // @see \Drupal\Core\Extension\Plugin\Validation\Constraint\ExtensionExistsConstraint::$themeMessage
      // @todo Remove this in https://www.drupal.org/project/drupal/issues/3362456
      "Module '.*' is not installed.",
      "Theme '.*' is not installed.",
      // @see \Drupal\Core\Plugin\Plugin\Validation\Constraint\PluginExistsConstraint::$unknownPluginMessage
      // @todo Remove this in https://www.drupal.org/project/drupal/issues/3362457
      "The '.*' plugin does not exist.",
      // @see "machine_name" in core.data_types.schema.yml
      // @todo Remove this in https://www.drupal.org/project/drupal/issues/3372972
      "The <em class=\"placeholder\">.*<\/em> machine name is not valid.",
    ];
    $filtered_violations = array_filter(
      iterator_to_array($violations),
      fn (ConstraintViolation $v) => preg_match(sprintf("/^(%s)$/", implode('|', $ignored_validation_constraint_messages)), (string) $v->getMessage()) !== 1
    );
    $validation_errors = array_map(
      fn (ConstraintViolation $v) => sprintf("[%s] %s", $v->getPropertyPath(), (string) $v->getMessage()),
      $filtered_violations
    );
    $errors = array_merge($errors, $validation_errors);
    if (empty($errors)) {
      return TRUE;
    }
+3 −1
Original line number Diff line number Diff line
@@ -11,7 +11,9 @@ block.block.*:
      # @see https://www.drupal.org/project/drupal/issues/2685917
      # @see https://www.drupal.org/project/drupal/issues/2043527
      constraints:
        Regex: '/^[a-z0-9_.]+$/'
        Regex:
          pattern: '/^[a-z0-9_.]+$/'
          message: "The %value machine name is not valid."
    theme:
      type: string
      label: 'Theme'
+1 −0
Original line number Diff line number Diff line
@@ -580,6 +580,7 @@ public function testBlockUserRoleDelete() {
    $block = Block::create([
      'id' => $this->randomMachineName(),
      'plugin' => 'system_powered_by_block',
      'theme' => 'stark',
    ]);

    $block->setVisibilityConfig('user_role', [
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public function testDeletingBlockContentShouldClearPluginCache() {
    $block_content->save();

    $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid();
    $block = $this->placeBlock($plugin_id, ['region' => 'content']);
    $block = $this->placeBlock($plugin_id, ['region' => 'content', 'theme' => 'stark']);

    // Delete it via storage.
    $storage = $this->container->get('entity_type.manager')->getStorage('block_content');
Loading