View source
<?php
namespace Drupal\Tests\automatic_updates\Kernel;
use Drupal\automatic_updates\CronUpdater;
use Drupal\Core\Form\FormState;
use Drupal\update\UpdateSettingsForm;
class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
protected static $modules = [
'automatic_updates',
'package_manager',
];
public function providerUpdaterCalled() : array {
$fixture_dir = __DIR__ . '/../../fixtures/release-history';
return [
'disabled, normal release' => [
CronUpdater::DISABLED,
"{$fixture_dir}/drupal.9.8.1.xml",
FALSE,
],
'disabled, security release' => [
CronUpdater::DISABLED,
"{$fixture_dir}/drupal.9.8.1-security.xml",
FALSE,
],
'security only, security release' => [
CronUpdater::SECURITY,
"{$fixture_dir}/drupal.9.8.1-security.xml",
TRUE,
],
'security only, normal release' => [
CronUpdater::SECURITY,
"{$fixture_dir}/drupal.9.8.1.xml",
FALSE,
],
'enabled, normal release' => [
CronUpdater::ALL,
"{$fixture_dir}/drupal.9.8.1.xml",
TRUE,
],
'enabled, security release' => [
CronUpdater::ALL,
"{$fixture_dir}/drupal.9.8.1-security.xml",
TRUE,
],
];
}
public function testUpdaterCalled(string $setting, string $release_data, bool $will_update) : void {
$this
->setReleaseMetadata($release_data);
update_get_available(TRUE);
$form_builder = $this->container
->get('form_builder');
$form_state = new FormState();
$form = $form_builder
->buildForm(UpdateSettingsForm::class, $form_state);
$this
->assertStringContainsString('Automatic updates are only supported for 9.8.x versions of Drupal core. Drupal 9.8 will receive security updates until 9.10.0 is released.', $form['automatic_updates_cron']['#description']);
$form_state
->setValue('automatic_updates_cron', $setting);
$form_builder
->submitForm(UpdateSettingsForm::class, $form_state);
$will_update = (int) $will_update;
$updater = $this
->prophesize('\\Drupal\\automatic_updates\\Updater');
$updater
->begin([
'drupal' => '9.8.1',
])
->shouldBeCalledTimes($will_update);
$updater
->stage()
->shouldBeCalledTimes($will_update);
$updater
->commit()
->shouldBeCalledTimes($will_update);
$updater
->clean()
->shouldBeCalledTimes($will_update);
$this->container
->set('automatic_updates.updater', $updater
->reveal());
$this->container
->get('cron')
->run();
}
}