Skip to content
Snippets Groups Projects
Commit da859f5d authored by Adam G-H's avatar Adam G-H Committed by Ted Bowman
Browse files

Issue #3267632 by phenaproxima: Ensure new, changed or deleted routes are in...

Issue #3267632 by phenaproxima: Ensure new, changed or deleted routes are in the correct state after an update
parent 9ae97d18
No related branches found
No related tags found
1 merge request!234Issue #3267632: Ensure new, changed or deleted routes are in the correct state after an update
...@@ -5,6 +5,18 @@ ...@@ -5,6 +5,18 @@
* Contains global functions for testing updates to a .module file. * Contains global functions for testing updates to a .module file.
*/ */
/**
* Page controller that says hello.
*
* @return array
* A renderable array of the page content.
*/
function updated_module_hello(): array {
return [
'#markup' => 'Hello!',
];
}
/** /**
* A test function to test if global functions are reloaded during an update. * A test function to test if global functions are reloaded during an update.
* *
......
updated_module.changed:
path: '/updated-module/changed/pre'
defaults:
_controller: 'updated_module_hello'
requirements:
_access: 'TRUE'
updated_module.deleted:
path: '/updated-module/deleted'
defaults:
_controller: 'updated_module_hello'
requirements:
_access: 'TRUE'
...@@ -5,6 +5,18 @@ ...@@ -5,6 +5,18 @@
* Contains global functions for testing updates to a .module file. * Contains global functions for testing updates to a .module file.
*/ */
/**
* Page controller that says hello.
*
* @return array
* A renderable array of the page content.
*/
function updated_module_hello(): array {
return [
'#markup' => 'Hello!',
];
}
/** /**
* A test function to test if global functions are reloaded during an update. * A test function to test if global functions are reloaded during an update.
* *
......
updated_module.changed:
path: '/updated-module/changed/post'
defaults:
_controller: 'updated_module_hello'
requirements:
_access: 'TRUE'
updated_module.added:
path: '/updated-module/added'
defaults:
_controller: 'updated_module_hello'
requirements:
_access: 'TRUE'
...@@ -4,5 +4,6 @@ services: ...@@ -4,5 +4,6 @@ services:
arguments: arguments:
- '@package_manager.path_locator' - '@package_manager.path_locator'
- '@state' - '@state'
- '@router.no_access_checks'
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
...@@ -9,6 +9,7 @@ use Drupal\package_manager\Event\PreApplyEvent; ...@@ -9,6 +9,7 @@ use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Event\StageEvent;
use Drupal\package_manager\PathLocator; use Drupal\package_manager\PathLocator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouterInterface;
/** /**
* Defines a service for checking system changes during an update. * Defines a service for checking system changes during an update.
...@@ -29,6 +30,13 @@ class SystemChangeRecorder implements EventSubscriberInterface { ...@@ -29,6 +30,13 @@ class SystemChangeRecorder implements EventSubscriberInterface {
*/ */
private $state; private $state;
/**
* The router service.
*
* @var \Symfony\Component\Routing\RouterInterface
*/
private $router;
/** /**
* Constructs a SystemChangeRecorder object. * Constructs a SystemChangeRecorder object.
* *
...@@ -36,10 +44,13 @@ class SystemChangeRecorder implements EventSubscriberInterface { ...@@ -36,10 +44,13 @@ class SystemChangeRecorder implements EventSubscriberInterface {
* The path locator service. * The path locator service.
* @param \Drupal\Core\State\StateInterface $state * @param \Drupal\Core\State\StateInterface $state
* The state service. * The state service.
* @param \Symfony\Component\Routing\RouterInterface $router
* The router service.
*/ */
public function __construct(PathLocator $path_locator, StateInterface $state) { public function __construct(PathLocator $path_locator, StateInterface $state, RouterInterface $router) {
$this->pathLocator = $path_locator; $this->pathLocator = $path_locator;
$this->state = $state; $this->state = $state;
$this->router = $router;
} }
/** /**
...@@ -56,7 +67,16 @@ class SystemChangeRecorder implements EventSubscriberInterface { ...@@ -56,7 +67,16 @@ class SystemChangeRecorder implements EventSubscriberInterface {
$results['return value of existing global function'] = _updated_module_global1(); $results['return value of existing global function'] = _updated_module_global1();
// Check if a new global function exists after changes are applied. // Check if a new global function exists after changes are applied.
$results['new global function exists'] = function_exists('_update_module_global2') ? "exists" : "not exists"; $results['new global function exists'] = function_exists('_updated_module_global2') ? "exists" : "not exists";
$route_collection = $this->router->getRouteCollection();
// Check if changes to an existing route are picked up.
$results['path of changed route'] = $route_collection->get('updated_module.changed')
->getPath();
// Check if a route removed from the updated module is no longer available.
$results['deleted route exists'] = $route_collection->get('updated_module.deleted') ? 'exists' : 'not exists';
// Check if a route added in the updated module is available.
$results['new route exists'] = $route_collection->get('updated_module.added') ? 'exists' : 'not exists';
$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);
......
...@@ -71,6 +71,9 @@ class PackageUpdateTest extends TemplateProjectTestBase { ...@@ -71,6 +71,9 @@ class PackageUpdateTest extends TemplateProjectTestBase {
$expected_pre_apply_results = [ $expected_pre_apply_results = [
'return value of existing global function' => 'pre-update-value', 'return value of existing global function' => 'pre-update-value',
'new global function exists' => 'not exists', 'new global function exists' => 'not exists',
'path of changed route' => '/updated-module/changed/pre',
'deleted route exists' => 'exists',
'new route exists' => 'not exists',
]; ];
$this->assertSame($expected_pre_apply_results, $results['pre']); $this->assertSame($expected_pre_apply_results, $results['pre']);
...@@ -79,6 +82,12 @@ class PackageUpdateTest extends TemplateProjectTestBase { ...@@ -79,6 +82,12 @@ class PackageUpdateTest extends TemplateProjectTestBase {
'return value of existing global function' => 'pre-update-value', 'return value of existing global function' => 'pre-update-value',
// New functions that were added in .module files will not be available. // New functions that were added in .module files will not be available.
'new global function exists' => 'not exists', 'new global function exists' => 'not exists',
// Definitions for existing routes should be updated.
'path of changed route' => '/updated-module/changed/post',
// Routes deleted from the updated module should not be available.
'deleted route exists' => 'not exists',
// Routes added to the updated module should be available.
'new route exists' => 'exists',
]; ];
$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