Skip to content
Snippets Groups Projects
Commit 3b224b4f authored by Yash Rode's avatar Yash Rode
Browse files

test fix

parent 704e600e
No related branches found
Tags 2.4.0-beta1
No related merge requests found
......@@ -148,7 +148,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
$this->setReleaseMetadata($release_data);
$this->setCoreVersion('9.8.0');
update_get_available(TRUE);
$version = strpos($release_data['drupal'], '9.8.2') ? '9.8.2' : '9.8.1';
// Submit the configuration form programmatically, to prove our alterations
// work as expected.
$form_builder = $this->container->get('form_builder');
......@@ -160,6 +160,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
$form_state->setValue('automatic_updates_cron', $setting);
$form_builder->submitForm(UpdateSettingsForm::class, $form_state);
$this->setStagedCoreVersion($version);
// Since we're just trying to ensure that all of Package Manager's services
// are called as expected, disable validation by replacing the event
// dispatcher with a dummy version.
......@@ -299,6 +300,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
/** @var \Drupal\automatic_updates\CronUpdater $updater */
$updater = $this->container->get('automatic_updates.cron_updater');
$this->assertTrue($updater->isAvailable());
$this->setStagedCoreVersion('9.8.1');
$this->container->get('cron')->run();
$logged_by_updater = $this->logger->hasRecord($expected_log_message, RfcLogLevel::ERROR);
......@@ -358,6 +360,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
* Tests that email is sent when an unattended update succeeds.
*/
public function testEmailOnSuccess(): void {
$this->setStagedCoreVersion('9.8.1');
$this->container->get('cron')->run();
// Ensure we sent a success message to all recipients.
......@@ -414,6 +417,7 @@ END;
];
TestSubscriber1::setTestResult($results, $event_class);
$exception = new StageValidationException($results);
$this->setStagedCoreVersion('9.8.2');
$this->container->get('cron')->run();
$url = Url::fromRoute('update.report_update')
......@@ -448,6 +452,7 @@ END;
];
TestSubscriber1::setTestResult($results, $event_class);
$exception = new StageValidationException($results);
$this->setStagedCoreVersion('9.8.1');
$this->container->get('cron')->run();
$url = Url::fromRoute('update.report_update')
......@@ -475,6 +480,7 @@ END;
$error = new \Exception('I drink your milkshake!');
Committer::setException($error);
$this->setStagedCoreVersion('9.8.1');
$this->container->get('cron')->run();
$expected_body = <<<END
Drupal core failed to update automatically from 9.8.0 to 9.8.1. The following error was logged:
......@@ -496,4 +502,20 @@ END;
$this->assertSame('setLogger', $updater_method_calls[0][0]);
}
/**
* Modifies staged core version.
*
* @param string $version
* Requested version.
*/
private function setStagedCoreVersion(string $version): void {
$listener = function (PreApplyEvent $event) use ($version): void {
/** @var \Drupal\automatic_updates\CronUpdater $cron_updater */
$cron_updater = $this->container->get('automatic_updates.cron_updater');
$this->modifyCorePackageVersion($cron_updater->getStageDirectory(), $version);
};
$this->container->get('event_dispatcher')
->addListener(PreApplyEvent::class, $listener, PHP_INT_MAX);
}
}
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