public function PermissionHandlerTest::testBuildPermissionsSortPerModule in Drupal 8
Same name and namespace in other branches
- 9 core/modules/user/tests/src/Unit/PermissionHandlerTest.php \Drupal\Tests\user\Unit\PermissionHandlerTest::testBuildPermissionsSortPerModule()
- 10 core/modules/user/tests/src/Unit/PermissionHandlerTest.php \Drupal\Tests\user\Unit\PermissionHandlerTest::testBuildPermissionsSortPerModule()
Tests permissions sort inside a module.
@covers ::__construct @covers ::getPermissions @covers ::buildPermissionsYaml @covers ::sortPermissions
File
- core/
modules/ user/ tests/ src/ Unit/ PermissionHandlerTest.php, line 164 - Contains \Drupal\Tests\user\Unit\PermissionHandlerTest.
Class
- PermissionHandlerTest
- Tests the permission handler.
Namespace
Drupal\Tests\user\UnitCode
public function testBuildPermissionsSortPerModule() {
vfsStreamWrapper::register();
$root = new vfsStreamDirectory('modules');
vfsStreamWrapper::setRoot($root);
$this->moduleHandler = $this
->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$this->moduleHandler
->expects($this
->once())
->method('getModuleDirectories')
->willReturn([
'module_a' => vfsStream::url('modules/module_a'),
'module_b' => vfsStream::url('modules/module_b'),
'module_c' => vfsStream::url('modules/module_c'),
]);
$this->moduleHandler
->expects($this
->exactly(3))
->method('getName')
->will($this
->returnValueMap([
[
'module_a',
'Module a',
],
[
'module_b',
'Module b',
],
[
'module_c',
'A Module',
],
]));
$url = vfsStream::url('modules');
mkdir($url . '/module_a');
file_put_contents($url . '/module_a/module_a.permissions.yml', <<<EOF
access_module_a2: single_description2
access_module_a1: single_description1
EOF
);
mkdir($url . '/module_b');
file_put_contents($url . '/module_b/module_b.permissions.yml', "access_module_a3: single_description");
mkdir($url . '/module_c');
file_put_contents($url . '/module_c/module_c.permissions.yml', "access_module_a4: single_description");
$modules = [
'module_a',
'module_b',
'module_c',
];
$this->moduleHandler
->expects($this
->once())
->method('getModuleList')
->willReturn(array_flip($modules));
$permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver);
$actual_permissions = $permissionHandler
->getPermissions();
$this
->assertEquals([
'access_module_a4',
'access_module_a1',
'access_module_a2',
'access_module_a3',
], array_keys($actual_permissions));
}