Skip to content
Snippets Groups Projects
Commit d105d726 authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Adam G-H
Browse files

Issue #3276534 by kunal.sachdev, phenaproxima, Theresa.Grannum:...

Issue #3276534 by kunal.sachdev, phenaproxima, Theresa.Grannum: CronUpdater::getMode() should always return a value
parent 7c5e93ad
No related branches found
No related tags found
No related merge requests found
...@@ -172,15 +172,13 @@ class CronUpdater extends Updater { ...@@ -172,15 +172,13 @@ class CronUpdater extends Updater {
* can be done during cron. * can be done during cron.
* - \Drupal\automatic_updates\CronUpdater::ALL if all updates are allowed * - \Drupal\automatic_updates\CronUpdater::ALL if all updates are allowed
* during cron. * during cron.
*
* @todo Make this always return a string, with a sensible default, in
* https://www.drupal.org/i/3276534.
*/ */
final public function getMode(): ?string { final public function getMode(): string {
if (self::$disabled) { if (self::$disabled) {
return static::DISABLED; return static::DISABLED;
} }
return $this->configFactory->get('automatic_updates.settings')->get('cron'); $mode = $this->configFactory->get('automatic_updates.settings')->get('cron');
return $mode ?: CronUpdater::SECURITY;
} }
} }
...@@ -65,10 +65,10 @@ abstract class AutomaticUpdatesKernelTestBase extends PackageManagerKernelTestBa ...@@ -65,10 +65,10 @@ abstract class AutomaticUpdatesKernelTestBase extends PackageManagerKernelTestBa
// have run. // have run.
$this->registerPostUpdateFunctions(); $this->registerPostUpdateFunctions();
// By default, pretend we're running Drupal core 9.8.1 and a non-security // By default, pretend we're running Drupal core 9.8.0 and a non-security
// update to 9.8.2 is available. // update to 9.8.1 is available.
$this->setCoreVersion('9.8.1'); $this->setCoreVersion('9.8.0');
$this->setReleaseMetadata(['drupal' => __DIR__ . '/../../fixtures/release-history/drupal.9.8.2.xml']); $this->setReleaseMetadata(['drupal' => __DIR__ . '/../../fixtures/release-history/drupal.9.8.1-security.xml']);
// Set a last cron run time so that the cron frequency validator will run // Set a last cron run time so that the cron frequency validator will run
// from a sane state. // from a sane state.
......
...@@ -21,6 +21,15 @@ class CronFrequencyValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -21,6 +21,15 @@ class CronFrequencyValidatorTest extends AutomaticUpdatesKernelTestBase {
*/ */
protected static $modules = ['automatic_updates']; protected static $modules = ['automatic_updates'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->setCoreVersion('9.8.0');
$this->setReleaseMetadata(['drupal' => __DIR__ . '/../../../fixtures/release-history/drupal.9.8.1-security.xml']);
}
/** /**
* Tests that nothing is validated if updates are disabled during cron. * Tests that nothing is validated if updates are disabled during cron.
*/ */
......
...@@ -220,7 +220,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -220,7 +220,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
*/ */
public function testStoredResultsDeletedPostApply(): void { public function testStoredResultsDeletedPostApply(): void {
$this->enableModules(['automatic_updates']); $this->enableModules(['automatic_updates']);
$this->setCoreVersion('9.8.1'); $this->setCoreVersion('9.8.0');
$this->setReleaseMetadata(['drupal' => __DIR__ . '/../../../fixtures/release-history/drupal.9.8.1-security.xml']);
// The readiness checker should raise a warning, so that the update is not // The readiness checker should raise a warning, so that the update is not
// blocked or aborted. // blocked or aborted.
...@@ -231,6 +232,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -231,6 +232,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
/** @var \Drupal\automatic_updates\Validation\ReadinessValidationManager $manager */ /** @var \Drupal\automatic_updates\Validation\ReadinessValidationManager $manager */
$manager = $this->container->get('automatic_updates.readiness_validation_manager') $manager = $this->container->get('automatic_updates.readiness_validation_manager')
->run(); ->run();
$this->assertValidationResultsEqual($results, $manager->getResults());
TestSubscriber1::setTestResult(NULL, ReadinessCheckEvent::class); TestSubscriber1::setTestResult(NULL, ReadinessCheckEvent::class);
// Even though the checker no longer returns any results, the previous // Even though the checker no longer returns any results, the previous
// results should be stored. // results should be stored.
...@@ -244,7 +246,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -244,7 +246,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
/** @var \Drupal\automatic_updates\Updater $updater */ /** @var \Drupal\automatic_updates\Updater $updater */
$updater = $this->container->get('automatic_updates.updater'); $updater = $this->container->get('automatic_updates.updater');
$updater->begin(['drupal' => '9.8.2']); $updater->begin(['drupal' => '9.8.1']);
$updater->stage(); $updater->stage();
$updater->apply(); $updater->apply();
$updater->destroy(); $updater->destroy();
......
...@@ -51,7 +51,7 @@ class SettingsValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -51,7 +51,7 @@ class SettingsValidatorTest extends AutomaticUpdatesKernelTestBase {
$this->assertCheckerResultsFromManager($expected_results, TRUE); $this->assertCheckerResultsFromManager($expected_results, TRUE);
try { try {
$this->container->get('automatic_updates.updater')->begin([ $this->container->get('automatic_updates.updater')->begin([
'drupal' => '9.8.2', 'drupal' => '9.8.1',
]); ]);
// If there was no exception, ensure we're not expecting any errors. // If there was no exception, ensure we're not expecting any errors.
$this->assertSame([], $expected_results); $this->assertSame([], $expected_results);
......
...@@ -35,7 +35,7 @@ class StagedDatabaseUpdateValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -35,7 +35,7 @@ class StagedDatabaseUpdateValidatorTest extends AutomaticUpdatesKernelTestBase {
/** @var \Drupal\Tests\automatic_updates\Kernel\TestCronUpdater $updater */ /** @var \Drupal\Tests\automatic_updates\Kernel\TestCronUpdater $updater */
$updater = $this->container->get('automatic_updates.cron_updater'); $updater = $this->container->get('automatic_updates.cron_updater');
$updater->begin(['drupal' => '9.8.2']); $updater->begin(['drupal' => '9.8.1']);
$updater->stage(); $updater->stage();
} }
......
...@@ -46,7 +46,7 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -46,7 +46,7 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
private function validate(array $expected_results): void { private function validate(array $expected_results): void {
/** @var \Drupal\automatic_updates\Updater $updater */ /** @var \Drupal\automatic_updates\Updater $updater */
$updater = $this->container->get('automatic_updates.updater'); $updater = $this->container->get('automatic_updates.updater');
$updater->begin(['drupal' => '9.8.2']); $updater->begin(['drupal' => '9.8.1']);
$updater->stage(); $updater->stage();
try { try {
......
...@@ -79,14 +79,14 @@ class ReleaseChooserTest extends AutomaticUpdatesKernelTestBase { ...@@ -79,14 +79,14 @@ class ReleaseChooserTest extends AutomaticUpdatesKernelTestBase {
'updater' => 'automatic_updates.cron_updater', 'updater' => 'automatic_updates.cron_updater',
'minor_support' => FALSE, 'minor_support' => FALSE,
'installed_version' => '9.8.0', 'installed_version' => '9.8.0',
'current_minor' => '9.8.2', 'current_minor' => '9.8.1',
'next_minor' => NULL, 'next_minor' => NULL,
], ],
'cron, installed 9.8.0, minor support' => [ 'cron, installed 9.8.0, minor support' => [
'updater' => 'automatic_updates.cron_updater', 'updater' => 'automatic_updates.cron_updater',
'minor_support' => TRUE, 'minor_support' => TRUE,
'installed_version' => '9.8.0', 'installed_version' => '9.8.0',
'current_minor' => '9.8.2', 'current_minor' => '9.8.1',
'next_minor' => NULL, 'next_minor' => NULL,
], ],
'cron, installed 9.7.0, no minor support' => [ 'cron, installed 9.7.0, no minor support' => [
......
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