function PermissionHandlerTest::testPermissionsYamlStaticAndCallback
Same name in other branches
- 9 core/modules/user/tests/src/Unit/PermissionHandlerTest.php \Drupal\Tests\user\Unit\PermissionHandlerTest::testPermissionsYamlStaticAndCallback()
- 8.9.x core/modules/user/tests/src/Unit/PermissionHandlerTest.php \Drupal\Tests\user\Unit\PermissionHandlerTest::testPermissionsYamlStaticAndCallback()
- 11.x core/modules/user/tests/src/Unit/PermissionHandlerTest.php \Drupal\Tests\user\Unit\PermissionHandlerTest::testPermissionsYamlStaticAndCallback()
Tests a YAML file containing both static permissions and a callback.
File
-
core/
modules/ user/ tests/ src/ Unit/ PermissionHandlerTest.php, line 273
Class
- PermissionHandlerTest
- Tests the permission handler.
Namespace
Drupal\Tests\user\UnitCode
public function testPermissionsYamlStaticAndCallback() : void {
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'),
]);
$url = vfsStream::url('modules');
mkdir($url . '/module_a');
file_put_contents($url . '/module_a/module_a.permissions.yml', <<<EOF
'access module a':
title: 'Access A'
description: 'bla bla'
permission_callbacks:
- 'Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription'
EOF
);
$modules = [
'module_a',
];
$this->moduleHandler
->expects($this->any())
->method('getModuleList')
->willReturn(array_flip($modules));
$this->callableResolver
->expects($this->once())
->method('getCallableFromDefinition')
->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription')
->willReturn([
new TestPermissionCallbacks(),
'titleDescription',
]);
$module_extension_list = $this->createMock(ModuleExtensionList::class);
$this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver, $module_extension_list);
$actual_permissions = $this->permissionHandler
->getPermissions();
$this->assertCount(2, $actual_permissions);
$this->assertEquals('Access A', $actual_permissions['access module a']['title']);
$this->assertEquals('module_a', $actual_permissions['access module a']['provider']);
$this->assertEquals('bla bla', $actual_permissions['access module a']['description']);
$this->assertEquals('Access B', $actual_permissions['access module b']['title']);
$this->assertEquals('module_a', $actual_permissions['access module b']['provider']);
$this->assertEquals('bla bla', $actual_permissions['access module b']['description']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.