Skip to content
Snippets Groups Projects
Commit 544b6609 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3277775 by tedbow, mherman-pro: "Reports > Available updates" should...

Issue #3277775 by tedbow, mherman-pro: "Reports > Available updates" should link the automatic updates form, not the regular list of available updates
parent 9a08d182
No related branches found
No related tags found
No related merge requests found
update_status:
css:
theme:
css/update-status.css: {}
......@@ -171,3 +171,58 @@ function automatic_updates_batch_alter(array &$batch): void {
}
}
}
/**
* Implements hook_preprocess_update_project_status().
*/
function automatic_updates_preprocess_update_project_status(array &$variables) {
$project = &$variables['project'];
if ($project['name'] !== 'drupal') {
return;
}
$updater = \Drupal::service('automatic_updates.updater');
/** @var \Drupal\automatic_updates\ReleaseChooser $recommender */
$recommender = \Drupal::service('automatic_updates.release_chooser');
try {
$supported_update_release = $recommender->getLatestInInstalledMinor($updater) ?? $recommender->getLatestInNextMinor($updater);
}
catch (RuntimeException $exception) {
// If for some reason we are not able to get the update recommendations
// do not alter the report.
watchdog_exception('automatic_updates', $exception);
return;
}
$variables['#attached']['library'][] = 'automatic_updates/update_status';
$status = &$variables['status'];
if ($supported_update_release && $status['label']) {
$status['label'] = [
'#markup' => t(
'@label <a href=":update-form">Update now</a>', [
'@label' => $status['label'],
':update-form' => Url::fromRoute('automatic_updates.report_update')->toString(),
]),
];
}
// BEGIN: DELETE FROM CORE MERGE REQUEST
if (empty($variables['versions'])) {
return;
}
foreach ($variables['versions'] as &$themed_version) {
$version_info = &$themed_version['#version'];
if ($supported_update_release && $version_info['version'] === $supported_update_release->getVersion()) {
$version_info['download_link'] = Url::fromRoute('automatic_updates.report_update')->setAbsolute()->toString();
}
else {
// If this version will not be displayed as an option on this module's
// update form replace the link to download the archive file with the
// release notes link. The release notes page will provide Composer
// instructions. While this isn't a perfect solution the Update module twig
// templates do not check if 'download_link' is set, so we cannot unset it
// here.
$themed_version['#attributes']['class'][] = 'automatic-updates-unsupported-version';
$version_info['download_link'] = $version_info['release_link'];
}
}
// END: DELETE FROM CORE MERGE REQUEST
}
......@@ -131,6 +131,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
*/
public function testSuccessfulUpdate(bool $maintenance_mode_on, string $project_name, string $installed_version, string $update_version): void {
$this->updateProject = $project_name;
$this->setReleaseMetadata(__DIR__ . '/../../../../tests/fixtures/release-history/drupal.9.8.2.xml');
$this->setReleaseMetadata(__DIR__ . "/../../fixtures/release-history/$project_name.1.1.xml");
$this->setProjectInstalledVersion($installed_version);
$this->checkForUpdates();
......
/**
* @file
* Styles used by the Automatic Updates module.
*/
.automatic-updates-unsupported-version .project-update__download-link {
display: none;
}
......@@ -139,10 +139,10 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
->save();
[$project] = explode('.', basename($file, '.xml'), 2);
$xml_map = $this->config('update_test.settings')->get('xml_map') ?? [];
$xml_map[$project] = $file;
$this->config('update_test.settings')
->set('xml_map', [
$project => $file,
])
->set('xml_map', $xml_map)
->save();
}
......
<?php
namespace Drupal\Tests\automatic_updates\Functional;
use Drupal\Core\Url;
/**
* Tests changes to the Available Updates report provided by the Update module.
*
* @group automatic_updates
*/
class AvailableUpdatesReportTest extends AutomaticUpdatesFunctionalTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'block',
'automatic_updates',
'automatic_updates_test',
'package_manager_test_fixture',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
// In this test class, all actual staging operations are bypassed by
// package_manager_bypass, which means this validator will complain because
// there is no actual Composer data for it to inspect.
$this->disableValidators[] = 'automatic_updates.staged_projects_validator';
parent::setUp();
$user = $this->createUser([
'administer site configuration',
'administer software updates',
'access administration pages',
'access site reports',
]);
$this->drupalLogin($user);
}
/**
* Tests the Available Updates report links are correct.
*/
public function testReportLinks(): void {
$assert = $this->assertSession();
$form_url = Url::fromRoute('automatic_updates.report_update')->toString();
$this->config('automatic_updates.settings')->set('allow_core_minor_updates', TRUE)->save();
$fixture_directory = __DIR__ . '/../../fixtures/release-history/';
$this->setReleaseMetadata("$fixture_directory/drupal.9.8.1-security.xml");
$this->setCoreVersion('9.8.0');
$this->checkForUpdates();
$assert->pageTextContains('Security update required! Update now');
$assert->elementAttributeContains('named', ['link', 'Update now'], 'href', $form_url);
$this->assertVersionLink('9.8.1', $form_url);
$this->setReleaseMetadata("$fixture_directory/drupal.9.8.2-older-sec-release.xml");
$this->setCoreVersion('9.7.0');
$this->checkForUpdates();
$assert->pageTextContains('Security update required! Update now');
$assert->elementAttributeContains('named', ['link', 'Update now'], 'href', $form_url);
// Releases that will available on the form should link to the form.
$this->assertVersionLink('9.8.2', 'http://example.com/drupal-9-8-2-release');
$this->assertVersionLink('9.7.1', $form_url);
// Releases that will not be available in the form should link to the
// project release page.
$this->assertVersionLink('9.8.1', 'http://example.com/drupal-9-8-1-release');
$this->setReleaseMetadata("$fixture_directory/drupal.9.8.2.xml");
$this->checkForUpdates();
$assert->pageTextContains('Update available Update now');
$assert->elementAttributeContains('named', ['link', 'Update now'], 'href', $form_url);
$this->assertVersionLink('9.8.2', 'http://example.com/drupal-9-8-2-release');
}
/**
* Asserts the version download link is correct.
*
* @param string $version
* The version.
* @param string $url
* The expected URL.
*/
private function assertVersionLink(string $version, string $url): void {
$assert = $this->assertSession();
$row = $assert->elementExists('css', "table.update .project-update__version:contains(\"$version\")");
$link = $assert->elementExists('named', ['link', 'Download'], $row);
$this->assertStringEndsWith($url, $link->getAttribute('href'));
}
}
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