diff --git a/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php b/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php index b8b4c618977f5ce5a693aa62c86fbff2e103a320..15018db232ffd4f548be7437bdb1078cf7f2699e 100644 --- a/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php +++ b/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php @@ -51,28 +51,45 @@ class DefaultConfigTest extends KernelTestBase { * @dataProvider coreModuleListDataProvider */ public function testModuleConfig($module) { + $this->assertExtensionConfig($module, 'module'); + } + + /** + * Tests if installed config is equal to the exported config. + * + * @dataProvider themeListDataProvider + */ + public function testThemeConfig($theme) { + $this->assertExtensionConfig($theme, 'theme'); + } + + /** + * Tests that the config provided by the extension is correct. + * + * @param string $name + * Extension name. + * @param string $type + * Extension type, either 'module' or 'theme'. + */ + protected function assertExtensionConfig(string $name, string $type) { // 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 // this for all tests in case optional configuration depends on it. $this->installConfig(['system', 'user']); - $module_path = drupal_get_path('module', $module) . '/'; - - /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */ - $module_installer = $this->container->get('module_installer'); + $extension_path = drupal_get_path($type, $name) . '/'; + $extension_config_storage = new FileStorage($extension_path . InstallStorage::CONFIG_INSTALL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION); + $optional_config_storage = new FileStorage($extension_path . InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION); - $module_config_storage = new FileStorage($module_path . InstallStorage::CONFIG_INSTALL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION); - $optional_config_storage = new FileStorage($module_path . InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION); - - if (empty($optional_config_storage->listAll()) && empty($module_config_storage->listAll())) { - $this->markTestSkipped("$module has no configuration to test"); + if (empty($optional_config_storage->listAll()) && empty($extension_config_storage->listAll())) { + $this->markTestSkipped("$name has no configuration to test"); } // Work out any additional modules and themes that need installing to create // an optional config. - $modules_to_install = [$module]; - $themes_to_install = []; + $modules_to_install = $type !== 'theme' ? [$name] : []; + $themes_to_install = $type === 'theme' ? [$name] : []; foreach ($optional_config_storage->listAll() as $config_name) { $data = $optional_config_storage->read($config_name); $dependency = new ConfigEntityDependency($config_name, $data); @@ -81,14 +98,36 @@ public function testModuleConfig($module) { } // Remove core because that cannot be installed. $modules_to_install = array_diff(array_unique($modules_to_install), ['core']); - $module_installer->install($modules_to_install); + $this->container->get('module_installer')->install($modules_to_install); $this->container->get('theme_installer')->install(array_unique($themes_to_install)); // Test configuration in the module's config/install directory. - $this->doTestsOnConfigStorage($module_config_storage, $module); + $this->doTestsOnConfigStorage($extension_config_storage, $name); // Test configuration in the module's config/optional directory. - $this->doTestsOnConfigStorage($optional_config_storage, $module); + $this->doTestsOnConfigStorage($optional_config_storage, $name); + } + + /** + * A data provider that lists every theme in core. + * + * @return array + * An array of theme names to test. + */ + public function themeListDataProvider() { + $prefix = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'themes'; + $theme_dirs = array_keys(iterator_to_array(new \FilesystemIterator($prefix))); + $theme_names = array_map(function ($path) use ($prefix) { + return str_replace($prefix . DIRECTORY_SEPARATOR, '', $path); + }, $theme_dirs); + $themes_keyed = array_combine($theme_names, $theme_names); + + // Engines is not a theme. + unset($themes_keyed['engines']); + + return array_map(function ($theme) { + return [$theme]; + }, $themes_keyed); } /** diff --git a/core/themes/olivero/config/install/block.block.olivero_account_menu.yml b/core/themes/olivero/config/install/block.block.olivero_account_menu.yml index 36f3becdcdd337f7073be20d279d311970748501..9d89372c13ede1deb4c753243dd476cc9b24f020 100644 --- a/core/themes/olivero/config/install/block.block.olivero_account_menu.yml +++ b/core/themes/olivero/config/install/block.block.olivero_account_menu.yml @@ -1,6 +1,10 @@ langcode: en status: true dependencies: + config: + - system.menu.account + module: + - system theme: - olivero id: olivero_account_menu @@ -8,9 +12,9 @@ theme: olivero region: secondary_menu weight: -4 provider: null -plugin: system_menu_block:account +plugin: 'system_menu_block:account' settings: - id: system_menu_block:account + id: 'system_menu_block:account' label: 'User account menu' provider: system label_display: '0' diff --git a/core/themes/olivero/config/install/block.block.olivero_main_menu.yml b/core/themes/olivero/config/install/block.block.olivero_main_menu.yml index e956075c62fd63147a692d63a48fe91a6ffc63f2..79fe3d2c817f7bd3d1aa61a768a80bef8f5dc640 100644 --- a/core/themes/olivero/config/install/block.block.olivero_main_menu.yml +++ b/core/themes/olivero/config/install/block.block.olivero_main_menu.yml @@ -1,6 +1,10 @@ langcode: en status: true dependencies: + config: + - system.menu.main + module: + - system theme: - olivero id: olivero_main_menu @@ -8,9 +12,9 @@ theme: olivero region: primary_menu weight: 0 provider: null -plugin: system_menu_block:main +plugin: 'system_menu_block:main' settings: - id: system_menu_block:main + id: 'system_menu_block:main' label: 'Main navigation' provider: system label_display: '0' diff --git a/core/themes/olivero/config/install/block.block.olivero_powered.yml b/core/themes/olivero/config/install/block.block.olivero_powered.yml index 6f5d83f42927ce748d11b95380ea8400a8bec88b..177f33f87f4bc6d99e8deeee08b01239adb51a13 100644 --- a/core/themes/olivero/config/install/block.block.olivero_powered.yml +++ b/core/themes/olivero/config/install/block.block.olivero_powered.yml @@ -1,6 +1,8 @@ langcode: en status: true dependencies: + module: + - system theme: - olivero id: olivero_powered diff --git a/core/themes/olivero/config/optional/block.block.olivero_syndicate.yml b/core/themes/olivero/config/optional/block.block.olivero_syndicate.yml index c066164a380e0055260c9403f53bc15820907a10..3f6bf35a76202101c7089a61af6021a3b56619d5 100644 --- a/core/themes/olivero/config/optional/block.block.olivero_syndicate.yml +++ b/core/themes/olivero/config/optional/block.block.olivero_syndicate.yml @@ -13,7 +13,8 @@ provider: null plugin: node_syndicate_block settings: id: node_syndicate_block - label: RSS feed + label: 'RSS feed' provider: node label_display: '0' + block_count: 10 visibility: { }