@@ -30,25 +30,55 @@ class UpdateVersionValidatorTest extends AutomaticUpdatesKernelTestBase {
];
/**
* Tests an update version that is same major & minor version as the current.
* The logger for cron updates.
*
* @var \Psr\Log\Test\TestLogger
*/
publicfunctiontestNoMajorOrMinorUpdates():void{
$this->setCoreVersion('9.8.0');
$this->config('automatic_updates.settings')
->set('cron',CronUpdater::DISABLED)
->save();
$this->assertCheckerResultsFromManager([],TRUE);
private$logger;
/**
* {@inheritdoc}
*/
protectedfunctionsetUp():void{
parent::setUp();
$this->logger=newTestLogger();
$this->container->get('logger.factory')
->get('automatic_updates')
->addLogger($this->logger);
}
/**
* Tests an update version that is a different major version than the current.
* Data provider for all possible cron update frequencies.
*
* @return array[]
* Sets of arguments to pass to the test method.
*/
publicfunctiontestMajorUpdates():void{
$this->setCoreVersion('8.9.1');
$result=ValidationResult::createError([
'Drupal cannot be automatically updated from its current version, 8.9.1, to the recommended version, 9.8.2, because automatic updates from one major version to another are not supported.',
'Drupal cannot be automatically updated during cron from its current version, 9.8.0, to the recommended version, 9.8.2, because Automatic Updates only supports 1 patch version update during cron.',
]);
/**
* Tests a current version that is a dev version.
*/
publicfunctiontestUpdatesFromDevVersion():void{
$this->setCoreVersion('9.8.0-dev');
$result=ValidationResult::createError(['Drupal cannot be automatically updated from its current version, 9.8.0-dev, to the recommended version, 9.8.2, because automatic updates from a dev version to any other version are not supported.']);
// The latest version is two patch releases ahead, so we won't update to it
// during cron, even if configuration allows it, and this should be flagged
// as an error during readiness checking. Trying to run the update anyway
// should raise an error.
$config->set('cron',CronUpdater::ALL)->save();
$result=ValidationResult::createError(['Drupal cannot be automatically updated during cron from its current version, 9.8.0, to the recommended version, 9.8.2, because Automatic Updates only supports 1 patch version update during cron.']);
$this->assertTrue($logger->hasRecord("<h2>Unable to complete the update because of errors.</h2>Drupal cannot be automatically updated during cron from its current version, 9.8.0, to the recommended version, 9.8.2, because Automatic Updates only supports 1 patch version update during cron.",RfcLogLevel::ERROR));
// If cron updates are totally disabled, there's no problem here and no
$this->assertTrue($logger->hasRecord("<h2>Unable to complete the update because of errors.</h2>Drupal cannot be automatically updated during cron from its current version, 9.8.0, to the recommended version, 9.8.2, because Automatic Updates only supports 1 patch version update during cron.",RfcLogLevel::ERROR));
/**
* Data provider for ::testCronUpdateOnePatchReleaseAhead().
'Drupal cannot be automatically updated during cron from its current version, 9.8.0-alpha1, because Automatic Updates only supports updating from stable versions during cron.',
'Drupal cannot be automatically updated from its current version, 9.8.0-dev, to the recommended version, 9.8.2, because automatic updates from a dev version to any other version are not supported.',
'Drupal cannot be automatically updated from its current version, 8.9.1, to the recommended version, 9.8.2, because automatic updates from one major version to another are not supported.',
]);
return[
'unstable current version, cron disabled'=>[
CronUpdater::DISABLED,
'9.8.0-alpha1',
// If cron updates are disabled, no error should be flagged, because
// the validation will be run with the regular updater, not the cron
// updater.
[],
[],
],
'unstable current version, security updates allowed'=>[
CronUpdater::SECURITY,
'9.8.0-alpha1',
[$unstable_current_version],
// The update will not run because the latest release is not a security
// release, so nothing should be logged.
[],
],
'unstable current version, all updates allowed'=>[
CronUpdater::ALL,
'9.8.0-alpha1',
[$unstable_current_version],
[$unstable_current_version],
],
'dev current version, cron disabled'=>[
CronUpdater::DISABLED,
'9.8.0-dev',
[$dev_current_version],
[],
],
'dev current version, security updates allowed'=>[
CronUpdater::SECURITY,
'9.8.0-dev',
[$dev_current_version],
// The update will not run because the latest release is not a security
// release, so nothing should be logged.
[],
],
'dev current version, all updates allowed'=>[
CronUpdater::ALL,
'9.8.0-dev',
[$dev_current_version],
[$dev_current_version],
],
'newer current version, cron disabled'=>[
CronUpdater::DISABLED,
'9.8.3',
[$newer_current_version],
[],
],
'newer current version, security updates allowed'=>[
CronUpdater::SECURITY,
'9.8.3',
[$newer_current_version],
// The update will not run because the latest release is not a security
// release, so nothing should be logged.
[],
],
'newer current version, all updates allowed'=>[
CronUpdater::ALL,
'9.8.3',
[$newer_current_version],
[$newer_current_version],
],
'different current major, cron disabled'=>[
CronUpdater::DISABLED,
'8.9.1',
[$different_major_version],
[],
],
'different current major, security updates allowed'=>[
CronUpdater::SECURITY,
'8.9.1',
[$different_major_version],
// The update will not run because the latest release is not a security
// release, so nothing should be logged.
[],
],
'different current major, all updates allowed'=>[
CronUpdater::ALL,
'8.9.1',
[$different_major_version],
[$different_major_version],
],
];
}
/**
* Tests invalid version jumps before and during a cron update.
*
* @param string $cron_setting
* The value of the automatic_updates.settings:cron config setting.
* @param string $current_core_version
* The current core version from which we are updating.
$message='Drupal cannot be automatically updated during cron from its current version, 9.8.0-alpha1, because Automatic Updates only supports updating from stable versions during cron.';