Verified Commit 39cf4d22 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3377055 by Wim Leers, borisson_: Validate config schema compliance of...

Issue #3377055 by Wim Leers, borisson_: Validate config schema compliance of Demo Umami and Minimal profiles, just like we do for Standard
parent 9947041b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ settings:
        - '<h4 id>'
        - '<h5 id>'
        - '<h6 id>'
        - '<img src alt data-entity-type data-entity-uuid data-align data-caption width height>'
        - '<img src alt data-entity-type data-entity-uuid data-align data-caption width height loading>'
        - '<drupal-media data-view-mode title>'
    media_media:
      allow_view_mode_override: false
+35 −0
Original line number Diff line number Diff line
@@ -2,13 +2,17 @@

namespace Drupal\Tests\demo_umami\Functional;

use Drupal\ckeditor5\Plugin\Editor\CKEditor5;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\editor\Entity\Editor;
use Drupal\KernelTests\AssertConfigTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\SchemaCheckTestTrait;
use Symfony\Component\Validator\ConstraintViolation;

/**
 * Tests demo_umami profile.
@@ -17,6 +21,7 @@
 */
class DemoUmamiProfileTest extends BrowserTestBase {
  use AssertConfigTrait;
  use SchemaCheckTestTrait;

  /**
   * {@inheritdoc}
@@ -57,6 +62,36 @@ public function testConfig() {

    $default_config_storage = new FileStorage($this->container->get('extension.list.profile')->getPath('demo_umami') . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY, InstallStorage::DEFAULT_COLLECTION);
    $this->assertDefaultConfig($default_config_storage, $active_config_storage);

    // Now we have all configuration imported, test all of them for schema
    // conformance. Ensures all imported default configuration is valid when
    // Demo Umami profile modules are enabled.
    $names = $this->container->get('config.storage')->listAll();
    /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
    $typed_config = $this->container->get('config.typed');
    foreach ($names as $name) {
      $config = $this->config($name);
      $this->assertConfigSchema($typed_config, $name, $config->get());
    }

    // Validate all configuration.
    // @todo Generalize in https://www.drupal.org/project/drupal/issues/2164373
    foreach (Editor::loadMultiple() as $editor) {
      // Currently only text editors using CKEditor 5 can be validated.
      if ($editor->getEditor() !== 'ckeditor5') {
        continue;
      }

      $this->assertSame([], array_map(
        function (ConstraintViolation $v) {
          return (string) $v->getMessage();
        },
        iterator_to_array(CKEditor5::validatePair(
          $editor,
          $editor->getFilterFormat()
        ))
      ));
    }
  }

  /**
+13 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\user\UserInterface;

/**
@@ -13,6 +14,7 @@
 */
class MinimalTest extends BrowserTestBase {

  use SchemaCheckTestTrait;
  use RequirementsPageTrait;

  protected $profile = 'minimal';
@@ -55,6 +57,17 @@ public function testMinimal() {
    // Ensure special configuration overrides are correct.
    $this->assertFalse($this->config('system.theme.global')->get('features.node_user_picture'), 'Configuration system.theme.global:features.node_user_picture is FALSE.');
    $this->assertEquals(UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL, $this->config('user.settings')->get('register'));

    // Now we have all configuration imported, test all of them for schema
    // conformance. Ensures all imported default configuration is valid when
    // Minimal profile modules are enabled.
    $names = $this->container->get('config.storage')->listAll();
    /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
    $typed_config = $this->container->get('config.typed');
    foreach ($names as $name) {
      $config = $this->config($name);
      $this->assertConfigSchema($typed_config, $name, $config->get());
    }
  }

}