diff --git a/core/modules/update/src/ModuleVersion.php b/core/modules/update/src/ModuleVersion.php index 94297824d9..96657948ef 100644 --- a/core/modules/update/src/ModuleVersion.php +++ b/core/modules/update/src/ModuleVersion.php @@ -160,18 +160,20 @@ public function getVersionExtra() { } /** - * Gets the support branch. + * Determines if the version is in a specific support branch. * - * @return string - * The support branch as is used in update XML files. + * @param string $support_branch + * The support branch. + * + * @return bool + * TRUE if the version is in the support branch, otherwise FALSE. */ - public function getSupportBranch() { - $branch = $this->useCorePrefix ? static::CORE_COMPATIBILITY_PREFIX : ''; - $branch .= $this->majorVersion . '.'; - if ($this->minorVersion !== NULL) { - $branch .= $this->minorVersion . '.'; + public function isInSupportBranch($support_branch) { + $branch_version = static::createFromSupportBranch($support_branch); + if ($branch_version->minorVersion === NULL) { + return $this->getMajorVersion() === $branch_version->getMajorVersion(); } - return $branch; + return $this->getMajorVersion() === $branch_version->getMajorVersion() && $this->getMinorVersion() === $branch_version->getMinorVersion(); } } diff --git a/core/modules/update/tests/src/Unit/ModuleVersionTest.php b/core/modules/update/tests/src/Unit/ModuleVersionTest.php index dcb3c10e60..0a42f8c7c0 100644 --- a/core/modules/update/tests/src/Unit/ModuleVersionTest.php +++ b/core/modules/update/tests/src/Unit/ModuleVersionTest.php @@ -52,16 +52,6 @@ public function testGetVersionExtra($version, $expected_version_info) { $this->assertSame($expected_version_info['extra'], $version->getVersionExtra()); } - /** - * @covers ::getSupportBranch - * - * @dataProvider providerVersionInfos - */ - public function testGetSupportBranch($version, $expected_version_info) { - $version = ModuleVersion::createFromVersionString($version); - $this->assertSame($expected_version_info['branch'], $version->getSupportBranch()); - } - /** * @covers ::createFromSupportBranch * @@ -258,4 +248,51 @@ public function providerVersionInfos() { ]; } + /** + * @covers ::isInSupportBranch + * + * @dataProvider providerIsInSupportBranch + */ + public function testIsInSupportBranch($version, $branch, $expected_result) { + $this->assertEquals($expected_result, ModuleVersion::createFromVersionString($version)->isInSupportBranch($branch)); + } + + /** + * Data provider for testIsInSupportBranch(). + */ + public function providerIsInSupportBranch() { + return [ + [ + '1.2.3', + '1.', + TRUE, + ], + [ + '1.2.3', + '1.2.', + TRUE, + ], + [ + '1.2.3', + '1.3.', + FALSE, + ], + [ + '1.2.3', + '2.', + FALSE, + ], + [ + '1.2.3', + '2.2.', + FALSE, + ], + [ + '1.2.3', + '2.3.', + FALSE, + ], + ]; + } + } diff --git a/core/modules/update/update.compare.inc b/core/modules/update/update.compare.inc index ab191fed5b..71ac563939 100644 --- a/core/modules/update/update.compare.inc +++ b/core/modules/update/update.compare.inc @@ -261,7 +261,15 @@ function update_calculate_project_update_status(&$project_data, $available) { $supported_branches = explode(',', $available['supported_branches']); } - if (in_array($existing_module_version->getSupportBranch(), $supported_branches)) { + $is_in_supported_branch = function (ModuleVersion $version) use ($supported_branches) { + foreach ($supported_branches as $supported_branch) { + if ($version->isInSupportBranch($supported_branch)) { + return TRUE; + } + } + return FALSE; + }; + if ($is_in_supported_branch($existing_module_version)) { // Still supported, stay at the current major version. $target_major = $existing_major; } @@ -355,7 +363,7 @@ function update_calculate_project_update_status(&$project_data, $available) { // be one of those being compared. They would not have version_major // set, so we must call isset first. if ($release_major_version !== NULL && $release_major_version > $target_major) { - if (in_array($release_module_version->getSupportBranch(), $supported_branches)) { + if ($is_in_supported_branch($release_module_version)) { if (!isset($project_data['also'])) { $project_data['also'] = []; }