diff --git a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php index f793c4ff6a..cfdd1bd4f1 100644 --- a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php +++ b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php @@ -56,7 +56,7 @@ public function parse($filename) { if (!empty($missing_keys)) { throw new InfoParserException('Missing required keys (' . implode(', ', $missing_keys) . ') in ' . $filename); } - if (!isset($parsed_info['core']) && !isset($parsed_info['core_version_requirement'])) { + if (!isset($parsed_info['core_version_requirement'])) { if (strpos($filename, 'core/') === 0 || strpos($filename, $this->root . '/core/') === 0) { // Core extensions do not need to specify core compatibility: they are // by definition compatible so a sensible default is used. Core @@ -70,12 +70,9 @@ public function parse($filename) { } else { // Non-core extensions must specify core compatibility. - throw new InfoParserException("The 'core' or the 'core_version_requirement' key must be present in " . $filename); + throw new InfoParserException("The 'core_version_requirement' key must be present in " . $filename); } } - if (isset($parsed_info['core']) && !preg_match("/^\d\.x$/", $parsed_info['core'])) { - throw new InfoParserException("Invalid 'core' value \"{$parsed_info['core']}\" in " . $filename); - } if (isset($parsed_info['core_version_requirement'])) { try { $supports_pre_core_version_requirement_version = static::isConstraintSatisfiedByPreviousVersion($parsed_info['core_version_requirement'], static::FIRST_CORE_VERSION_REQUIREMENT_SUPPORTED_VERSION); @@ -99,6 +96,9 @@ public function parse($filename) { throw new InfoParserException("The 'core_version_requirement' can not be used to specify compatibility for a specific version before " . static::FIRST_CORE_VERSION_REQUIREMENT_SUPPORTED_VERSION . " in $filename"); } } + if (isset($parsed_info['core']) && $parsed_info['core'] !== '8.x') { + throw new InfoParserException("'core: {$parsed_info['core']}' is not supported. Use 'core_version_requirement' to specify core compatibility in " . $filename); + } // Determine if the extension is compatible with the current version of // Drupal core. diff --git a/core/modules/system/tests/modules/database_statement_monitoring_test/database_statement_monitoring_test.info.yml b/core/modules/system/tests/modules/database_statement_monitoring_test/database_statement_monitoring_test.info.yml index 74b03a3b8a..894715d976 100644 --- a/core/modules/system/tests/modules/database_statement_monitoring_test/database_statement_monitoring_test.info.yml +++ b/core/modules/system/tests/modules/database_statement_monitoring_test/database_statement_monitoring_test.info.yml @@ -1,6 +1,5 @@ name: 'Database Statement Monitoring Test' type: module description: 'Support module for Database layer tests that need to monitor executed database statements.' -core: 8.x package: Testing version: VERSION diff --git a/core/modules/system/tests/modules/delay_cache_tags_invalidation/delay_cache_tags_invalidation.info.yml b/core/modules/system/tests/modules/delay_cache_tags_invalidation/delay_cache_tags_invalidation.info.yml index 5fe56c9d55..0777e09ca5 100644 --- a/core/modules/system/tests/modules/delay_cache_tags_invalidation/delay_cache_tags_invalidation.info.yml +++ b/core/modules/system/tests/modules/delay_cache_tags_invalidation/delay_cache_tags_invalidation.info.yml @@ -1,5 +1,4 @@ name: 'Delay Cache Tags Invalidation Test' type: module -core: 8.x package: Testing version: VERSION diff --git a/core/modules/system/tests/modules/system_incompatible_core_version_dependencies_test/system_incompatible_core_version_dependencies_test.info.yml b/core/modules/system/tests/modules/system_incompatible_core_version_dependencies_test/system_incompatible_core_version_dependencies_test.info.yml index f429775dd3..35dd9d8948 100644 --- a/core/modules/system/tests/modules/system_incompatible_core_version_dependencies_test/system_incompatible_core_version_dependencies_test.info.yml +++ b/core/modules/system/tests/modules/system_incompatible_core_version_dependencies_test/system_incompatible_core_version_dependencies_test.info.yml @@ -4,4 +4,4 @@ description: 'Support module for testing system dependencies.' package: Testing version: VERSION dependencies: - - drupal:system_incompatible_core_version_test + - drupal:system_core_incompatible_semver_test diff --git a/core/modules/system/tests/modules/system_incompatible_core_version_test/system_incompatible_core_version_test.info.yml b/core/modules/system/tests/modules/system_incompatible_core_version_test/system_incompatible_core_version_test.info.yml deleted file mode 100644 index d99300b830..0000000000 --- a/core/modules/system/tests/modules/system_incompatible_core_version_test/system_incompatible_core_version_test.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: 'System incompatible core version test' -type: module -description: 'Support module for testing system dependencies.' -package: Testing -version: VERSION -core: 5.x diff --git a/core/modules/system/tests/modules/system_incompatible_core_version_test_1x/system_incompatible_core_version_test_1x.info.yml b/core/modules/system/tests/modules/system_incompatible_core_version_test_1x/system_incompatible_core_version_test_1x.info.yml deleted file mode 100644 index f79d71dff8..0000000000 --- a/core/modules/system/tests/modules/system_incompatible_core_version_test_1x/system_incompatible_core_version_test_1x.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: 'System incompatible core 1.x version test' -type: module -description: 'Support module for testing system core incompatibility.' -package: Testing -version: 1.0.0 -core: 1.x diff --git a/core/modules/system/tests/modules/system_test/system_test.module b/core/modules/system/tests/modules/system_test/system_test.module index e206ae978b..0e6f41352d 100644 --- a/core/modules/system/tests/modules/system_test/system_test.module +++ b/core/modules/system/tests/modules/system_test/system_test.module @@ -70,8 +70,6 @@ function system_test_system_info_alter(&$info, Extension $file, $type) { 'system_incompatible_module_version_dependencies_test', 'system_incompatible_core_version_dependencies_test', 'system_incompatible_module_version_test', - 'system_incompatible_core_version_test', - 'system_incompatible_core_version_test_1x', ])) { $info['hidden'] = FALSE; } diff --git a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php index 678353a583..460efa725c 100644 --- a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php +++ b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php @@ -56,29 +56,66 @@ public function testModuleListForm() { $this->assertText('dblog'); } + /** + * Tests the module form with modules with invalid info.yml files. + */ public function testModulesListFormWithInvalidInfoFile() { - $broken_info_yml = <<getParameter('site.path') . "/modules/broken"; mkdir($path, 0777, TRUE); - file_put_contents("$path/broken.info.yml", $broken_info_yml); - - $this->drupalLogin( - $this->drupalCreateUser( - ['administer modules', 'administer permissions'] - ) - ); - $this->drupalGet('admin/modules'); - $this->assertSession()->statusCodeEquals(200); - - // Confirm that the error message is shown. - $this->assertSession() - ->pageTextContains("The 'core' or the 'core_version_requirement' key must be present in " . $path . '/broken.info.yml'); + $file_path = "$path/broken.info.yml"; - // Check that the module filter text box is available. - $this->assertSession()->elementExists('xpath', '//input[@name="text"]'); + $broken_infos = [ + 'no core_version_requirement' => [ + 'yml' => << "The 'core_version_requirement' key must be present in $file_path", + ], + [ + 'yml' => << "The 'core_version_requirement' key must be present in $file_path", + ], + [ + 'yml' => << "'core: 9.x' is not supported. Use 'core_version_requirement' to specify core compatibility in $file_path", + ], + ]; + + foreach ($broken_infos as $broken_info) { + file_put_contents($file_path, $broken_info['yml']); + $this->drupalLogin( + $this->drupalCreateUser( + ['administer modules', 'administer permissions'] + ) + ); + $this->drupalGet('admin/modules'); + $this->assertSession()->statusCodeEquals(200); + + // Confirm that the error message is shown. + $this->assertSession() + ->pageTextContains('Modules could not be listed due to an error: ' . $broken_info['expected_error']); + + // Check that the module filter text box is available. + $this->assertSession()->elementExists('xpath', '//input[@name="text"]'); + + unlink($file_path); + $this->drupalGet('admin/modules'); + $this->assertSession()->statusCodeEquals(200); + + // Check that the module filter text box is available. + $this->assertSession()->elementExists('xpath', '//input[@name="text"]'); + $this->assertSession()->pageTextNotContains('Modules could not be listed due to an error'); + } } } diff --git a/core/modules/system/tests/src/Functional/Module/DependencyTest.php b/core/modules/system/tests/src/Functional/Module/DependencyTest.php index 2c1530790c..c5027c37fd 100644 --- a/core/modules/system/tests/src/Functional/Module/DependencyTest.php +++ b/core/modules/system/tests/src/Functional/Module/DependencyTest.php @@ -91,7 +91,7 @@ public function testIncompatibleCoreVersionDependency() { // marked as having an incompatible dependency. $this->drupalGet('admin/modules'); $this->assertRaw(t('@module (incompatible with this version of Drupal core)', [ - '@module' => 'System incompatible core version test', + '@module' => 'System core incompatible semver test', ]), 'A module that depends on a module with an incompatible core version is marked as such.'); $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_core_version_dependencies_test][enable]"]'); $this->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.'); @@ -115,7 +115,6 @@ public function testCoreCompatibility() { // Test incompatible 'core_version_requirement'. $this->drupalGet('admin/modules'); - $assert_session->fieldDisabled('modules[system_incompatible_core_version_test_1x][enable]'); $assert_session->fieldDisabled('modules[system_core_incompatible_semver_test][enable]'); // Test compatible 'core_version_requirement' and compatible 'core'. diff --git a/core/modules/system/tests/src/Functional/System/ThemeTest.php b/core/modules/system/tests/src/Functional/System/ThemeTest.php index 2a7b5f898c..db473afc7a 100644 --- a/core/modules/system/tests/src/Functional/System/ThemeTest.php +++ b/core/modules/system/tests/src/Functional/System/ThemeTest.php @@ -376,7 +376,6 @@ public function testInvalidTheme() { // Check for the error text of a theme with the wrong core version // using 7.x and ^7. $incompatible_core_message = 'This theme is not compatible with Drupal ' . \Drupal::VERSION . ". Check that the .info.yml file contains a compatible 'core' or 'core_version_requirement' value."; - $this->assertThemeIncompatibleText('Theme test with invalid core version', $incompatible_core_message); $this->assertThemeIncompatibleText('Theme test with invalid semver core version', $incompatible_core_message); // Check for the error text of a theme without a content region. $this->assertText("This theme is missing a 'content' region."); diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php index e98462fdbe..d5c3b966ec 100644 --- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php +++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php @@ -240,17 +240,6 @@ public function providerExtensionCompatibilityChange() { $incompatible_module_message = "The following module is installed, but it is incompatible with Drupal " . \Drupal::VERSION . ":"; $incompatible_theme_message = "The following theme is installed, but it is incompatible with Drupal " . \Drupal::VERSION . ":"; return [ - 'module: core key incompatible' => [ - [ - 'core_version_requirement' => '^8 || ^9', - 'type' => 'module', - ], - [ - 'core' => '7.x', - 'type' => 'module', - ], - $incompatible_module_message, - ], 'module: core_version_requirement key incompatible' => [ [ 'core_version_requirement' => '^8 || ^9', @@ -262,17 +251,6 @@ public function providerExtensionCompatibilityChange() { ], $incompatible_module_message, ], - 'theme: core key incompatible' => [ - [ - 'core_version_requirement' => '^8 || ^9', - 'type' => 'theme', - ], - [ - 'core' => '7.x', - 'type' => 'theme', - ], - $incompatible_theme_message, - ], 'theme: core_version_requirement key incompatible' => [ [ 'core_version_requirement' => '^8 || ^9', diff --git a/core/modules/system/tests/themes/test_invalid_core/test_invalid_core.info.yml b/core/modules/system/tests/themes/test_invalid_core/test_invalid_core.info.yml deleted file mode 100644 index 3ac1e2017a..0000000000 --- a/core/modules/system/tests/themes/test_invalid_core/test_invalid_core.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: 'Theme test with invalid core version' -type: theme -base theme: stable -description: 'Test theme which has an invalid core version.' -version: VERSION -core: 7.x diff --git a/core/modules/system/tests/themes/test_legacy_stylesheets_remove/test_legacy_stylesheets_remove.info.yml b/core/modules/system/tests/themes/test_legacy_stylesheets_remove/test_legacy_stylesheets_remove.info.yml index d5042ce2c2..6cd835e4d5 100644 --- a/core/modules/system/tests/themes/test_legacy_stylesheets_remove/test_legacy_stylesheets_remove.info.yml +++ b/core/modules/system/tests/themes/test_legacy_stylesheets_remove/test_legacy_stylesheets_remove.info.yml @@ -2,8 +2,8 @@ name: 'Theme Legacy Test Stylesheets Remove' type: theme description: 'Test theme using legacy stylesheets-remove.' version: VERSION -core: 8.x base theme: classy +package: Testing libraries: { } stylesheets-remove: - '@classy/css/components/action-links.css' diff --git a/core/modules/system/tests/themes/test_legacy_theme/test_legacy_theme.info.yml b/core/modules/system/tests/themes/test_legacy_theme/test_legacy_theme.info.yml index d49d40105f..e168af31c7 100644 --- a/core/modules/system/tests/themes/test_legacy_theme/test_legacy_theme.info.yml +++ b/core/modules/system/tests/themes/test_legacy_theme/test_legacy_theme.info.yml @@ -2,5 +2,5 @@ name: 'Test legacy theme' type: theme description: 'Test theme to test deprecated functionality.' version: VERSION -core: 8.x +package: Testing base theme: test_theme diff --git a/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.info.yml b/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.info.yml index fbac46814d..70b9397b3b 100644 --- a/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.info.yml +++ b/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.info.yml @@ -2,5 +2,5 @@ name: 'Theme test subtheme' type: theme description: 'Test theme which uses test_basetheme as the base theme.' version: VERSION -core: 8.x base theme: classy +package: Testing diff --git a/core/tests/Drupal/FunctionalTests/Installer/SingleVisibleProfileTest.php b/core/tests/Drupal/FunctionalTests/Installer/SingleVisibleProfileTest.php index 02e60a817e..e632f8dcb7 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/SingleVisibleProfileTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/SingleVisibleProfileTest.php @@ -34,7 +34,7 @@ protected function prepareEnvironment() { foreach ($profiles as $profile) { $info = [ 'type' => 'profile', - 'core' => \Drupal::CORE_COMPATIBILITY, + 'core_version_requirement' => '^8 || ^9 || ^10', 'name' => 'Override ' . $profile, 'hidden' => TRUE, ]; diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php index 8c94c70620..696a4f798b 100644 --- a/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php @@ -103,14 +103,6 @@ public function testInvalidCoreInstall($module_name, $install_dependencies) { */ public function providerTestInvalidCoreInstall() { return [ - 'no dependencies system_incompatible_core_version_test_1x' => [ - 'system_incompatible_core_version_test_1x', - FALSE, - ], - 'install_dependencies system_incompatible_core_version_test_1x' => [ - 'system_incompatible_core_version_test_1x', - TRUE, - ], 'no dependencies system_core_incompatible_semver_test' => [ 'system_core_incompatible_semver_test', FALSE, @@ -129,7 +121,7 @@ public function providerTestInvalidCoreInstall() { */ public function testDependencyInvalidCoreInstall() { $this->expectException(MissingDependencyException::class); - $this->expectExceptionMessage("Unable to install modules: module 'system_incompatible_core_version_dependencies_test'. Its dependency module 'system_incompatible_core_version_test' is incompatible with this version of Drupal core."); + $this->expectExceptionMessage("Unable to install modules: module 'system_incompatible_core_version_dependencies_test'. Its dependency module 'system_core_incompatible_semver_test' is incompatible with this version of Drupal core."); $this->container->get('module_installer')->install(['system_incompatible_core_version_dependencies_test']); } diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php index 16e5ad5a4c..b6d4f67b56 100644 --- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php @@ -125,7 +125,7 @@ public function testMissingCoreCoreVersionRequirement() { 'missing_core_and_core_version_requirement-duplicate.info.txt' => $missing_core_and_core_version_requirement, ], ]); - $exception_message = "The 'core' or the 'core_version_requirement' key must be present in vfs://modules/fixtures/missing_core_and_core_version_requirement"; + $exception_message = "The 'core_version_requirement' key must be present in vfs://modules/fixtures/missing_core_and_core_version_requirement"; // Set the expected exception for the 2nd call to parse(). $this->expectException('\Drupal\Core\Extension\InfoParserException'); $this->expectExceptionMessage("$exception_message-duplicate.info.txt"); @@ -237,12 +237,15 @@ public function testCoreCoreVersionRequirement88() { * Tests a invalid 'core' key. * * @covers ::parse + * + * @dataProvider providerInvalidCore */ - public function testInvalidCore() { + public function testInvalidCore($core, $filename) { $invalid_core = << [ - 'invalid_core.info.txt' => $invalid_core, - 'invalid_core-duplicate.info.txt' => $invalid_core, + "invalid_core-$filename.info.txt" => $invalid_core, + "invalid_core-$filename-duplicate.info.txt" => $invalid_core, ], ]); - $exception_message = "Invalid 'core' value \"^8\" in vfs://modules/fixtures/invalid_core"; + $exception_message = "'core: {$core}' is not supported. Use 'core_version_requirement' to specify core compatibility in vfs://modules/fixtures/invalid_core-$filename"; // Set the expected exception for the 2nd call to parse(). $this->expectException('\Drupal\Core\Extension\InfoParserException'); $this->expectExceptionMessage("$exception_message-duplicate.info.txt"); try { - $this->infoParser->parse(vfsStream::url('modules/fixtures/invalid_core.info.txt')); + $this->infoParser->parse(vfsStream::url("modules/fixtures/invalid_core-$filename.info.txt")); } catch (InfoParserException $exception) { $this->assertSame("$exception_message.info.txt", $exception->getMessage()); - $this->infoParser->parse(vfsStream::url('modules/fixtures/invalid_core-duplicate.info.txt')); + $this->infoParser->parse(vfsStream::url("modules/fixtures/invalid_core-$filename-duplicate.info.txt")); } } + public function providerInvalidCore() { + return [ + '^8' => [ + '^8', + 'caret8', + ], + '^9' => [ + '^9', + 'caret', + ], + '7.x' => [ + '7.x', + '7.x', + ], + '9.x' => [ + '9.x', + '9.x', + ], + '10.x' => [ + '10.x', + '10.x', + ], + ]; + } + + /** + * Tests a 'core: 8.x' with different values for 'core_version_requirement'. + * + * @covers ::parse + * + * @dataProvider providerCore8x + */ + public function testCore8x($core_version_requirement, $filename) { + $core_8x = << [ + "core_8x-$filename.info.txt" => $core_8x, + "core_8x-$filename-duplicate.info.txt" => $core_8x, + ], + ]); + $parsed = $this->infoParser->parse(vfsStream::url("modules/fixtures/core_8x-$filename.info.txt")); + $this->assertSame($core_version_requirement, $parsed['core_version_requirement']); + $this->infoParser->parse(vfsStream::url("modules/fixtures/core_8x-$filename-duplicate.info.txt")); + $this->assertSame($core_version_requirement, $parsed['core_version_requirement']); + } + + /** + * Dataprovider for testCore8x(). + */ + public function providerCore8x() { + return [ + '^8 || ^9' => [ + '^8 || ^9', + 'all-8-9', + ], + '*' => [ + '*', + 'asterisk', + ], + '>=8' => [ + ">=8", + 'gte8', + ], + ]; + } + + /** + * Tests setting the 'core' key without the 'core_version_requirement' key. + * + * @covers ::parse + * + * @dataProvider providerCoreWithoutCoreVersionRequirement + */ + public function testCoreWithoutCoreVersionRequirement($core) { + $core_without_core_version_requirement = << [ + "core_without_core_version_requirement-$core.info.txt" => $core_without_core_version_requirement, + "core_without_core_version_requirement-$core-duplicate.info.txt" => $core_without_core_version_requirement, + ], + ]); + $exception_message = "The 'core_version_requirement' key must be present in vfs://modules/fixtures/core_without_core_version_requirement-$core"; + // Set the expected exception for the 2nd call to parse(). + $this->expectException('\Drupal\Core\Extension\InfoParserException'); + $this->expectExceptionMessage("$exception_message-duplicate.info.txt"); + + try { + $this->infoParser->parse(vfsStream::url("modules/fixtures/core_without_core_version_requirement-$core.info.txt")); + } + catch (InfoParserException $exception) { + $this->assertSame("$exception_message.info.txt", $exception->getMessage()); + $this->infoParser->parse(vfsStream::url("modules/fixtures/core_without_core_version_requirement-$core-duplicate.info.txt")); + } + } + + /** + * DataProvider for testCoreWithoutCoreVersionRequirement(). + */ + public function providerCoreWithoutCoreVersionRequirement() { + return [ + '7.x' => ['7.x'], + '8.x' => ['8.x'], + '9.x' => ['9.x'], + '10.x' => ['10.x'], + ]; + } + /** * Tests a invalid 'core_version_requirement'. *