Skip to content
Snippets Groups Projects
Commit 3b8307bc authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2329429 by dawehner: Fixed Permission page order is all wackadoo.

parent 12ee21a3
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -80,7 +80,7 @@ public function getPermissions() {
$all_permissions += $this->buildPermissionsModules();
return $this->sortPermissionsByProviderName($all_permissions);
return $this->sortPermissions($all_permissions);
}
/**
......@@ -138,7 +138,7 @@ protected function buildPermissionsModules() {
}
/**
* Sorts the given permissions by provider name.
* Sorts the given permissions by provider name and title.
*
* @param array $all_permissions
* The permissions to be sorted.
......@@ -149,13 +149,18 @@ protected function buildPermissionsModules() {
* - description: The description of the permission, defaults to NULL.
* - provider: The provider of the permission.
*/
protected function sortPermissionsByProviderName(array $all_permissions = array()) {
protected function sortPermissions(array $all_permissions = array()) {
// Get a list of all the modules providing permissions and sort by
// display name.
$modules = $this->getModuleNames();
uasort($all_permissions, function (array $permission_a, array $permission_b) use ($modules) {
return $modules[$permission_a['provider']] > $modules[$permission_b['provider']];
if ($modules[$permission_a['provider']] == $modules[$permission_b['provider']]) {
return $permission_a['title'] > $permission_b['title'];
}
else {
return $modules[$permission_a['provider']] > $modules[$permission_b['provider']];
}
});
return $all_permissions;
}
......
......@@ -75,7 +75,7 @@ protected function mockModuleExtension($module, $name) {
* @covers ::getPermissions
* @covers ::buildPermissions
* @covers ::buildPermissionsModules
* @covers ::sortPermissionsByProviderName
* @covers ::sortPermissions
* @covers ::getModuleNames
*/
public function testBuildPermissionsModules() {
......@@ -124,6 +124,7 @@ public function testBuildPermissionsModules() {
$this->assertSame(array('access_module_a', 'access_module_c', 'access module b'), array_keys($actual_permissions));
}
/**
* Tests permissions provided by YML files.
*
......@@ -188,6 +189,56 @@ public function testBuildPermissionsYaml() {
$this->assertPermissions($actual_permissions);
}
/**
* Tests permissions sort inside a module.
*
* @covers ::__construct
* @covers ::getPermissions
* @covers ::buildPermissions
* @covers ::buildPermissionsYaml
* @covers ::sortPermissions
*/
public function testBuildPermissionsSortPerModule() {
vfsStreamWrapper::register();
$root = new vfsStreamDirectory('modules');
vfsStreamWrapper::setRoot($root);
$this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
$this->moduleHandler->expects($this->once())
->method('getModuleDirectories')
->willReturn([
'module_a' => vfsStream::url('modules/module_a'),
]);
$url = vfsStream::url('modules');
mkdir($url . '/module_a');
file_put_contents($url . '/module_a/module_a.permissions.yml',
"access_module_a2: single_description
access_module_a1: single_description"
);
$modules = ['module_a'];
$extensions = [
'module_a' => $this->mockModuleExtension('module_a', 'Module a'),
];
$this->moduleHandler->expects($this->any())
->method('getImplementations')
->with('permission')
->willReturn([]);
$this->moduleHandler->expects($this->any())
->method('getModuleList')
->willReturn(array_flip($modules));
$this->permissionHandler = new TestPermissionHandler($this->moduleHandler, $this->stringTranslation);
// Setup system_rebuild_module_data().
$this->permissionHandler->setSystemRebuildModuleData($extensions);
$actual_permissions = $this->permissionHandler->getPermissions();
$this->assertEquals(['access_module_a1', 'access_module_a2'], array_keys($actual_permissions));
}
/**
* Checks that the permissions are like expected.
*
......
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