Fix all type: machine_name constraint violations in tests

Created on 6 July 2023, over 1 year ago
Updated 1 August 2023, over 1 year ago

Problem/Motivation

Discovered in 📌 KernelTestBase::$strictConfigSchema = TRUE and BrowserTestBase::$strictConfigSchema = TRUE do not actually strictly validate Fixed .

For example:

1) Drupal\Tests\language\Functional\LanguageUILanguageNegotiationTest::testUrlLanguageFallback
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for block.block.site-branding with the following errors: 0 [id] The "site-branding" machine name is not valid.

and

1) Drupal\KernelTests\Core\Asset\ResolvedLibraryDefinitionsFilesMatchTest::testCoreLibraryCompleteness
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for tour.tour.block-layout with the following errors: 0 [id] The <em class="placeholder">"block-layout"</em> machine name is not valid.

Steps to reproduce

Run Drupal core's test suite with 📌 KernelTestBase::$strictConfigSchema = TRUE and BrowserTestBase::$strictConfigSchema = TRUE do not actually strictly validate Fixed applied, and with the lines

      // @see "machine_name" in core.data_types.schema.yml
      // @todo Remove this in
      "This machine name is not valid.",

removed from \Drupal\Core\Config\Schema\SchemaCheckTrait::checkConfigSchema().

Proposed resolution

Solution for the examples above:

diff --git a/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php b/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php
index 900b0c9dc4..e5e2bf0ca5 100644
--- a/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php
+++ b/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php
@@ -466,7 +466,7 @@ public function testUrlLanguageFallback() {
     // Place a site branding block in the header region.
     $this->drupalPlaceBlock('system_branding_block', [
       'region' => 'header',
-      'id' => 'site-branding',
+      'id' => 'site_branding',
     ]);
 
     // Access the front page without specifying any valid URL language prefix

and

diff --git a/core/modules/tour/config/schema/tour.schema.yml b/core/modules/tour/config/schema/tour.schema.yml
index 05fcb5b058..7117f4b4ef 100644
--- a/core/modules/tour/config/schema/tour.schema.yml
+++ b/core/modules/tour/config/schema/tour.schema.yml
@@ -6,6 +6,9 @@ tour.tour.*:
   mapping:
     id:
       type: machine_name
+      # Tour IDs also allow dashes.
+      constraints:
+        Regex: '/^[a-z0-9_-]+$/'
       label: 'ID'
     label:
       type: label

(that's right, that's an oversight from 📌 Add config validation for the allowed characters of machine names Fixed , and the same is true for the action config entity type, because these two A) barely have test coverage, B) have no UI, C) are not maintained!)

Remaining tasks

Fix all of these failures.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

📌 Task
Status

Fixed

Version

11.0 🔥

Component
Configuration 

Last updated 3 days ago

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024