function PermissionHandlerTest::testBuildPermissionsYaml
Same name in other branches
- 8.9.x core/modules/user/tests/src/Unit/PermissionHandlerTest.php \Drupal\Tests\user\Unit\PermissionHandlerTest::testBuildPermissionsYaml()
- 10 core/modules/user/tests/src/Unit/PermissionHandlerTest.php \Drupal\Tests\user\Unit\PermissionHandlerTest::testBuildPermissionsYaml()
- 11.x core/modules/user/tests/src/Unit/PermissionHandlerTest.php \Drupal\Tests\user\Unit\PermissionHandlerTest::testBuildPermissionsYaml()
Tests permissions provided by YML files.
@covers ::__construct @covers ::getPermissions @covers ::buildPermissionsYaml @covers ::moduleProvidesPermissions
File
-
core/
modules/ user/ tests/ src/ Unit/ PermissionHandlerTest.php, line 92
Class
- PermissionHandlerTest
- Tests the permission handler.
Namespace
Drupal\Tests\user\UnitCode
public function testBuildPermissionsYaml() {
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'),
]);
$url = vfsStream::url('modules');
mkdir($url . '/module_a');
file_put_contents($url . '/module_a/module_a.permissions.yml', "access_module_a: single_description");
mkdir($url . '/module_b');
file_put_contents($url . '/module_b/module_b.permissions.yml', <<<EOF
'access module b':
title: 'Access B'
description: 'bla bla'
'access module a via module b':
title: 'Access A via B'
provider: 'module_a'
EOF
);
mkdir($url . '/module_c');
file_put_contents($url . '/module_c/module_c.permissions.yml', <<<EOF
'access_module_c':
title: 'Access C'
description: 'bla bla'
'restrict access': TRUE
EOF
);
$modules = [
'module_a',
'module_b',
'module_c',
];
$this->moduleHandler
->expects($this->any())
->method('getModuleList')
->willReturn(array_flip($modules));
$this->controllerResolver
->expects($this->never())
->method('getControllerFromDefinition');
$this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver);
$actual_permissions = $this->permissionHandler
->getPermissions();
$this->assertPermissions($actual_permissions);
$this->assertTrue($this->permissionHandler
->moduleProvidesPermissions('module_a'));
$this->assertTrue($this->permissionHandler
->moduleProvidesPermissions('module_b'));
$this->assertTrue($this->permissionHandler
->moduleProvidesPermissions('module_c'));
$this->assertFalse($this->permissionHandler
->moduleProvidesPermissions('module_d'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.