Skip to content
Snippets Groups Projects
Commit 7e612d8a authored by catch's avatar catch
Browse files

Issue #3261250 by andypost, longwave: Remove deprecated update.module functions

parent 4997bdb4
No related branches found
No related tags found
38 merge requests!7471uncessary 5 files are moved from media-library folder to misc folder,!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!3291Issue #3336463: Rewrite rules for gzipped CSS and JavaScript aggregates never match,!3143Issue #3313342: [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1 LayoutBuilderUiCacheContext.php on line 28,!3102Issue #3164428 by DonAtt, longwave, sahil.goyal, Anchal_gupta, alexpott: Use...,!2853#3274419 Makes BaseFieldOverride inherit the internal property from the base field.,!2719Issue #3110137: Remove Classy from core.,!2437Issue #3238257 by hooroomoo, Wim Leers: Fragment link pointing to <textarea>...,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2074Issue #2707689: NodeForm::actions() checks for delete access on new entities,!2062Issue #3246454: Add weekly granularity to views date sort,!1974Issue #3036862 demonstration,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1254Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!957Added throwing of InvalidPluginDefinitionException from getDefinition().,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!873Issue #2875228: Site install not using batch API service,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!712Issue #2909128: Autocomplete intermittent on Chrome Android,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
<?php
namespace Drupal\update;
/**
* Provides a module version value object.
*
* @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use
* \Drupal\Core\Extension\ExtensionVersion instead. As an internal class
* ExtensionVersion may also be removed in a minor release.
*
* @internal
*
* @see https://www.drupal.org/node/3095201
*/
final class ModuleVersion {
/**
* The '8.x-' prefix is used on contrib module version numbers.
*
* @var string
*/
const CORE_PREFIX = '8.x-';
/**
* The major version.
*
* @var string
*/
protected $majorVersion;
/**
* The version extra string.
*
* For example, if the module version is '2.0.3-alpha1', then the version
* extra string is 'alpha1'.
*
* @var string|null
*/
protected $versionExtra;
/**
* Constructs a module version object from a version string.
*
* @param string $version_string
* The version string.
*
* @return \Drupal\update\ModuleVersion
* The module version instance.
*
* @throws \UnexpectedValueException
* Thrown when a legacy version string has a core prefix other than "8.x-"
* for example, version strings such as "7.x-1.0" are not supported.
*/
public static function createFromVersionString($version_string) {
$original_version = $version_string;
if (strpos($version_string, static::CORE_PREFIX) === 0 && $version_string !== '8.x-dev') {
$version_string = preg_replace('/8\.x-/', '', $version_string, 1);
}
else {
// Ensure the version string has no unsupported core prefixes.
$dot_x_position = strpos($version_string, '.x-');
if ($dot_x_position === 1 || $dot_x_position === 2) {
$after_core_prefix = explode('.x-', $version_string)[1];
if ($after_core_prefix !== 'dev') {
throw new \UnexpectedValueException("Unexpected version core prefix in $version_string. The only core prefix expected in \Drupal\update\ModuleVersion is: 8.x-");
}
}
}
$version_parts = explode('.', $version_string);
$major_version = $version_parts[0];
$version_parts_count = count($version_parts);
$last_part_split = explode('-', $version_parts[count($version_parts) - 1]);
$version_extra = count($last_part_split) === 1 ? NULL : $last_part_split[1];
if ($version_parts_count > 3 || $version_parts_count < 2
|| !is_numeric($major_version)
|| ($version_parts_count === 3 && !is_numeric($version_parts[1]))
// The only case where a non-numeric version part other the extra part is
// allowed is in development versions like 8.x-1.x-dev, 1.2.x-dev or
// 1.x-dev.
|| (!is_numeric($last_part_split[0]) && $last_part_split !== 'x' && $version_extra !== 'dev')) {
throw new \UnexpectedValueException("Unexpected version number in: $original_version");
}
return new static($major_version, $version_extra);
}
/**
* Constructs a ModuleVersion object.
*
* @param string $major_version
* The major version.
* @param string|null $version_extra
* The extra version string.
*/
private function __construct($major_version, $version_extra) {
@trigger_error(__CLASS__ . ' is deprecated in drupal:9.2.0 and will be removed before drupal:10.0.0. Use The \Drupal\Core\Extension\ExtensionVersion instead. As an internal class, ExtensionVersion may also be removed in a minor release.', E_USER_DEPRECATED);
$this->majorVersion = $major_version;
$this->versionExtra = $version_extra;
}
/**
* Constructs a module version object from a support branch.
*
* This can be used to determine the major version of the branch.
* ::getVersionExtra() will always return NULL for branches.
*
* @param string $branch
* The support branch.
*
* @return \Drupal\update\ModuleVersion
* The module version instance.
*
* @throws \UnexpectedValueException
* Thrown when $branch is not valid because it does not end in ".".
*/
public static function createFromSupportBranch($branch) {
if (substr($branch, -1) !== '.') {
throw new \UnexpectedValueException("Invalid support branch: $branch");
}
return static::createFromVersionString($branch . '0');
}
/**
* Gets the major version.
*
* @return string
* The major version.
*/
public function getMajorVersion() {
return $this->majorVersion;
}
/**
* Gets the version extra string at the end of the version number.
*
* @return string|null
* The version extra string if available, or otherwise NULL.
*/
public function getVersionExtra() {
return $this->versionExtra;
}
}
<?php
namespace Drupal\Tests\update\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\update\ModuleVersion;
/**
* @coversDefaultClass \Drupal\update\ModuleVersion
*
* @group legacy
* @group update
*/
class ModuleVersionTest extends UnitTestCase {
/**
* @covers ::getMajorVersion
*
* @dataProvider providerVersionInfos
*
* @param string $version
* The version string to test.
* @param array $expected_version_info
* The expected version information.
*/
public function testGetMajorVersion($version, array $expected_version_info) {
$version = ModuleVersion::createFromVersionString($version);
$this->assertSame($expected_version_info['major'], $version->getMajorVersion());
}
/**
* @covers ::getVersionExtra
*
* @dataProvider providerVersionInfos
*
* @param string $version
* The version string to test.
* @param array $expected_version_info
* The expected version information.
*/
public function testGetVersionExtra($version, array $expected_version_info) {
$version = ModuleVersion::createFromVersionString($version);
$this->assertSame($expected_version_info['extra'], $version->getVersionExtra());
}
/**
* Data provider for expected version information.
*
* @return array
* Arrays of version information.
*/
public function providerVersionInfos() {
// Data provider values are:
// - The version number to test.
// - Array of expected version information with the following keys:
// -'major': The expected result from ::getMajorVersion().
// -'extra': The expected result from ::getVersionExtra().
return [
'8.x-1.3' => [
'8.x-1.3',
[
'major' => '1',
'extra' => NULL,
],
],
'8.x-1.0' => [
'8.x-1.0',
[
'major' => '1',
'extra' => NULL,
],
],
'8.x-1.0-alpha1' => [
'8.x-1.0-alpha1',
[
'major' => '1',
'extra' => 'alpha1',
],
],
'8.x-1.3-alpha1' => [
'8.x-1.3-alpha1',
[
'major' => '1',
'extra' => 'alpha1',
],
],
'0.1' => [
'0.1',
[
'major' => '0',
'extra' => NULL,
],
],
'1.0' => [
'1.0',
[
'major' => '1',
'extra' => NULL,
],
],
'1.3' => [
'1.3',
[
'major' => '1',
'extra' => NULL,
],
],
'1.0-alpha1' => [
'1.0-alpha1',
[
'major' => '1',
'extra' => 'alpha1',
],
],
'1.3-alpha1' => [
'1.3-alpha1',
[
'major' => '1',
'extra' => 'alpha1',
],
],
'0.2.0' => [
'0.2.0',
[
'major' => '0',
'extra' => NULL,
],
],
'1.2.0' => [
'1.2.0',
[
'major' => '1',
'extra' => NULL,
],
],
'1.0.3' => [
'1.0.3',
[
'major' => '1',
'extra' => NULL,
],
],
'1.2.3' => [
'1.2.3',
[
'major' => '1',
'extra' => NULL,
],
],
'1.2.0-alpha1' => [
'1.2.0-alpha1',
[
'major' => '1',
'extra' => 'alpha1',
],
],
'1.2.3-alpha1' => [
'1.2.3-alpha1',
[
'major' => '1',
'extra' => 'alpha1',
],
],
'8.x-1.x-dev' => [
'8.x-1.x-dev',
[
'major' => '1',
'extra' => 'dev',
],
],
'8.x-8.x-dev' => [
'8.x-8.x-dev',
[
'major' => '8',
'extra' => 'dev',
],
],
'1.x-dev' => [
'1.x-dev',
[
'major' => '1',
'extra' => 'dev',
],
],
'8.x-dev' => [
'8.x-dev',
[
'major' => '8',
'extra' => 'dev',
],
],
'1.0.x-dev' => [
'1.0.x-dev',
[
'major' => '1',
'extra' => 'dev',
],
],
'1.2.x-dev' => [
'1.2.x-dev',
[
'major' => '1',
'extra' => 'dev',
],
],
];
}
/**
* @covers ::createFromVersionString
*
* @dataProvider providerInvalidVersionNumber
*
* @param string $version
* The version string to test.
*/
public function testInvalidVersionNumber($version) {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage("Unexpected version number in: $version");
ModuleVersion::createFromVersionString($version);
}
/**
* Data provider for testInvalidVersionNumber().
*/
public function providerInvalidVersionNumber() {
return static::createKeyedTestCases([
'',
'8',
'x',
'xx',
'8.x-',
'8.x',
'.x',
'.0',
'.1',
'.1.0',
'1.0.',
'x.1',
'1.x.0',
'1.1.x',
'1.1.x-extra',
'x.1.1',
'1.1.1.1',
'1.1.1.0',
]);
}
/**
* @covers ::createFromVersionString
*
* @dataProvider providerInvalidVersionCorePrefix
*
* @param string $version
* The version string to test.
*/
public function testInvalidVersionCorePrefix($version) {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage("Unexpected version core prefix in $version. The only core prefix expected in \Drupal\update\ModuleVersion is: 8.x-");
ModuleVersion::createFromVersionString($version);
}
/**
* Data provider for testInvalidVersionCorePrefix().
*/
public function providerInvalidVersionCorePrefix() {
return static::createKeyedTestCases([
'6.x-1.0',
'7.x-1.x',
'9.x-1.x',
'10.x-1.x',
]);
}
/**
* @covers ::createFromSupportBranch
*
* @dataProvider providerInvalidBranchCorePrefix
*
* @param string $branch
* The branch to test.
*/
public function testInvalidBranchCorePrefix($branch) {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage("Unexpected version core prefix in {$branch}0. The only core prefix expected in \Drupal\update\ModuleVersion is: 8.x-");
ModuleVersion::createFromSupportBranch($branch);
}
/**
* Data provider for testInvalidBranchCorePrefix().
*/
public function providerInvalidBranchCorePrefix() {
return static::createKeyedTestCases([
'6.x-1.',
'7.x-1.',
'9.x-1.',
'10.x-1.',
]);
}
/**
* @covers ::createFromSupportBranch
*
* @dataProvider providerCreateFromSupportBranch
*
* @param string $branch
* The branch to test.
* @param string $expected_major
* The expected major version.
*/
public function testCreateFromSupportBranch($branch, $expected_major) {
$version = ModuleVersion::createFromSupportBranch($branch);
$this->assertInstanceOf(ModuleVersion::class, $version);
$this->assertSame($expected_major, $version->getMajorVersion());
// Version extra can't be determined from a branch.
$this->assertSame(NULL, $version->getVersionExtra());
}
/**
* Data provider for testCreateFromSupportBranch().
*/
public function providerCreateFromSupportBranch() {
// Data provider values are:
// - The version number to test.
// - Array of expected version information with the following keys:
// -'major': The expected result from ::getMajorVersion().
// -'extra': The expected result from ::getVersionExtra().
return [
'0.' => [
'0.',
'0',
],
'1.' => [
'1.',
'1',
],
'0.1.' => [
'0.1.',
'0',
],
'1.2.' => [
'1.2.',
'1',
],
'8.x-1.' => [
'8.x-1.',
'1',
],
];
}
/**
* @covers ::createFromSupportBranch
*
* @dataProvider provideInvalidBranch
*
* @param string $branch
* The branch to test.
*/
public function testInvalidBranch($branch) {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage("Invalid support branch: $branch");
ModuleVersion::createFromSupportBranch($branch);
}
/**
* Data provider for testInvalidBranch().
*/
public function provideInvalidBranch() {
return self::createKeyedTestCases([
'8.x-1.0',
'8.x-2.x',
'2.x-1.0',
'1.1',
'1.x',
'1.1.x',
'1.1.1',
'1.1.1.1',
]);
}
/**
* Creates test case arrays for data provider methods.
*
* @param string[] $test_arguments
* The test arguments.
*
* @return array
* An array with $test_arguments as keys and each element of $test_arguments
* as a single item array
*/
protected static function createKeyedTestCases(array $test_arguments) {
return array_combine(
$test_arguments,
array_map(function ($test_argument) {
return [$test_argument];
}, $test_arguments)
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment