Skip to content
Snippets Groups Projects
Commit ad0b676a authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3284443 by phenaproxima: Enable unattended updates

parent 3fb91ffc
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ declare(strict_types = 1); ...@@ -10,6 +10,7 @@ declare(strict_types = 1);
use Drupal\automatic_updates\BatchProcessor; use Drupal\automatic_updates\BatchProcessor;
use Drupal\automatic_updates\CronUpdateStage; use Drupal\automatic_updates\CronUpdateStage;
use Drupal\automatic_updates\Validator\AutomatedCronDisabledValidator; use Drupal\automatic_updates\Validator\AutomatedCronDisabledValidator;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\automatic_updates\Validation\AdminStatusCheckMessages; use Drupal\automatic_updates\Validation\AdminStatusCheckMessages;
use Drupal\Core\Url; use Drupal\Core\Url;
...@@ -249,6 +250,59 @@ function automatic_updates_batch_alter(array &$batch): void { ...@@ -249,6 +250,59 @@ function automatic_updates_batch_alter(array &$batch): void {
} }
} }
/**
* Implements hook_form_FORM_ID_alter() for update_settings.
*/
function automatic_updates_form_update_settings_alter(array &$form): void {
$config = \Drupal::config('automatic_updates.settings');
$form['unattended_level'] = [
'#type' => 'radios',
'#title' => t('Unattended background updates'),
'#options' => [
CronUpdateStage::DISABLED => t('Disabled'),
CronUpdateStage::SECURITY => t('Security updates only'),
CronUpdateStage::ALL => t('All patch releases'),
],
'#default_value' => $config->get('unattended.level'),
];
$form['unattended_method'] = [
'#type' => 'radios',
'#title' => t('How unattended updates should be run'),
'#options' => [
'web' => t('By a request to /system/cron'),
'console' => t('By the <code>auto-update</code> Drush command'),
],
'#default_value' => $config->get('unattended.method'),
'#states' => [
'invisible' => [
'input[name="unattended_level"]' => [
'value' => CronUpdateStage::DISABLED,
],
],
],
];
$form['#submit'][] = '_automatic_updates_submit_update_settings';
}
/**
* Saves settings for unattended updates.
*
* @param array $form
* The complete form structure.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
function _automatic_updates_submit_update_settings(array &$form, FormStateInterface $form_state): void {
\Drupal::configFactory()
->getEditable('automatic_updates.settings')
->set('unattended', [
'method' => $form_state->getValue('unattended_method'),
'level' => $form_state->getValue('unattended_level'),
])
->save();
}
/** /**
* Implements hook_preprocess_update_project_status(). * Implements hook_preprocess_update_project_status().
*/ */
......
...@@ -44,9 +44,9 @@ build: ...@@ -44,9 +44,9 @@ build:
halt-on-fail: false halt-on-fail: false
# Functional JavaScript tests require a concurrency of 1 because there is # Functional JavaScript tests require a concurrency of 1 because there is
# only one instance of PhantomJS on the testbot machine. # only one instance of PhantomJS on the testbot machine.
#run_tests.javascript: run_tests.javascript:
# concurrency: 1 concurrency: 1
# types: 'PHPUnit-FunctionalJavascript' types: 'PHPUnit-FunctionalJavascript'
# testgroups: '--all' testgroups: '--all'
# suppress-deprecations: false suppress-deprecations: false
# halt-on-fail: false halt-on-fail: false
...@@ -45,8 +45,13 @@ class ClickableHelpTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -45,8 +45,13 @@ class ClickableHelpTest extends AutomaticUpdatesFunctionalTestBase {
$this->drupalLogin($this->createUser([ $this->drupalLogin($this->createUser([
'administer site configuration', 'administer site configuration',
'administer software updates',
])); ]));
$this->drupalGet('admin/reports/status'); $this->drupalGet('admin/reports/status');
// Status checks were run when modules were installed, and are now cached,
// so we need to re-run the status checks to see our new result.
// @see automatic_updates_modules_installed()
$this->clickLink('Rerun readiness checks');
$assert_session = $this->assertSession(); $assert_session = $this->assertSession();
$assert_session->pageTextContains('A problem was found! Read all about it.'); $assert_session->pageTextContains('A problem was found! Read all about it.');
$assert_session->linkExists('Read all about it.'); $assert_session->linkExists('Read all about it.');
......
<?php
namespace Drupal\Tests\automatic_updates\FunctionalJavascript;
use Drupal\automatic_updates\CronUpdateStage;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* @group automatic_updates
*/
class UpdateSettingsFormTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = ['automatic_updates'];
/**
* Tests Automatic Updates' alterations to the update settings form.
*/
public function testSettingsForm(): void {
$account = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($account);
$this->drupalGet('/admin/reports/updates/settings');
// The default values should be reflected.
$assert_session = $this->assertSession();
$assert_session->fieldValueEquals('unattended_method', 'web');
$assert_session->fieldValueEquals('unattended_level', CronUpdateStage::DISABLED);
// Since unattended updates are disabled, the method radio buttons should be
// hidden.
$this->assertFalse($assert_session->fieldExists('unattended_method')->isVisible());
// Enabling unattended updates should reveal the method radio buttons.
$page = $this->getSession()->getPage();
$page->selectFieldOption('unattended_level', CronUpdateStage::SECURITY);
$this->assertNotEmpty($assert_session->waitForElementVisible('named', ['field', 'unattended_method']));
// Change the method, to ensure it is properly saved in config.
$page->selectFieldOption('unattended_method', 'console');
// Ensure the changes are reflected in config.
$page->pressButton('Save configuration');
$config = $this->config('automatic_updates.settings');
$this->assertSame(CronUpdateStage::SECURITY, $config->get('unattended.level'));
$this->assertSame('console', $config->get('unattended.method'));
// Our saved changes should be reflected in the form too.
$assert_session->fieldValueEquals('unattended_level', CronUpdateStage::SECURITY);
$assert_session->fieldValueEquals('unattended_method', 'console');
}
}
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