From 408f6296f2d9be4e193cc5478c7da736f2a031fb Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Thu, 24 Feb 2022 10:51:05 +0000 Subject: [PATCH] Issue #3265546 by Spokje, quietone: Drupal\KernelTests\Config\DefaultConfigTest throws deprecation notice for deprecated Core modules/themes which have config --- .../install/deprecated_module.settings.yml | 2 + .../schema/deprecated_module.schema.yml | 7 +++ .../test_deprecated_theme.settings.yml | 2 + .../schema/test_deprecated_theme.schema.yml | 3 + .../KernelTests/Config/DefaultConfigTest.php | 55 ++++++++++++++++++- 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 core/modules/system/tests/modules/deprecated_module/config/install/deprecated_module.settings.yml create mode 100644 core/modules/system/tests/modules/deprecated_module/config/schema/deprecated_module.schema.yml create mode 100644 core/modules/system/tests/themes/test_deprecated_theme/config/install/test_deprecated_theme.settings.yml create mode 100644 core/modules/system/tests/themes/test_deprecated_theme/config/schema/test_deprecated_theme.schema.yml diff --git a/core/modules/system/tests/modules/deprecated_module/config/install/deprecated_module.settings.yml b/core/modules/system/tests/modules/deprecated_module/config/install/deprecated_module.settings.yml new file mode 100644 index 000000000000..4eddb872b850 --- /dev/null +++ b/core/modules/system/tests/modules/deprecated_module/config/install/deprecated_module.settings.yml @@ -0,0 +1,2 @@ +foo: + bar diff --git a/core/modules/system/tests/modules/deprecated_module/config/schema/deprecated_module.schema.yml b/core/modules/system/tests/modules/deprecated_module/config/schema/deprecated_module.schema.yml new file mode 100644 index 000000000000..decbe5da4de4 --- /dev/null +++ b/core/modules/system/tests/modules/deprecated_module/config/schema/deprecated_module.schema.yml @@ -0,0 +1,7 @@ +deprecated_module.settings: + type: config_object + label: 'deprecated_module settings' + mapping: + foo: + type: string + label: 'Wait until you meet baz!' diff --git a/core/modules/system/tests/themes/test_deprecated_theme/config/install/test_deprecated_theme.settings.yml b/core/modules/system/tests/themes/test_deprecated_theme/config/install/test_deprecated_theme.settings.yml new file mode 100644 index 000000000000..502e7f0ee367 --- /dev/null +++ b/core/modules/system/tests/themes/test_deprecated_theme/config/install/test_deprecated_theme.settings.yml @@ -0,0 +1,2 @@ +favicon: + use_default: true diff --git a/core/modules/system/tests/themes/test_deprecated_theme/config/schema/test_deprecated_theme.schema.yml b/core/modules/system/tests/themes/test_deprecated_theme/config/schema/test_deprecated_theme.schema.yml new file mode 100644 index 000000000000..5d11eca98dd1 --- /dev/null +++ b/core/modules/system/tests/themes/test_deprecated_theme/config/schema/test_deprecated_theme.schema.yml @@ -0,0 +1,3 @@ +test_deprecated_theme.settings: + type: theme_settings + label: 'test_deprecated_theme settings' diff --git a/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php b/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php index 0de9040330c0..5d27fd0a9a87 100644 --- a/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php +++ b/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php @@ -49,7 +49,7 @@ class DefaultConfigTest extends KernelTestBase { /** * Tests if installed config is equal to the exported config. * - * @dataProvider coreModuleListDataProvider + * @dataProvider moduleListDataProvider */ public function testModuleConfig($module) { $this->assertExtensionConfig($module, 'module'); @@ -75,6 +75,31 @@ public function testThemeConfig($theme) { * @internal */ protected function assertExtensionConfig(string $name, string $type): void { + // Parse .info.yml file for module/theme $name. Since it's not installed at + // this point we can't retrieve it from the 'module_handler' service. + switch ($name) { + case 'test_deprecated_theme': + $file_name = DRUPAL_ROOT . '/core/modules/system/tests/themes/' . $name . '/' . $name . '.info.yml'; + break; + + case 'deprecated_module': + $file_name = DRUPAL_ROOT . '/core/modules/system/tests/modules/' . $name . '/' . $name . '.info.yml'; + break; + + default; + $file_name = DRUPAL_ROOT . '/core/' . $type . 's/' . $name . '/' . $name . '.info.yml'; + } + + $info = \Drupal::service('info_parser')->parse($file_name); + // Test we have a parsed info.yml file. + $this->assertNotEmpty($info); + + // Skip deprecated extensions. + if (isset($info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER]) + && $info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER] === ExtensionLifecycle::DEPRECATED) { + $this->markTestSkipped("The $type '$name' is deprecated."); + } + // System and user are required in order to be able to install some of the // other modules. Therefore they are put into static::$modules, which though // doesn't install config files, so import those config files explicitly. Do @@ -114,8 +139,11 @@ protected function assertExtensionConfig(string $name, string $type): void { /** * A data provider that lists every theme in core. * - * @return array - * An array of theme names to test. + * Also adds a deprecated theme with config. + * + * @return string[][] + * An array of theme names to test, with both key and value being the name + * of the theme. */ public function themeListDataProvider() { $prefix = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'themes'; @@ -128,11 +156,32 @@ public function themeListDataProvider() { // Engines is not a theme. unset($themes_keyed['engines']); + // Add a deprecated theme with config. + $themes_keyed['test_deprecated_theme'] = 'test_deprecated_theme'; + return array_map(function ($theme) { return [$theme]; }, $themes_keyed); } + /** + * A data provider that lists every module in core. + * + * Also adds a deprecated module with config. + * + * @return string[][] + * An array of module names to test, with both key and value being the name + * of the module. + */ + public function moduleListDataProvider() { + $modules_keyed = $this->coreModuleListDataProvider(); + + // Add a deprecated module with config. + $modules_keyed['deprecated_module'] = ['deprecated_module']; + + return $modules_keyed; + } + /** * Tests that default config matches the installed config. * -- GitLab