diff --git a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php index 7189560d17202a2609b8803ef42f277b1abe6586..bcdb294f2c0973ab71a4ab3de2f1ad3ba08354d9 100644 --- a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php +++ b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php @@ -18,11 +18,6 @@ class InfoParserDynamic implements InfoParserInterface { */ protected $root; - /** - * The earliest Drupal version that supports the 'core_version_requirement'. - */ - const FIRST_CORE_VERSION_REQUIREMENT_SUPPORTED_VERSION = '8.7.7'; - /** * InfoParserDynamic constructor. * @@ -68,42 +63,20 @@ public function parse($filename) { // easier for contrib to use test modules. $parsed_info['core_version_requirement'] = \Drupal::VERSION; } - elseif (!isset($parsed_info['core'])) { + else { // Non-core extensions must specify core compatibility. throw new InfoParserException("The 'core_version_requirement' key must be present 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); - } - catch (\UnexpectedValueException $e) { - throw new InfoParserException("The 'core_version_requirement' constraint ({$parsed_info['core_version_requirement']}) is not a valid value in $filename"); - } - // If the 'core_version_requirement' constraint does not satisfy any - // Drupal 8 versions before 8.7.7 then 'core' cannot be set or it will - // effectively support all versions of Drupal 8 because - // 'core_version_requirement' will be ignored in previous versions. - if (!$supports_pre_core_version_requirement_version && isset($parsed_info['core'])) { - throw new InfoParserException("The 'core_version_requirement' constraint ({$parsed_info['core_version_requirement']}) requires the 'core' key not be set in " . $filename); - } - // 'core_version_requirement' can not be used to specify Drupal 8 - // versions before 8.7.7 because these versions do not use the - // 'core_version_requirement' key. Do not throw the exception if the - // constraint also is satisfied by 8.0.0-alpha1 to allow constraints - // such as '^8' or '^8 || ^9'. - if ($supports_pre_core_version_requirement_version && !Semver::satisfies('8.0.0-alpha1', $parsed_info['core_version_requirement'])) { - 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. Only 'core: 8.x' is supported to provide backwards compatibility for Drupal 8 when needed in $filename"); - } // Determine if the extension is compatible with the current version of // Drupal core. - $core_version_constraint = $parsed_info['core_version_requirement'] ?? $parsed_info['core']; - $parsed_info['core_incompatible'] = !Semver::satisfies(\Drupal::VERSION, $core_version_constraint); + try { + $parsed_info['core_incompatible'] = !Semver::satisfies(\Drupal::VERSION, $parsed_info['core_version_requirement']); + } + catch (\UnexpectedValueException $exception) { + throw new InfoParserException("The 'core_version_requirement' constraint ({$parsed_info['core_version_requirement']}) is not a valid value in $filename"); + } if (isset($parsed_info['version']) && $parsed_info['version'] === 'VERSION') { $parsed_info['version'] = \Drupal::VERSION; } @@ -140,77 +113,4 @@ protected function getRequiredKeys() { return ['type', 'name']; } - /** - * Determines if a constraint is satisfied by earlier versions of Drupal 8. - * - * @param string $constraint - * A core semantic version constraint. - * @param string $version - * A core version. - * - * @return bool - * TRUE if the constraint is satisfied by a core version prior to the - * provided version. - */ - protected static function isConstraintSatisfiedByPreviousVersion($constraint, $version) { - static $evaluated_constraints = []; - // Any particular constraint and version combination only needs to be - // evaluated once. - if (!isset($evaluated_constraints[$constraint][$version])) { - $evaluated_constraints[$constraint][$version] = FALSE; - foreach (static::getAllPreviousCoreVersions($version) as $previous_version) { - if (Semver::satisfies($previous_version, $constraint)) { - $evaluated_constraints[$constraint][$version] = TRUE; - // The constraint only has to satisfy one previous version so break - // when the first one is found. - break; - } - } - } - return $evaluated_constraints[$constraint][$version]; - } - - /** - * Gets all the versions of Drupal 8 before a specific version. - * - * @param string $version - * The version to get versions before. - * - * @return array - * All of the applicable Drupal 8 releases. - */ - protected static function getAllPreviousCoreVersions($version) { - static $versions_lists = []; - // Check if list of previous versions for the specified version has already - // been created. - if (empty($versions_lists[$version])) { - // Loop through all minor versions including 8.7. - foreach (range(0, 7) as $minor) { - // The largest patch number in a release was 17 in 8.6.17. Use 27 to - // leave room for future security releases. - foreach (range(0, 27) as $patch) { - $patch_version = "8.$minor.$patch"; - if ($patch_version === $version) { - // Reverse the order of the versions so that they will be evaluated - // from the most recent versions first. - $versions_lists[$version] = array_reverse($versions_lists[$version]); - return $versions_lists[$version]; - } - if ($patch === 0) { - // If this is a '0' patch release like '8.1.0' first create the - // pre-release versions such as '8.1.0-alpha1' and '8.1.0-rc1'. - foreach (['alpha', 'beta', 'rc'] as $prerelease) { - // The largest prerelease number was in 8.0.0-beta16. - foreach (range(0, 16) as $prerelease_number) { - $versions_lists[$version][] = "$patch_version-$prerelease$prerelease_number"; - } - } - } - $versions_lists[$version][] = $patch_version; - } - } - } - return $versions_lists[$version]; - } - } diff --git a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php index e8b941a91918310080fc4593ad980625aecaae35..1e4678c60dc8b3bef068926229dc8bc6f918221e 100644 --- a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php +++ b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php @@ -89,60 +89,36 @@ public function testModulesListFormStatusMessage() { } /** - * Tests the module form with modules with invalid info.yml files. + * Tests the module form with a module with an invalid info.yml file. */ public function testModulesListFormWithInvalidInfoFile() { $path = \Drupal::getContainer()->getParameter('site.path') . "/modules/broken"; mkdir($path, 0777, TRUE); $file_path = "$path/broken.info.yml"; - $broken_infos = [ - [ - 'yml' => <<<BROKEN -name: Module with no core_version_requirement or core + $yml = <<<BROKEN +name: Module with no core_version_requirement type: module -BROKEN, - 'expected_error' => "The 'core_version_requirement' key must be present in $file_path", - ], - [ - 'yml' => <<<BROKEN -name: Module no core_version_requirement and invalid core -type: module -core: 9.x -BROKEN, - 'expected_error' => "'core: 9.x' is not supported. Use 'core_version_requirement' to specify core compatibility. Only 'core: 8.x' is supported to provide backwards compatibility for Drupal 8 when needed in $file_path", - ], - [ - 'yml' => <<<BROKEN -name: Module with core_version_requirement and invalid core -type: module -core: 9.x -core_version_requirement: ^8 || ^9 -BROKEN, - 'expected_error' => "'core: 9.x' is not supported. Use 'core_version_requirement' to specify core compatibility. Only 'core: 8.x' is supported to provide backwards compatibility for Drupal 8 when needed in $file_path", - ], - ]; +BROKEN; - foreach ($broken_infos as $broken_info) { - file_put_contents($file_path, $broken_info['yml']); + file_put_contents($file_path, $yml); - $this->drupalGet('admin/modules'); - $this->assertSession()->statusCodeEquals(200); + $this->drupalGet('admin/modules'); + $this->assertSession()->statusCodeEquals(200); - $this->assertSession() - ->pageTextContains('Modules could not be listed due to an error: ' . $broken_info['expected_error']); + $this->assertSession() + ->pageTextContains("Modules could not be listed due to an error: The 'core_version_requirement' key must be present in $file_path"); - // Check that the module filter text box is available. - $this->assertSession()->elementExists('xpath', '//input[@name="text"]'); + // 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); + 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'); - } + // 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'); } /** @@ -171,6 +147,7 @@ public function testInstalledIncompatibleModule() { 'type' => 'module', ]; $compatible_info = $info + ['core_version_requirement' => '*']; + $incompatible_info = $info + ['core_version_requirement' => '^1']; file_put_contents($file_path, Yaml::encode($compatible_info)); $edit = ['modules[changing_module][enable]' => 'changing_module']; @@ -178,24 +155,14 @@ public function testInstalledIncompatibleModule() { $this->submitForm($edit, 'Install'); $this->assertSession()->pageTextContains('Module Module that changes has been enabled.'); - $incompatible_updates = [ - [ - 'core_version_requirement' => '^1', - ], - [ - 'core' => '8.x', - ], - ]; - foreach ($incompatible_updates as $incompatible_update) { - $incompatible_info = $info + $incompatible_update; - file_put_contents($file_path, Yaml::encode($incompatible_info)); - $this->drupalGet('admin/modules'); - $this->assertSession()->pageTextContains($incompatible_modules_message); - - file_put_contents($file_path, Yaml::encode($compatible_info)); - $this->drupalGet('admin/modules'); - $this->assertSession()->pageTextNotContains($incompatible_modules_message); - } + file_put_contents($file_path, Yaml::encode($incompatible_info)); + $this->drupalGet('admin/modules'); + $this->assertSession()->pageTextContains($incompatible_modules_message); + + file_put_contents($file_path, Yaml::encode($compatible_info)); + $this->drupalGet('admin/modules'); + $this->assertSession()->pageTextNotContains($incompatible_modules_message); + // Uninstall the module and ensure that incompatible modules message is not // displayed for modules that are not installed. $edit = ['uninstall[changing_module]' => 'changing_module']; @@ -203,12 +170,10 @@ public function testInstalledIncompatibleModule() { $this->submitForm($edit, 'Uninstall'); $this->submitForm([], 'Uninstall'); $this->assertSession()->pageTextContains('The selected modules have been uninstalled.'); - foreach ($incompatible_updates as $incompatible_update) { - $incompatible_info = $info + $incompatible_update; - file_put_contents($file_path, Yaml::encode($incompatible_info)); - $this->drupalGet('admin/modules'); - $this->assertSession()->pageTextNotContains($incompatible_modules_message); - } + + file_put_contents($file_path, Yaml::encode($incompatible_info)); + $this->drupalGet('admin/modules'); + $this->assertSession()->pageTextNotContains($incompatible_modules_message); } } diff --git a/core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php b/core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php index 98388dbd1462c87d8380d610366a3b5ea54b95ed..4be6b94fa0f82ae7069254c16fd77c4fde77e35d 100644 --- a/core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php +++ b/core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php @@ -342,6 +342,7 @@ public function testInstalledIncompatibleTheme() { ]; $compatible_info = $info + ['core_version_requirement' => '*']; + $incompatible_info = $info + ['core_version_requirement' => '^1']; file_put_contents($file_path, Yaml::encode($compatible_info)); $this->drupalGet('admin/appearance'); @@ -350,33 +351,21 @@ public function testInstalledIncompatibleTheme() { $assert_session->addressEquals('admin/appearance'); $assert_session->pageTextContains("The $theme_name theme has been installed"); - $incompatible_updates = [ - [ - 'core_version_requirement' => '^1', - ], - [ - 'core' => '8.x', - ], - ]; - foreach ($incompatible_updates as $incompatible_update) { - $incompatible_info = $info + $incompatible_update; - file_put_contents($file_path, Yaml::encode($incompatible_info)); - $this->drupalGet('admin/appearance'); - $this->assertSession()->pageTextContains($incompatible_themes_message); - - file_put_contents($file_path, Yaml::encode($compatible_info)); - $this->drupalGet('admin/appearance'); - $this->assertSession()->pageTextNotContains($incompatible_themes_message); - } + file_put_contents($file_path, Yaml::encode($incompatible_info)); + $this->drupalGet('admin/appearance'); + $this->assertSession()->pageTextContains($incompatible_themes_message); + + file_put_contents($file_path, Yaml::encode($compatible_info)); + $this->drupalGet('admin/appearance'); + $this->assertSession()->pageTextNotContains($incompatible_themes_message); + // Uninstall the theme and ensure that incompatible themes message is not // displayed for themes that are not installed. $this->uninstallTheme($theme_name); - foreach ($incompatible_updates as $incompatible_update) { - $incompatible_info = $info + $incompatible_update; - file_put_contents($file_path, Yaml::encode($incompatible_info)); - $this->drupalGet('admin/appearance'); - $this->assertSession()->pageTextNotContains($incompatible_themes_message); - } + + file_put_contents($file_path, Yaml::encode($incompatible_info)); + $this->drupalGet('admin/appearance'); + $this->assertSession()->pageTextNotContains($incompatible_themes_message); } } diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php index 5e1088e0943346c1bdc3a92edcdd251d4d76d7d4..3f99ff814ccefb927d89387bd5d7a9cd1d66882d 100644 --- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php +++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php @@ -325,28 +325,6 @@ public function providerExtensionCompatibilityChange() { ], 'The following theme is installed, but it is incompatible with PHP ' . phpversion() . ":", ], - 'module: core_version_requirement key missing' => [ - [ - 'core_version_requirement' => '>= 8', - 'type' => 'module', - ], - [ - 'core' => '8.x', - 'type' => 'module', - ], - $incompatible_module_message, - ], - 'theme: core_version_requirement key missing' => [ - [ - 'core_version_requirement' => '>= 8', - 'type' => 'theme', - ], - [ - 'core' => '8.x', - 'type' => 'theme', - ], - $incompatible_theme_message, - ], ]; } diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php index 96fd9fd76a2052be552926e78ea4eb15be45d6bd..a7dad625b6d78eaea317d1e523876c355bc5ddb4 100644 --- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php @@ -61,7 +61,7 @@ public function testInfoParserBroken() { description: 'Defines a file field type.' package: Core version: VERSION -core: 8.x +core_version_requirement: '*' dependencies::;; - field BROKEN_INFO; @@ -105,39 +105,39 @@ public function testInfoParserMissingKeys() { } /** - * Tests that missing 'core' and 'core_version_requirement' keys are detected. + * Tests that a missing 'core_version_requirement' key is detected. * * @covers ::parse */ - public function testMissingCoreCoreVersionRequirement() { - $missing_core_and_core_version_requirement = <<<MISSING_CORE_AND_CORE_VERSION_REQUIREMENT -# info.yml for testing core and core_version_requirement. + public function testMissingCoreVersionRequirement() { + $missing_core_version_requirement = <<<MISSING_CORE_VERSION_REQUIREMENT +# info.yml for testing core_version_requirement. version: VERSION type: module name: Skynet dependencies: - self_awareness -MISSING_CORE_AND_CORE_VERSION_REQUIREMENT; +MISSING_CORE_VERSION_REQUIREMENT; vfsStream::setup('modules'); vfsStream::create([ 'fixtures' => [ - 'missing_core_and_core_version_requirement.info.txt' => $missing_core_and_core_version_requirement, - 'missing_core_and_core_version_requirement-duplicate.info.txt' => $missing_core_and_core_version_requirement, + 'missing_core_version_requirement.info.txt' => $missing_core_version_requirement, + 'missing_core_version_requirement-duplicate.info.txt' => $missing_core_version_requirement, ], ]); - $exception_message = "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_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"); try { - $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_core_and_core_version_requirement.info.txt')); + $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_core_version_requirement.info.txt')); } catch (InfoParserException $exception) { $this->assertSame("$exception_message.info.txt", $exception->getMessage()); - $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_core_and_core_version_requirement-duplicate.info.txt')); + $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_core_version_requirement-duplicate.info.txt')); } } @@ -146,316 +146,25 @@ public function testMissingCoreCoreVersionRequirement() { * * @covers ::parse */ - public function testTestingPackageMissingCoreCoreVersionRequirement() { - $missing_core_and_core_version_requirement = <<<MISSING_CORE_AND_CORE_VERSION_REQUIREMENT -# info.yml for testing core and core_version_requirement. + public function testTestingPackageMissingCoreVersionRequirement() { + $missing_core_version_requirement = <<<MISSING_CORE_VERSION_REQUIREMENT +# info.yml for testing core_version_requirement. package: Testing version: VERSION type: module name: Skynet -MISSING_CORE_AND_CORE_VERSION_REQUIREMENT; +MISSING_CORE_VERSION_REQUIREMENT; vfsStream::setup('modules'); vfsStream::create([ 'fixtures' => [ - 'missing_core_and_core_version_requirement.info.txt' => $missing_core_and_core_version_requirement, + 'missing_core_version_requirement.info.txt' => $missing_core_version_requirement, ], ]); - $info_values = $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_core_and_core_version_requirement.info.txt')); + $info_values = $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_core_version_requirement.info.txt')); $this->assertSame($info_values['core_version_requirement'], \Drupal::VERSION); } - /** - * Tests that 'core_version_requirement: ^8.8' is valid with no 'core' key. - * - * @covers ::parse - */ - public function testCoreVersionRequirement88() { - $core_version_requirement = <<<BOTH_CORE_VERSION_REQUIREMENT -# info.yml for testing core and core_version_requirement keys. -package: Core -core_version_requirement: ^8.8 -version: VERSION -type: module -name: Module for That -dependencies: - - field -BOTH_CORE_VERSION_REQUIREMENT; - - vfsStream::setup('modules'); - foreach (['1', '2'] as $file_delta) { - $filename = "core_version_requirement-$file_delta.info.txt"; - vfsStream::create([ - 'fixtures' => [ - $filename => $core_version_requirement, - ], - ]); - $info_values = $this->infoParser->parse(vfsStream::url("modules/fixtures/$filename")); - $this->assertSame($info_values['core_version_requirement'], '^8.8', "Expected core_version_requirement for file: $filename"); - } - } - - /** - * Tests that 'core_version_requirement: ^8.8' is invalid with a 'core' key. - * - * @covers ::parse - */ - public function testCoreCoreVersionRequirement88() { - $core_and_core_version_requirement_88 = <<<BOTH_CORE_CORE_VERSION_REQUIREMENT_88 -# info.yml for testing core and core_version_requirement keys. -package: Core -core: 8.x -core_version_requirement: ^8.8 -version: VERSION -type: module -name: Form auto submitter -dependencies: - - field -BOTH_CORE_CORE_VERSION_REQUIREMENT_88; - - vfsStream::setup('modules'); - vfsStream::create([ - 'fixtures' => [ - 'core_and_core_version_requirement_88.info.txt' => $core_and_core_version_requirement_88, - 'core_and_core_version_requirement_88-duplicate.info.txt' => $core_and_core_version_requirement_88, - ], - ]); - $exception_message = "The 'core_version_requirement' constraint (^8.8) requires the 'core' key not be set in vfs://modules/fixtures/core_and_core_version_requirement_88"; - // 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_and_core_version_requirement_88.info.txt')); - } - catch (InfoParserException $exception) { - $this->assertSame("$exception_message.info.txt", $exception->getMessage()); - - $this->infoParser->parse(vfsStream::url('modules/fixtures/core_and_core_version_requirement_88-duplicate.info.txt')); - } - } - - /** - * Tests a invalid 'core' key. - * - * @covers ::parse - * - * @dataProvider providerInvalidCore - */ - public function testInvalidCore($core, $filename) { - $invalid_core = <<<INVALID_CORE -# info.yml for testing invalid core key. -package: Core -core: $core -core_version_requirement: ^8 || ^9 -version: VERSION -type: module -name: Llama or Alpaca -description: Tells whether an image is of a Llama or Alpaca -dependencies: - - llama_detector - - alpaca_detector -INVALID_CORE; - - vfsStream::setup('modules'); - vfsStream::create([ - 'fixtures' => [ - "invalid_core-$filename.info.txt" => $invalid_core, - "invalid_core-$filename-duplicate.info.txt" => $invalid_core, - ], - ]); - $exception_message = "'core: {$core}' is not supported. Use 'core_version_requirement' to specify core compatibility. Only 'core: 8.x' is supported to provide backwards compatibility for Drupal 8 when needed 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-$filename.info.txt")); - } - catch (InfoParserException $exception) { - $this->assertSame("$exception_message.info.txt", $exception->getMessage()); - - $this->infoParser->parse(vfsStream::url("modules/fixtures/invalid_core-$filename-duplicate.info.txt")); - } - } - - public function providerInvalidCore() { - return [ - '^8' => [ - '^8', - 'caret8', - ], - '^9' => [ - '^9', - 'caret9', - ], - '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 -package: Tests -core: 8.x -core_version_requirement: '$core_version_requirement' -version: VERSION -type: module -name: Yet another test module -description: Sorry, I am running out of witty descriptions -CORE_8X; - - vfsStream::setup('modules'); - vfsStream::create([ - 'fixtures' => [ - "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']); - } - - /** - * Data provider 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 -package: Dogs -core: $core -version: VERSION -type: module -name: Gracie Daily Picture -description: Shows a random picture of Gracie the Dog everyday. -CORE_WITHOUT_CORE_VERSION_REQUIREMENT; - - vfsStream::setup('modules'); - vfsStream::create([ - 'fixtures' => [ - "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 = "'core: $core' is not supported. Use 'core_version_requirement' to specify core compatibility. Only 'core: 8.x' is supported to provide backwards compatibility for Drupal 8 when needed 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'], - '9.x' => ['9.x'], - '10.x' => ['10.x'], - ]; - } - - /** - * Tests a invalid 'core_version_requirement'. - * - * @covers ::parse - * - * @dataProvider providerCoreVersionRequirementInvalid - */ - public function testCoreVersionRequirementInvalid($test_case, $constraint) { - $invalid_core_version_requirement = <<<INVALID_CORE_VERSION_REQUIREMENT -# info.yml for core_version_requirement validation. -name: Gracie Evaluator -description: 'Determines if Gracie is a "Good Dog". The answer is always "Yes".' -package: Core -type: module -version: VERSION -core_version_requirement: '$constraint' -dependencies: - - goodness_api -INVALID_CORE_VERSION_REQUIREMENT; - - vfsStream::setup('modules'); - vfsStream::create([ - 'fixtures' => [ - "invalid_core_version_requirement-$test_case.info.txt" => $invalid_core_version_requirement, - "invalid_core_version_requirement-$test_case-duplicate.info.txt" => $invalid_core_version_requirement, - ], - ]); - $exception_message = "The 'core_version_requirement' can not be used to specify compatibility for a specific version before 8.7.7 in vfs://modules/fixtures/invalid_core_version_requirement-$test_case"; - // 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_version_requirement-$test_case.info.txt")); - } - catch (InfoParserException $exception) { - $this->assertSame("$exception_message.info.txt", $exception->getMessage()); - - $this->infoParser->parse(vfsStream::url("modules/fixtures/invalid_core_version_requirement-$test_case-duplicate.info.txt")); - } - } - - /** - * Data provider for testCoreVersionRequirementInvalid(). - */ - public function providerCoreVersionRequirementInvalid() { - return [ - '8.0.0-alpha2' => ['alpha2', '8.0.0-alpha2'], - '8.6.0-rc1' => ['rc1', '8.6.0-rc1'], - '^8.7' => ['8_7', '^8.7'], - '>8.6.3' => ['gt8_6_3', '>8.6.3'], - ]; - } - /** * Tests that missing required key is detected. * @@ -468,7 +177,6 @@ public function testInfoParserMissingKey() { description: 'Defines a file field type.' package: Core version: VERSION -core: 8.x dependencies: - field MISSINGKEY; @@ -663,35 +371,6 @@ public function testUnparsableCoreVersionRequirement() { $this->infoParser->parse(vfsStream::url('modules/fixtures/unparsable_core_version_requirement.info.txt')); } - /** - * Tests an info file with 'core: 8.x' but without 'core_version_requirement'. - * - * @covers ::parse - */ - public function testCore8xNoCoreVersionRequirement() { - $info = <<<INFO -package: Core -core: 8.x -version: VERSION -type: module -name: Module for That -dependencies: - - field -INFO; - - vfsStream::setup('modules'); - foreach (['1', '2'] as $file_delta) { - $filename = "core_version_requirement-$file_delta.info.txt"; - vfsStream::create([ - 'fixtures' => [ - $filename => $info, - ], - ]); - $info_values = $this->infoParser->parse(vfsStream::url("modules/fixtures/$filename")); - $this->assertSame(TRUE, $info_values['core_incompatible'], "Expected 'core_incompatible's for file: $filename"); - } - } - /** * Tests an info file with valid lifecycle values. * @@ -702,7 +381,7 @@ public function testCore8xNoCoreVersionRequirement() { public function testValidLifecycle($lifecycle, $expected) { $info = <<<INFO package: Core -core: 8.x +core_version_requirement: '*' version: VERSION type: module name: Module for That @@ -762,7 +441,7 @@ public function providerValidLifecycle() { public function testInvalidLifecycle($lifecycle, $exception_message) { $info = <<<INFO package: Core -core: 8.x +core_version_requirement: '*' version: VERSION type: module name: Module for That @@ -811,7 +490,7 @@ public function providerInvalidLifecycle() { public function testLifecycleLink($lifecycle, $lifecycle_link = NULL, $exception_message = NULL) { $info = <<<INFO package: Core -core: 8.x +core_version_requirement: '*' version: VERSION type: module name: Module for That