function SuperUserAccessInstallTest::getInstallTests
Same name in other branches
- 11.x core/tests/Drupal/FunctionalTests/Installer/SuperUserAccessInstallTest.php \Drupal\FunctionalTests\Installer\SuperUserAccessInstallTest::getInstallTests()
File
-
core/
tests/ Drupal/ FunctionalTests/ Installer/ SuperUserAccessInstallTest.php, line 90
Class
- SuperUserAccessInstallTest
- Tests superuser access and the installer.
Namespace
Drupal\FunctionalTests\InstallerCode
public static function getInstallTests() : array {
$test_cases = [];
$test_cases['runtime super user policy enabled'] = [
'expected_runtime_has_permission' => TRUE,
'expected_no_access_message' => FALSE,
'expected_roles' => [],
'install_code' => <<<PHP
<?php
function superuser_install() {
\$user = \\Drupal\\user\\Entity\\User::load(1);
\\Drupal::state()->set('admin_permission_in_installer', \$user->hasPermission('administer software updates'));
}
PHP
,
'super_user_policy' => TRUE,
];
$test_cases['no super user policy enabled and no admin role'] = [
'expected_runtime_has_permission' => FALSE,
'expected_no_access_message' => TRUE,
'expected_roles' => [],
'install_code' => $test_cases['runtime super user policy enabled']['install_code'],
'super_user_policy' => FALSE,
];
$test_cases['no super user policy enabled and admin role'] = [
'expected_runtime_has_permission' => TRUE,
'expected_no_access_message' => FALSE,
'expected_roles' => [
'admin_role',
],
'install_code' => <<<PHP
<?php
function superuser_install() {
\$user = \\Drupal\\user\\Entity\\User::load(1);
\\Drupal::state()->set('admin_permission_in_installer', \$user->hasPermission('administer software updates'));
\\Drupal\\user\\Entity\\Role::create(['id' => 'admin_role', 'label' => 'Admin role'])->setIsAdmin(TRUE)->save();
\\Drupal\\user\\Entity\\Role::create(['id' => 'another_role', 'label' => 'Another role'])->save();
}
PHP
,
'super_user_policy' => FALSE,
];
$test_cases['no super user policy enabled and multiple admin role'] = [
'expected_runtime_has_permission' => TRUE,
'expected_no_access_message' => FALSE,
'expected_roles' => [
'admin_role',
'another_admin_role',
],
'install_code' => <<<PHP
<?php
function superuser_install() {
\$user = \\Drupal\\user\\Entity\\User::load(1);
\\Drupal::state()->set('admin_permission_in_installer', \$user->hasPermission('administer software updates'));
\\Drupal\\user\\Entity\\Role::create(['id' => 'admin_role', 'label' => 'Admin role'])->setIsAdmin(TRUE)->save();
\\Drupal\\user\\Entity\\Role::create(['id' => 'another_admin_role', 'label' => 'Another admin role'])->setIsAdmin(TRUE)->save();
\\Drupal\\user\\Entity\\Role::create(['id' => 'another_role', 'label' => 'Another role'])->save();
}
PHP
,
'super_user_policy' => FALSE,
];
return $test_cases;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.