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

Issue #3271144 by kunal.sachdev, phenaproxima, tedbow: Ensure new, changed or...

Issue #3271144 by kunal.sachdev, phenaproxima, tedbow: Ensure new, changed or deleted service definitions are in the correct state after an update
parent 04edfe28
No related branches found
No related tags found
1 merge request!246Issue #3271144: Ensure new, changed or deleted service definitions are in the correct state after an update
services:
updated_module.existing_service:
class: stdClass
properties:
value: 'Pre-update value'
updated_module.deleted_service:
class: stdClass
properties:
value: 'Deleted service, should not exist after update'
services: services:
updated_module.existing_service:
class: stdClass
properties:
value: 'Post-update value'
updated_module.added_service:
class: stdClass
properties:
value: 'New service, should not exist before update'
updated_module.post_apply_subscriber: updated_module.post_apply_subscriber:
class: Drupal\updated_module\PostApplySubscriber class: Drupal\updated_module\PostApplySubscriber
arguments: arguments:
......
...@@ -54,14 +54,14 @@ class SystemChangeRecorder implements EventSubscriberInterface { ...@@ -54,14 +54,14 @@ class SystemChangeRecorder implements EventSubscriberInterface {
* The state service. * The state service.
* @param \Symfony\Component\Routing\RouterInterface $router * @param \Symfony\Component\Routing\RouterInterface $router
* The router service. * The router service.
* @param \Drupal\user\PermissionHandlerInterface $permissionHandler * @param \Drupal\user\PermissionHandlerInterface $permission_handler
* The permission handler service. * The permission handler service.
*/ */
public function __construct(PathLocator $path_locator, StateInterface $state, RouterInterface $router, PermissionHandlerInterface $permissionHandler) { public function __construct(PathLocator $path_locator, StateInterface $state, RouterInterface $router, PermissionHandlerInterface $permission_handler) {
$this->pathLocator = $path_locator; $this->pathLocator = $path_locator;
$this->state = $state; $this->state = $state;
$this->router = $router; $this->router = $router;
$this->permissionHandler = $permissionHandler; $this->permissionHandler = $permission_handler;
} }
/** /**
...@@ -96,10 +96,36 @@ class SystemChangeRecorder implements EventSubscriberInterface { ...@@ -96,10 +96,36 @@ class SystemChangeRecorder implements EventSubscriberInterface {
$results['deleted permission exists'] = array_key_exists('deleted permission', $permissions) ? 'exists' : 'not exists'; $results['deleted permission exists'] = array_key_exists('deleted permission', $permissions) ? 'exists' : 'not exists';
// Check if a permission added in the updated module is available. // Check if a permission added in the updated module is available.
$results['new permission exists'] = array_key_exists('added permission', $permissions) ? 'exists' : 'not exists'; $results['new permission exists'] = array_key_exists('added permission', $permissions) ? 'exists' : 'not exists';
// Check if changes to an existing service are picked up.
$this->recordServiceValue('updated_module.existing_service', $results);
// Check if a service removed from the updated module is available.
$this->recordServiceValue('updated_module.deleted_service', $results);
// Check if a service added in the updated module is available.
$this->recordServiceValue('updated_module.added_service', $results);
$phase = $event instanceof PreApplyEvent ? 'pre' : 'post'; $phase = $event instanceof PreApplyEvent ? 'pre' : 'post';
$this->state->set("system_changes:$phase", $results); $this->state->set("system_changes:$phase", $results);
} }
/**
* Checks if a given service exists, and records its ->value property.
*
* @param string $service_id
* The ID of the service to check.
* @param array $results
* The current set of results, passed by reference.
*/
private function recordServiceValue(string $service_id, array &$results): void {
if (\Drupal::hasService($service_id)) {
$results["$service_id exists"] = 'exists';
$results["value of $service_id"] = \Drupal::service($service_id)->value;
}
else {
$results["$service_id exists"] = 'not exists';
}
}
/** /**
* Writes the results of ::recordSystemState() to file. * Writes the results of ::recordSystemState() to file.
* *
......
...@@ -77,6 +77,11 @@ class PackageUpdateTest extends TemplateProjectTestBase { ...@@ -77,6 +77,11 @@ class PackageUpdateTest extends TemplateProjectTestBase {
'title of changed permission' => 'permission', 'title of changed permission' => 'permission',
'deleted permission exists' => 'exists', 'deleted permission exists' => 'exists',
'new permission exists' => 'not exists', 'new permission exists' => 'not exists',
'updated_module.existing_service exists' => 'exists',
'value of updated_module.existing_service' => 'Pre-update value',
'updated_module.deleted_service exists' => 'exists',
'value of updated_module.deleted_service' => 'Deleted service, should not exist after update',
'updated_module.added_service exists' => 'not exists',
]; ];
$this->assertSame($expected_pre_apply_results, $results['pre']); $this->assertSame($expected_pre_apply_results, $results['pre']);
...@@ -97,6 +102,15 @@ class PackageUpdateTest extends TemplateProjectTestBase { ...@@ -97,6 +102,15 @@ class PackageUpdateTest extends TemplateProjectTestBase {
'deleted permission exists' => 'not exists', 'deleted permission exists' => 'not exists',
// Permissions added to the updated module should be available. // Permissions added to the updated module should be available.
'new permission exists' => 'exists', 'new permission exists' => 'exists',
// The existing generic service should have a new string value.
'updated_module.existing_service exists' => 'exists',
'value of updated_module.existing_service' => 'Post-update value',
// Services deleted from the updated module should not be available.
'updated_module.deleted_service exists' => 'not exists',
// Services added to the updated module should be available and return
// the expected value.
'updated_module.added_service exists' => 'exists',
'value of updated_module.added_service' => 'New service, should not exist before update',
]; ];
$this->assertSame($expected_post_apply_results, $results['post']); $this->assertSame($expected_post_apply_results, $results['post']);
} }
......
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