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

Issue #3233587 by phenaproxima, tedbow: Create a build test that tests calling...

Issue #3233587 by phenaproxima, tedbow: Create a build test that tests calling API as cleanly as possible
parent d143bfcd
No related branches found
No related tags found
1 merge request!45Issue #3233587: Create a build test that tests calling API as cleanly as possible
......@@ -14,6 +14,12 @@ services:
- '%site.path%'
- '@automatic_updates.path_locator'
properties: { _serviceId: package_manager.cleaner }
automatic_updates.update_refresh_subscriber:
class: Drupal\automatic_updates\Event\UpdateRefreshSubscriber
arguments:
- '@update.manager'
tags:
- { name: event_subscriber }
automatic_updates.excluded_paths_subscriber:
class: Drupal\automatic_updates\Event\ExcludedPathsSubscriber
arguments: ['%app.root%', '%site.path%', '@file_system', '@stream_wrapper_manager']
......
......@@ -57,4 +57,13 @@ final class AutomaticUpdatesEvents {
*/
const PRE_COMMIT = 'automatic_updates.pre_commit';
/**
* Name of the event fired when a staged update has been committed.
*
* @Event
*
* @var string
*/
const POST_COMMIT = 'automatic_updates.post_commit';
}
<?php
namespace Drupal\automatic_updates\Event;
use Drupal\automatic_updates\AutomaticUpdatesEvents;
use Drupal\update\UpdateManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Clears stale update data once a staged update has been committed.
*/
class UpdateRefreshSubscriber implements EventSubscriberInterface {
/**
* The update manager service.
*
* @var \Drupal\update\UpdateManagerInterface
*/
protected $updateManager;
/**
* Constructs an UpdateRefreshSubscriber object.
*
* @param \Drupal\update\UpdateManagerInterface $update_manager
* The update manager service.
*/
public function __construct(UpdateManagerInterface $update_manager) {
$this->updateManager = $update_manager;
}
/**
* Clears stale update data.
*/
public function clearData(): void {
$this->updateManager->refreshUpdateData();
update_storage_clear();
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
AutomaticUpdatesEvents::POST_COMMIT => ['clearData', 1000],
];
}
}
......@@ -234,6 +234,7 @@ class Updater {
/** @var \Drupal\automatic_updates\Event\PreCommitEvent $event */
$event = $this->dispatchUpdateEvent(new PreCommitEvent(), AutomaticUpdatesEvents::PRE_COMMIT);
$this->committer->commit($this->pathLocator->getStageDirectory(), $this->pathLocator->getActiveDirectory(), $this->getExclusions($event));
$this->dispatchUpdateEvent(new UpdateEvent(), AutomaticUpdatesEvents::POST_COMMIT);
}
/**
......
automatic_updates_test.update_test:
automatic_updates_test.metadata:
path: '/automatic-update-test/{project_name}/{version}'
defaults:
_title: 'Update test'
_controller: '\Drupal\automatic_updates_test\MetadataController::updateTest'
_controller: '\Drupal\automatic_updates_test\TestController::metadata'
requirements:
_access: 'TRUE'
automatic_updates_test.update:
path: '/automatic-update-test/update/{to_version}'
defaults:
_controller: '\Drupal\automatic_updates_test\TestController::update'
requirements:
_access: 'TRUE'
......@@ -2,11 +2,42 @@
namespace Drupal\automatic_updates_test;
use Drupal\automatic_updates\UpdateRecommender;
use Drupal\Component\Utility\Environment;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
class MetadataController extends ControllerBase {
class TestController extends ControllerBase {
/**
* Performs an in-place update to a given version of Drupal core.
*
* This executes the update immediately, in one request, without using the
* batch system or cron as wrappers.
*
* @param string $to_version
* The version of core to update to.
*
* @return array
* The renderable array of the page.
*/
public function update(string $to_version): array {
// Let it take as long as it needs.
Environment::setTimeLimit(0);
/** @var \Drupal\automatic_updates\Updater $updater */
$updater = \Drupal::service('automatic_updates.updater');
$updater->begin(['drupal' => $to_version]);
$updater->stage();
$updater->commit();
$updater->clean();
$project = (new UpdateRecommender())->getProjectInfo();
return [
'#markup' => $project['existing_version'],
];
}
/**
* Page callback: Prints mock XML for the Update Manager module.
......@@ -16,7 +47,7 @@ class MetadataController extends ControllerBase {
* testing automatic updates. This was done in order to use a different
* directory of mock XML files.
*/
public function updateTest($project_name = 'drupal', $version = NULL): Response {
public function metadata($project_name = 'drupal', $version = NULL): Response {
if ($project_name !== 'drupal') {
return new Response();
}
......
......@@ -103,6 +103,14 @@ class CoreUpdateTest extends UpdateTestBase {
];
}
/**
* Tests an end-to-end core update via the API.
*/
public function testApi(): void {
$this->visit('/automatic-update-test/update/9.8.1');
$this->getMink()->assertSession()->pageTextContains('9.8.1');
}
/**
* Tests an end-to-end core update via the UI.
*/
......
......@@ -83,7 +83,7 @@ abstract class UpdateTestBase extends QuickStartTestBase {
* @param array $xml_map
* The update XML map, as used by update_test.settings.
*
* @see \Drupal\automatic_updates_test\MetadataController::updateTest()
* @see \Drupal\automatic_updates_test\TestController::metadata()
*/
protected function setReleaseMetadata(array $xml_map): void {
$xml_map = var_export($xml_map, TRUE);
......
......@@ -25,6 +25,7 @@ class ComposerExecutableValidatorTest extends KernelTestBase {
protected static $modules = [
'automatic_updates',
'package_manager',
'update',
];
/**
......
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