From 7f2dd0dafdba233d2e452e52945bc01024742d85 Mon Sep 17 00:00:00 2001 From: Brian Canini <canini.16@osu.edu> Date: Tue, 30 Jun 2020 15:38:05 -0400 Subject: [PATCH] Updating drupal/roleassign (1.0.0-alpha2 => 1.0.0-beta1) --- composer.json | 2 +- composer.lock | 32 ++++++------- vendor/composer/installed.json | 32 ++++++------- web/modules/roleassign/CHANGELOG.txt | 14 +++++- web/modules/roleassign/README.txt | 10 ++++ web/modules/roleassign/composer.json | 13 +++++ web/modules/roleassign/roleassign.info.yml | 10 ++-- .../roleassign/roleassign.links.menu.yml | 9 ++-- .../roleassign/roleassign.links.task.yml | 5 ++ web/modules/roleassign/roleassign.module | 28 +++++++---- .../roleassign/roleassign.permissions.yml | 2 +- web/modules/roleassign/roleassign.routing.yml | 2 +- .../src/Form/RoleAssignAdminForm.php | 9 +--- .../views/field/RoleAssignUserBulkForm.php | 7 +-- .../RoleAssignUninstallValidator.php | 6 +-- .../src/RoleAssignUninstallValidator.php | 20 +++++--- .../Functional}/RoleAssignPermissionTest.php | 48 +++++++++---------- 17 files changed, 145 insertions(+), 104 deletions(-) mode change 100644 => 100755 web/modules/roleassign/README.txt create mode 100644 web/modules/roleassign/composer.json create mode 100644 web/modules/roleassign/roleassign.links.task.yml mode change 100644 => 100755 web/modules/roleassign/roleassign.module rename web/modules/roleassign/{src/Tests => tests/src/Functional}/RoleAssignPermissionTest.php (82%) diff --git a/composer.json b/composer.json index d7ad8e5963..b0e05493a1 100644 --- a/composer.json +++ b/composer.json @@ -155,7 +155,7 @@ "drupal/recaptcha": "2.5", "drupal/redirect": "1.6", "drupal/redis": "1.0", - "drupal/roleassign": "1.0.0-alpha2", + "drupal/roleassign": "1.0.0-beta1", "drupal/scheduler": "1.3", "drupal/search_api": "1.17", "drupal/search_api_db": "1.17", diff --git a/composer.lock b/composer.lock index b4fa092ecd..c69d2f54f0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b9be0e811209c12590dacc555ae9d6b5", + "content-hash": "663fff2bde862e3307ff7dee0ec7b108", "packages": [ { "name": "alchemy/zippy", @@ -6913,38 +6913,35 @@ }, { "name": "drupal/roleassign", - "version": "1.0.0-alpha2", + "version": "1.0.0-beta1", "source": { "type": "git", "url": "https://git.drupalcode.org/project/roleassign.git", - "reference": "8.x-1.0-alpha2" + "reference": "8.x-1.0-beta1" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/roleassign-8.x-1.0-alpha2.zip", - "reference": "8.x-1.0-alpha2", - "shasum": "e2c4cb24dd1bce59f4edcb3488377d2b12769136" + "url": "https://ftp.drupal.org/files/projects/roleassign-8.x-1.0-beta1.zip", + "reference": "8.x-1.0-beta1", + "shasum": "54848544164fdd7abcdb21b192eaf9788dc2da6d" }, "require": { - "drupal/core": "~8.0" + "drupal/core": "^8 || ^9" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - }, "drupal": { - "version": "8.x-1.0-alpha2", - "datestamp": "1454394539", + "version": "8.x-1.0-beta1", + "datestamp": "1582204691", "security-coverage": { "status": "not-covered", - "message": "Alpha releases are not covered by Drupal security advisories." + "message": "Beta releases are not covered by Drupal security advisories." } } }, "notification-url": "https://packages.drupal.org/8/downloads", "license": [ - "GPL-2.0-or-later" + "GPL-2.0+" ], "authors": [ { @@ -6952,10 +6949,11 @@ "homepage": "https://www.drupal.org/user/82964" } ], - "description": "Allows site administrators to further delegate the task of managing user's roles.", - "homepage": "https://www.drupal.org/project/roleassign", + "description": "Allows site administrators to further delegate the task of managing user''s roles.", + "homepage": "http://drupal.org/project/roleassign", "support": { - "source": "http://cgit.drupalcode.org/roleassign" + "source": "https://git.drupalcode.org/project/roleassign", + "issues": "https://www.drupal.org/project/issues/roleassign" } }, { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 1665601de5..ab7fdf081c 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -7124,40 +7124,37 @@ }, { "name": "drupal/roleassign", - "version": "1.0.0-alpha2", - "version_normalized": "1.0.0.0-alpha2", + "version": "1.0.0-beta1", + "version_normalized": "1.0.0.0-beta1", "source": { "type": "git", "url": "https://git.drupalcode.org/project/roleassign.git", - "reference": "8.x-1.0-alpha2" + "reference": "8.x-1.0-beta1" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/roleassign-8.x-1.0-alpha2.zip", - "reference": "8.x-1.0-alpha2", - "shasum": "e2c4cb24dd1bce59f4edcb3488377d2b12769136" + "url": "https://ftp.drupal.org/files/projects/roleassign-8.x-1.0-beta1.zip", + "reference": "8.x-1.0-beta1", + "shasum": "54848544164fdd7abcdb21b192eaf9788dc2da6d" }, "require": { - "drupal/core": "~8.0" + "drupal/core": "^8 || ^9" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - }, "drupal": { - "version": "8.x-1.0-alpha2", - "datestamp": "1454394539", + "version": "8.x-1.0-beta1", + "datestamp": "1582204691", "security-coverage": { "status": "not-covered", - "message": "Alpha releases are not covered by Drupal security advisories." + "message": "Beta releases are not covered by Drupal security advisories." } } }, "installation-source": "dist", "notification-url": "https://packages.drupal.org/8/downloads", "license": [ - "GPL-2.0-or-later" + "GPL-2.0+" ], "authors": [ { @@ -7165,10 +7162,11 @@ "homepage": "https://www.drupal.org/user/82964" } ], - "description": "Allows site administrators to further delegate the task of managing user's roles.", - "homepage": "https://www.drupal.org/project/roleassign", + "description": "Allows site administrators to further delegate the task of managing user''s roles.", + "homepage": "http://drupal.org/project/roleassign", "support": { - "source": "http://cgit.drupalcode.org/roleassign" + "source": "https://git.drupalcode.org/project/roleassign", + "issues": "https://www.drupal.org/project/issues/roleassign" } }, { diff --git a/web/modules/roleassign/CHANGELOG.txt b/web/modules/roleassign/CHANGELOG.txt index b15ace8694..8fab9b0d0a 100644 --- a/web/modules/roleassign/CHANGELOG.txt +++ b/web/modules/roleassign/CHANGELOG.txt @@ -5,11 +5,23 @@ CHANGELOG for RoleAssign for Drupal 8 roleassign 8.x-1.x-dev: +roleassign 8.x-1.0-beta1 (2020-02-20): + Issue #2882158 by Munavijayalakshmi, salvis, amit.drupal: Convert module to use short array syntax (new coding standard). + Issue #3114240 by emek: Restrict roles when adding users with the CAS module. + Issue #3042823 by franskuipers, Berdir: Drupal 9 Deprecated Code Report. + Issue #3065871 by AkashkumarOSL, AmandeepKaur, Berdir: Adding Composer.json File. + Issue #2964630 by salvis: Move the Role Assign settings from "Configuration" to "People" where it's more easily found. + Issue #2935117 by idebr: Can't uninstall with Drush. + Issue by salvis: Add self-evident warning to the README.txt file. + Issue #2766347 by Vinay15, Dane Powell: Remove @file tag docblock from all the .php files. + Issue #2661864 by heykarthikwithu: Remove unused imports in the code base. + Issue #2758855 by Alan-H: Fix Hard-sets the Authenticated User role. + + roleassign 8.x-1.0-alpha2 (2016-02-02): Issue #2657668 by salvis, svendecabooter: Avoid uninitialized $assigned_roles variable. Issue #2658028 by svendecabooter: Provide default values for config entity. - roleassign 8.x-1.0-alpha1 (2015-11-25): Issue #2405341 by svendecabooter, tkuldeep17, salvis: Initial port to D8. Issue #2405341: Branch to port to D8. diff --git a/web/modules/roleassign/README.txt b/web/modules/roleassign/README.txt old mode 100644 new mode 100755 index 23306c1b37..8243acb25f --- a/web/modules/roleassign/README.txt +++ b/web/modules/roleassign/README.txt @@ -82,3 +82,13 @@ permissions. assignable roles and change them as necessary. +BEWARE +------ + +'Administer users' is and remains a security-critical permission that must NOT +be given to untrusted users! RoleAssign will keep your assistant admins within +their limits, but if you introduce alternative ways to edit users, assign roles, +or give permissions (like the "Administration: Users" view in the popular +Administration Views module), then you may be opening up ways for your +assistant admins to gain additional privileges. + diff --git a/web/modules/roleassign/composer.json b/web/modules/roleassign/composer.json new file mode 100644 index 0000000000..1c4bdebbee --- /dev/null +++ b/web/modules/roleassign/composer.json @@ -0,0 +1,13 @@ +{ + "name": "drupal/roleassign", + "description": "Allows site administrators to further delegate the task of managing user''s roles.", + "type": "drupal-module", + "homepage": "http://drupal.org/project/roleassign", + "support": { + "issues": "https://www.drupal.org/project/issues/roleassign" + }, + "license": "GPL-2.0+", + "require": { + "drupal/core": "^8 || ^9" + } +} diff --git a/web/modules/roleassign/roleassign.info.yml b/web/modules/roleassign/roleassign.info.yml index dc0bd1cb8c..b218c4f733 100644 --- a/web/modules/roleassign/roleassign.info.yml +++ b/web/modules/roleassign/roleassign.info.yml @@ -1,11 +1,11 @@ name: RoleAssign description: 'Allows site administrators to further delegate the task of managing user''s roles.' -# core: 8.x +core: 8.x +core_version_requirement: ^8 || ^9 type: module configure: roleassign.settings -# Information added by Drupal.org packaging script on 2016-02-02 -version: '8.x-1.0-alpha2' -core: '8.x' +# Information added by Drupal.org packaging script on 2020-02-20 +version: '8.x-1.0-beta1' project: 'roleassign' -datestamp: 1454396974 +datestamp: 1582203773 diff --git a/web/modules/roleassign/roleassign.links.menu.yml b/web/modules/roleassign/roleassign.links.menu.yml index f7c5b6e835..18d1546d6b 100644 --- a/web/modules/roleassign/roleassign.links.menu.yml +++ b/web/modules/roleassign/roleassign.links.menu.yml @@ -1,7 +1,6 @@ roleassign.settings: - title: 'RoleAssign settings' - parent: user.admin_index - description: "Configuration settings to further delegate the task of managing user's roles." - weight: -8 + title: 'Role assign' + parent: entity.user.collection + description: "Define the roles that can be assigned via the 'Assign roles' permission." + weight: 10 route_name: roleassign.settings - menu_name: admin diff --git a/web/modules/roleassign/roleassign.links.task.yml b/web/modules/roleassign/roleassign.links.task.yml new file mode 100644 index 0000000000..42b4f126be --- /dev/null +++ b/web/modules/roleassign/roleassign.links.task.yml @@ -0,0 +1,5 @@ +roleassign.settings: + title: 'Role assign' + route_name: roleassign.settings + base_route: entity.user.collection + weight: 15 diff --git a/web/modules/roleassign/roleassign.module b/web/modules/roleassign/roleassign.module old mode 100644 new mode 100755 index cc418cb4bb..d871d46863 --- a/web/modules/roleassign/roleassign.module +++ b/web/modules/roleassign/roleassign.module @@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Url; use Drupal\user\RoleInterface; /** @@ -37,12 +38,12 @@ function roleassign_help($route_name, RouteMatchInterface $route_match) { <ol> <li>Log in as a user with both the Assign roles and the Administer users permissions.</li> <li>To change the roles of a user, go to the user\'s account and review the assignable roles and change them as necessary.</li> - </ol>', array( + </ol>', [ ':user_protect' => 'http://drupal.org/project/userprotect', - ) + ] ); case 'roleassign.settings': - return t('Users with both %administer_users and %assign_roles permissions are allowed to assign the roles selected below. For more information, see the <a href=":help">help page</a>.', array('%administer_users' => $permissions['administer users']['title'], '%assign_roles' => $permissions['assign roles']['title'], ':help' => \Drupal::url('help.page', array ('name' => 'roleassign')))); + return t('Users with both %administer_users and %assign_roles permissions are allowed to assign the roles selected below. For more information, see the <a href=":help">help page</a>.', ['%administer_users' => $permissions['administer users']['title'], '%assign_roles' => $permissions['assign roles']['title'], ':help' => Url::fromRoute('help.page', ['name' => 'roleassign'])->toString()]); } } @@ -99,16 +100,16 @@ function roleassign_form_alter(&$form, FormStateInterface $form_state, $form_id) $sticky_roles[RoleInterface::AUTHENTICATED_ID] = $roles[RoleInterface::AUTHENTICATED_ID]; // Store sticky roles in form values. - $form['sticky_roles'] = array('#type' => 'value', '#value' => $sticky_roles); + $form['sticky_roles'] = ['#type' => 'value', '#value' => $sticky_roles]; // Build the assign roles checkboxes. - $roles_field = array( + $roles_field = [ '#type' => 'checkboxes', '#title' => t('Assignable roles'), '#options' => $assignable_roles, - '#default_value' => empty($assigned_roles) ? array() : array_keys($assigned_roles), - '#description' => t('The user receives the combined permissions of all roles selected here and the following roles: %roles.', array('%roles' => implode(', ', $sticky_roles))), - ); + '#default_value' => empty($assigned_roles) ? [] : array_keys($assigned_roles), + '#description' => t('The user receives the combined permissions of all roles selected here and the following roles: %roles.', ['%roles' => implode(', ', $sticky_roles)]), + ]; // The user form is sometimes within an 'account' fieldset. if (isset($form['account'])) { $user_form =&$form['account']; @@ -129,6 +130,15 @@ function roleassign_form_alter(&$form, FormStateInterface $form_state, $form_id) $user_form['roles'] = $roles_field; } } + elseif (\Drupal::moduleHandler()->moduleExists('cas') && $form_id == 'bulk_add_cas_users') { + // Get all roles that are available. + $roles = user_role_names(TRUE); + + // Get roles that are available for assignment. + $assignable_roles = array_intersect_key($roles, array_filter(\Drupal::config('roleassign.settings')->get('roleassign_roles'))); + + $form['roles']['#options'] = $assignable_roles; + } } } @@ -181,6 +191,8 @@ function roleassign_user_presave($account) { */ function roleassign_get_unassignable_roles() { $all_roles = user_role_names(TRUE); + // Ignore Authenticated user as this is not required. + unset($all_roles[RoleInterface::AUTHENTICATED_ID]); $assignable_roles = array_filter(\Drupal::config('roleassign.settings')->get('roleassign_roles')); $unassignable_roles = array_diff(array_keys($all_roles), $assignable_roles); return $unassignable_roles; diff --git a/web/modules/roleassign/roleassign.permissions.yml b/web/modules/roleassign/roleassign.permissions.yml index 2aef0e3c49..d5689d3f2a 100644 --- a/web/modules/roleassign/roleassign.permissions.yml +++ b/web/modules/roleassign/roleassign.permissions.yml @@ -1,4 +1,4 @@ assign roles: title: 'Assign roles' - description: 'Allow users with the Administer users permission to assign a restricted set of roles.' + description: 'Allow users with the "Administer users" permission to assign a <a href="/admin/people/roleassign">restricted set of roles</a>.' restrict access: true diff --git a/web/modules/roleassign/roleassign.routing.yml b/web/modules/roleassign/roleassign.routing.yml index 0dc564a14b..b88d473f0c 100644 --- a/web/modules/roleassign/roleassign.routing.yml +++ b/web/modules/roleassign/roleassign.routing.yml @@ -1,5 +1,5 @@ roleassign.settings: - path: '/admin/config/people/roleassign' + path: '/admin/people/roleassign' defaults: _form: '\Drupal\roleassign\Form\RoleAssignAdminForm' _title: 'Role assign' diff --git a/web/modules/roleassign/src/Form/RoleAssignAdminForm.php b/web/modules/roleassign/src/Form/RoleAssignAdminForm.php index 09aafdcdc7..2f34900e8c 100644 --- a/web/modules/roleassign/src/Form/RoleAssignAdminForm.php +++ b/web/modules/roleassign/src/Form/RoleAssignAdminForm.php @@ -1,10 +1,5 @@ <?php -/** - * @file - * Contains \Drupal\roleassign\Form\RoleAssignAdminForm. - */ - namespace Drupal\roleassign\Form; use Drupal\Core\Form\ConfigFormBase; @@ -42,13 +37,13 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Show checkboxes with roles that can be delegated if any. if ($roles) { $config = $this->config('roleassign.settings'); - $form['roleassign_roles'] = array( + $form['roleassign_roles'] = [ '#type' => 'checkboxes', '#title' => $this->t('Roles'), '#default_value' => $config->get('roleassign_roles'), '#options' => $roles, '#description' => $this->t('Select roles that should be available for assignment.'), - ); + ]; } return parent::buildForm($form, $form_state); diff --git a/web/modules/roleassign/src/Plugin/views/field/RoleAssignUserBulkForm.php b/web/modules/roleassign/src/Plugin/views/field/RoleAssignUserBulkForm.php index c28ae73981..76cd50ee6d 100644 --- a/web/modules/roleassign/src/Plugin/views/field/RoleAssignUserBulkForm.php +++ b/web/modules/roleassign/src/Plugin/views/field/RoleAssignUserBulkForm.php @@ -1,10 +1,5 @@ <?php -/** - * @file - * Contains \Drupal\roleassign\Plugin\views\field\RoleAssignUserBulkForm. - */ - namespace Drupal\roleassign\Plugin\views\field; use Drupal\views\Plugin\views\display\DisplayPluginBase; @@ -27,7 +22,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o // Remove actions that are not allowed based on RoleAssign settings. $assignable_roles = array_filter(\Drupal::config('roleassign.settings')->get('roleassign_roles')); foreach ($this->actions as $action_key => $action) { - if (in_array($action->get('plugin'), array('user_add_role_action', 'user_remove_role_action'))) { + if (in_array($action->get('plugin'), ['user_add_role_action', 'user_remove_role_action'])) { $config = $action->get('configuration'); if (!in_array($config['rid'], $assignable_roles)) { unset($this->actions[$action_key]); diff --git a/web/modules/roleassign/src/ProxyClass/RoleAssignUninstallValidator.php b/web/modules/roleassign/src/ProxyClass/RoleAssignUninstallValidator.php index 6c2b2d33c9..b8f50e270b 100644 --- a/web/modules/roleassign/src/ProxyClass/RoleAssignUninstallValidator.php +++ b/web/modules/roleassign/src/ProxyClass/RoleAssignUninstallValidator.php @@ -1,9 +1,5 @@ <?php - -/** - * @file - * Contains \Drupal\roleassign\ProxyClass\RoleAssignUninstallValidator. - */ +// @codingStandardsIgnoreFile /** * This file was generated via php core/scripts/generate-proxy-class.php 'Drupal\roleassign\RoleAssignUninstallValidator' "modules/roleassign/src". diff --git a/web/modules/roleassign/src/RoleAssignUninstallValidator.php b/web/modules/roleassign/src/RoleAssignUninstallValidator.php index 8bcbd12c33..ca3676b26d 100644 --- a/web/modules/roleassign/src/RoleAssignUninstallValidator.php +++ b/web/modules/roleassign/src/RoleAssignUninstallValidator.php @@ -1,13 +1,7 @@ <?php -/** - * @file - * Contains \Drupal\roleassign\RoleAssignUninstallValidator. - */ - namespace Drupal\roleassign; -use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleUninstallValidatorInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; @@ -34,6 +28,10 @@ public function __construct(TranslationInterface $string_translation) { */ public function validate($module) { $reasons = []; + if ($this->isCli()) { + return $reasons; + } + if ($module == "roleassign") { if (!\Drupal::currentUser()->hasPermission('administer roles')) { $reasons[] = $this->t('You are not allowed to disable this module.'); @@ -42,4 +40,14 @@ public function validate($module) { return $reasons; } + /** + * Indicates whether this is a CLI request. + * + * @return bool + * TRUE for a cli request, or FALSE. + */ + public function isCli() { + return PHP_SAPI === 'cli'; + } + } diff --git a/web/modules/roleassign/src/Tests/RoleAssignPermissionTest.php b/web/modules/roleassign/tests/src/Functional/RoleAssignPermissionTest.php similarity index 82% rename from web/modules/roleassign/src/Tests/RoleAssignPermissionTest.php rename to web/modules/roleassign/tests/src/Functional/RoleAssignPermissionTest.php index d78124d885..87b8f2556b 100644 --- a/web/modules/roleassign/src/Tests/RoleAssignPermissionTest.php +++ b/web/modules/roleassign/tests/src/Functional/RoleAssignPermissionTest.php @@ -1,13 +1,8 @@ <?php -/** - * @file - * Contains \Drupal\roleassign\Tests\RoleAssignPermissionTest. - */ - -namespace Drupal\roleassign\Tests; +namespace Drupal\Tests\roleassign\Functional; -use Drupal\simpletest\WebTestBase; +use Drupal\Tests\BrowserTestBase; use Drupal\user\Entity\User; use Drupal\user\RoleInterface; @@ -16,7 +11,7 @@ * * @group roleassign */ -class RoleAssignPermissionTest extends WebTestBase { +class RoleAssignPermissionTest extends BrowserTestBase { /** * The user object to test (un)assigning roles to. @@ -40,6 +35,11 @@ class RoleAssignPermissionTest extends WebTestBase { */ protected $admin_user; + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + /** * Modules to install. * @@ -51,16 +51,16 @@ protected function setUp() { parent::setUp(); // Add Editor role - $this->drupalCreateRole(array(), 'editor', 'Editor'); + $this->drupalCreateRole([], 'editor', 'Editor'); // Add Webmaster role - $this->drupalCreateRole(array('administer users', 'assign roles'), 'webmaster', 'Webmaster'); + $this->drupalCreateRole(['administer users', 'assign roles'], 'webmaster', 'Webmaster'); // Add 'protected' SiteAdmin role - $this->drupalCreateRole(array('administer users', 'administer permissions'), 'siteadmin', 'SiteAdmin'); + $this->drupalCreateRole(['administer users', 'administer permissions'], 'siteadmin', 'SiteAdmin'); // Configure RoleAssign module - only editor & webmaster roles are // assignable by restricted users (i.e. webmasters) $this->config('roleassign.settings') - ->set('roleassign_roles', array('editor' => 'editor', 'webmaster' => 'webmaster')) + ->set('roleassign_roles', ['editor' => 'editor', 'webmaster' => 'webmaster']) ->save(); // Create a testaccount that we will be trying to assign roles. @@ -68,12 +68,12 @@ protected function setUp() { // Create a test restricted user without "administer permissions" permission // but with "assign roles" permission provided by RoleAssign. - $this->restricted_user = $this->drupalCreateUser(array('administer users', 'assign roles')); + $this->restricted_user = $this->drupalCreateUser(['administer users', 'assign roles']); // Create a test admin user with "administer users " & // "administer permissions" permissions, where RoleAssign will have no // effect on. - $this->admin_user = $this->drupalCreateUser(array('administer users', 'administer permissions')); + $this->admin_user = $this->drupalCreateUser(['administer users', 'administer permissions']); } /** @@ -81,7 +81,7 @@ protected function setUp() { */ function testRoleAssignSettings() { $assignable_roles = array_filter(\Drupal::config('roleassign.settings')->get('roleassign_roles')); - $this->assertIdentical(array('editor' => 'editor', 'webmaster' => 'webmaster'), $assignable_roles); + $this->assertIdentical(['editor' => 'editor', 'webmaster' => 'webmaster'], $assignable_roles); } /** @@ -101,7 +101,7 @@ function testRoleAssignRestrictedUser() { $this->assertNoField('edit-roles-siteadmin'); // Assign the role "editor" to the account. - $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', array("roles[editor]" => "editor"), t('Save')); + $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', ["roles[editor]" => "editor"], t('Save')); $this->assertText(t('The changes have been saved.')); $this->assertFieldChecked('edit-roles-editor', 'Role editor is assigned.'); $this->assertNoFieldChecked('edit-roles-webmaster'); @@ -110,7 +110,7 @@ function testRoleAssignRestrictedUser() { $this->userLoadAndCheckRoleAssigned($this->testaccount, RoleInterface::AUTHENTICATED_ID); // Remove the role "editor" from the account. - $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', array("roles[editor]" => FALSE), t('Save')); + $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', ["roles[editor]" => FALSE], t('Save')); $this->assertText(t('The changes have been saved.')); $this->assertNoFieldChecked('edit-roles-editor', 'Role editor is removed.'); $this->assertNoFieldChecked('edit-roles-webmaster'); @@ -119,10 +119,10 @@ function testRoleAssignRestrictedUser() { $this->userLoadAndCheckRoleAssigned($this->testaccount, RoleInterface::AUTHENTICATED_ID); // Try to assign a restricted role programmatically to a new user. - $values = array( + $values = [ 'name' => $this->randomString(), - 'roles' => array('editor', 'siteadmin'), - ); + 'roles' => ['editor', 'siteadmin'], + ]; $code_account = User::create($values); $code_account->save(); @@ -148,7 +148,7 @@ function testRoleAssignAdminUser() { $this->assertNoFieldChecked('edit-roles-siteadmin'); // Assign the role "SiteAdmin" to the account. - $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', array("roles[siteadmin]" => "siteadmin"), t('Save')); + $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', ["roles[siteadmin]" => "siteadmin"], t('Save')); $this->assertText(t('The changes have been saved.')); $this->assertFieldChecked('edit-roles-siteadmin', 'Role siteadmin is assigned.'); $this->userLoadAndCheckRoleAssigned($this->testaccount, 'siteadmin'); @@ -159,7 +159,7 @@ function testRoleAssignAdminUser() { // Assign the role "editor" to the account, and test that the assigned // "siteadmin" role doesn't get lost. - $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', array("roles[editor]" => "editor"), t('Save')); + $this->drupalPostForm('user/' . $this->testaccount->id() . '/edit', ["roles[editor]" => "editor"], t('Save')); $this->assertText(t('The changes have been saved.')); $this->assertFieldChecked('edit-roles-editor', 'Role editor is assigned.'); $this->assertNoField('edit-roles-siteadmin'); @@ -180,8 +180,8 @@ function testRoleAssignAdminUser() { * Defaults to TRUE. */ private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) { - $user_storage = $this->container->get('entity.manager')->getStorage('user'); - $user_storage->resetCache(array($account->id())); + $user_storage = \Drupal::entityTypeManager()->getStorage('user'); + $user_storage->resetCache([$account->id()]); $account = $user_storage->load($account->id()); if ($is_assigned) { $this->assertFalse(array_search($rid, $account->getRoles()) === FALSE, 'The role is present in the user object.'); -- GitLab