Skip to content
Snippets Groups Projects
Commit bb62e6c8 authored by Fran Garcia-Linares's avatar Fran Garcia-Linares
Browse files

Bring patch to 11.x

parent 717b02a8
No related branches found
No related tags found
1 merge request!8776Route migrate process plugin shouldn't assume that the $options variable is always an array
...@@ -131,7 +131,9 @@ public function transform($value, MigrateExecutableInterface $migrate_executable ...@@ -131,7 +131,9 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$options['query'] = $route['options']['query'] + $old_query; $options['query'] = $route['options']['query'] + $old_query;
unset($route['options']['query']); unset($route['options']['query']);
} }
$route['options'] = $route['options'] + $options; if (is_array($options)) {
$route['options'] += $options;
}
$route['url'] = NULL; $route['url'] = NULL;
} }
} }
......
...@@ -29,6 +29,19 @@ class RouteTest extends KernelTestBase { ...@@ -29,6 +29,19 @@ class RouteTest extends KernelTestBase {
*/ */
protected static $modules = ['user', 'system']; protected static $modules = ['user', 'system'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// We have to configure a front page since
// PathProcessorFront::processInbound relies on it for missing paths.
$this->config('system.site')
->set('page.front', 'user')
->save();
}
/** /**
* Tests Route plugin based on providerTestRoute() values. * Tests Route plugin based on providerTestRoute() values.
* *
...@@ -52,141 +65,150 @@ public function testRoute($value, $expected): void { ...@@ -52,141 +65,150 @@ public function testRoute($value, $expected): void {
* process plugin, and the second is the expected results. * process plugin, and the second is the expected results.
*/ */
public static function providerTestRoute() { public static function providerTestRoute() {
// Internal link tests. return [
// Valid link path and options. 'Valid internal link path and options' => [
$values[0] = [ 'data' => [
'user/login', 'user/login',
[ [
'attributes' => [ 'attributes' => [
'title' => 'Test menu link 1', 'title' => 'Test menu link 1',
],
],
], ],
], 'expected' => [
]; 'route_name' => 'user.login',
$expected[0] = [ 'route_parameters' => [],
'route_name' => 'user.login', 'options' => [
'route_parameters' => [], 'query' => [],
'options' => [ 'attributes' => [
'query' => [], 'title' => 'Test menu link 1',
'attributes' => [ ],
'title' => 'Test menu link 1', ],
'url' => NULL,
], ],
], ],
'url' => NULL, 'Valid internal link path and empty options' => [
]; 'data' => [
'user/login',
// Valid link path and empty options. [],
$values[1] = [ ],
'user/login', 'expected' => [
[], 'route_name' => 'user.login',
]; 'route_parameters' => [],
$expected[1] = [ 'options' => [
'route_name' => 'user.login', 'query' => [],
'route_parameters' => [], ],
'options' => [ 'url' => NULL,
'query' => [], ],
], ],
'url' => NULL, 'Valid internal link path and no options' => [
]; 'data' => 'user/login',
'expected' => [
// Valid link path and no options. 'route_name' => 'user.login',
$values[2] = 'user/login'; 'route_parameters' => [],
$expected[2] = [ 'options' => [
'route_name' => 'user.login', 'query' => [],
'route_parameters' => [], ],
'options' => [ 'url' => NULL,
'query' => [], ],
], ],
'url' => NULL, 'Valid internal link path and non-array options' => [
]; 'data' => [
'user/login',
// Invalid link path. 'options',
$values[3] = 'users'; ],
$expected[3] = []; 'expected' => [
'route_name' => 'user.login',
// Valid link path with parameter. 'route_parameters' => [],
$values[4] = [ 'options' => [
'system/timezone/nzdt', 'query' => [],
[ ],
'attributes' => [ 'url' => NULL,
'title' => 'Show NZDT',
], ],
], ],
]; 'Invalid internal link path' => [
$expected[4] = [ 'data' => 'users',
'route_name' => 'system.timezone', 'expected' => [],
'route_parameters' => [
'abbreviation' => 'nzdt',
'offset' => -1,
'is_daylight_saving_time' => NULL,
], ],
'options' => [ 'Valid internal link path with parameter' => [
'query' => [], 'data' => [
'attributes' => [ 'system/timezone/nzdt',
'title' => 'Show NZDT', [
'attributes' => [
'title' => 'Show NZDT',
],
],
], ],
], 'expected' => [
'url' => NULL, 'route_name' => 'system.timezone',
]; 'route_parameters' => [
'abbreviation' => 'nzdt',
// External link tests. 'offset' => -1,
// Valid external link path and options. 'is_daylight_saving_time' => NULL,
$values[5] = [ ],
'https://www.drupal.org', 'options' => [
[ 'query' => [],
'attributes' => [ 'attributes' => [
'title' => 'Drupal', 'title' => 'Show NZDT',
],
],
'url' => NULL,
], ],
], ],
]; 'Valid external link path and options' => [
$expected[5] = [ 'data' => [
'route_name' => NULL, 'https://www.drupal.org',
'route_parameters' => [], [
'options' => [ 'attributes' => [
'attributes' => [ 'title' => 'Drupal',
'title' => 'Drupal', ],
],
],
'expected' => [
'route_name' => NULL,
'route_parameters' => [],
'options' => [
'attributes' => [
'title' => 'Drupal',
],
],
'url' => 'https://www.drupal.org',
], ],
], ],
'url' => 'https://www.drupal.org', 'Valid external link path with query string and options' => [
]; 'data' => [
'https://www.drupal.org/user/1/edit?pass-reset-token=QgtDKcRV4e4fjg6v2HTa6CbWx-XzMZ5XBZTufinqsM73qIhscIuU_BjZ6J2tv4dQI6N50ZJOag',
// Valid external link path and options. [
$values[6] = [ 'attributes' => [
'https://www.drupal.org/user/1/edit?pass-reset-token=QgtDKcRV4e4fjg6v2HTa6CbWx-XzMZ5XBZTufinqsM73qIhscIuU_BjZ6J2tv4dQI6N50ZJOag', 'title' => 'Drupal password reset',
[ ],
'attributes' => [ ],
'title' => 'Drupal password reset', ],
'expected' => [
'route_name' => NULL,
'route_parameters' => [],
'options' => [
'attributes' => [
'title' => 'Drupal password reset',
],
],
'url' => 'https://www.drupal.org/user/1/edit?pass-reset-token=QgtDKcRV4e4fjg6v2HTa6CbWx-XzMZ5XBZTufinqsM73qIhscIuU_BjZ6J2tv4dQI6N50ZJOag',
], ],
], ],
]; 'Null link path with options' => [
$expected[6] = [ 'data' => [
'route_name' => NULL, NULL,
'route_parameters' => [], NULL,
'options' => [ ],
'attributes' => [ 'expected' => [
'title' => 'Drupal password reset', 'route_name' => 'user.page',
'route_parameters' => [],
'options' => [
'query' => [],
],
'url' => NULL,
], ],
], ],
'url' => 'https://www.drupal.org/user/1/edit?pass-reset-token=QgtDKcRV4e4fjg6v2HTa6CbWx-XzMZ5XBZTufinqsM73qIhscIuU_BjZ6J2tv4dQI6N50ZJOag',
];
return [
// Test data for internal paths.
// Test with valid link path and options.
[$values[0], $expected[0]],
// Test with valid link path and empty options.
[$values[1], $expected[1]],
// Test with valid link path and no options.
[$values[2], $expected[2]],
// Test with Invalid link path.
[$values[3], $expected[3]],
// Test with Valid link path with query options and parameters.
[$values[4], $expected[4]],
// Test data for external paths.
// Test with external link path and options.
[$values[5], $expected[5]],
// Test with valid link path and query options.
[$values[6], $expected[6]],
]; ];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment