diff --git a/core/modules/user/src/Tests/Update/UserUpdateUserOneAdminTest.php b/core/modules/user/src/Tests/Update/UserUpdateUserOneAdminTest.php deleted file mode 100644 index f2199a3..0000000 --- a/core/modules/user/src/Tests/Update/UserUpdateUserOneAdminTest.php +++ /dev/null @@ -1,106 +0,0 @@ -databaseDumpFiles = [ - __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', - ]; - } - - /** - * Tests that user 1 has the administrator role after the update. - */ - public function testUserOneAdminRole() { - // Standard install profile used to assign the administrator role to user 1. - // Let's check for its presence, remove it and check whether the removal did - // its job. - $this->assertTrue($this->userOneHasAdminRole()); - $user1 = User::load(1); - $user1->removeRole('administrator'); - $user1->save(); - $this->assertFalse($this->userOneHasAdminRole()); - - // The user_post_update_change_user_1_and_admin_role() post update function - // should have added the administrator role to user 1. - $this->runUpdates(); - $this->assertTrue($this->userOneHasAdminRole()); - } - - /** - * Tests that an existing non-admin 'administrator' role is renamed. - */ - public function testResolvesAdminRoleCollision() { - // Standard install profile used to assign the administrator role to user 1. - // Let's turn it into a non-admin role by assigning it a few permissions and - // unchecking the isAdmin() flag. It should then be migrated to a new role - // called administrator_legacy and users who had it should also receive the - // new role. - $admin_role = Role::load('administrator'); - $admin_role->setIsAdmin(FALSE); - $admin_role->grantPermission('access content'); - $admin_role->save(); - - // The user_post_update_change_user_1_and_admin_role() post update function - // should have added the administrator_legacy role to user 1. - $this->assertTrue($this->userOneHasAdminRole()); - $this->runUpdates(); - $this->assertTrue($this->userOneHasLegacyAdminRole(), 'User one received the legacy admin role.'); - - // The legacy admin role should have the permissions of the old admin role. - $legacy_admin_role = Role::load($this->getLegacyAdminRoleId()); - $this->assertEqual(['access content'], $legacy_admin_role->getPermissions(), 'Legacy admin role has the right permissions.'); - } - - /** - * Checks whether user 1 has the administrator role. - * - * @return bool - * Whether user 1 has the administrator role. - */ - protected function userOneHasAdminRole() { - $user1 = User::load(1); - return in_array('administrator', $user1->getRoles(), TRUE); - } - - /** - * Checks whether user 1 has the legacy administrator role. - * - * @return bool - * Whether user 1 has the legacy administrator role. - */ - protected function userOneHasLegacyAdminRole() { - $user1 = User::load(1); - return in_array($this->getLegacyAdminRoleId(), $user1->getRoles(), TRUE); - } - - /** - * Retrieves the legacy administrator role ID. - * - * By default this is administrator_legacy but in the rare event of a naming - * collision, people may choose an ID themselves by setting it to the - * user_update_8101_legacy_admin_role setting in settings.php. - * - * @return string - * The legacy administrator role ID. - */ - protected function getLegacyAdminRoleId() { - return Settings::get('user_update_8101_legacy_admin_role', 'administrator_legacy'); - } - -} diff --git a/core/modules/user/tests/src/Functional/Update/UserUpdateUserOneAdminTest.php b/core/modules/user/tests/src/Functional/Update/UserUpdateUserOneAdminTest.php new file mode 100644 index 0000000..dd2171d --- /dev/null +++ b/core/modules/user/tests/src/Functional/Update/UserUpdateUserOneAdminTest.php @@ -0,0 +1,106 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', + ]; + } + + /** + * Tests that user 1 has the administrator role after the update. + */ + public function testUserOneAdminRole() { + // Standard install profile used to assign the administrator role to user 1. + // Let's check for its presence, remove it and check whether the removal did + // its job. + $this->assertTrue($this->userOneHasAdminRole()); + $user1 = User::load(1); + $user1->removeRole('administrator'); + $user1->save(); + $this->assertFalse($this->userOneHasAdminRole()); + + // The user_post_update_change_user_1_and_admin_role() post update function + // should have added the administrator role to user 1. + $this->runUpdates(); + $this->assertTrue($this->userOneHasAdminRole()); + } + + /** + * Tests that an existing non-admin 'administrator' role is renamed. + */ + public function testResolvesAdminRoleCollision() { + // Standard install profile used to assign the administrator role to user 1. + // Let's turn it into a non-admin role by assigning it a few permissions and + // unchecking the isAdmin() flag. It should then be migrated to a new role + // called administrator_legacy and users who had it should also receive the + // new role. + $admin_role = Role::load('administrator'); + $admin_role->setIsAdmin(FALSE); + $admin_role->grantPermission('access content'); + $admin_role->save(); + + // The user_post_update_change_user_1_and_admin_role() post update function + // should have added the administrator_legacy role to user 1. + $this->assertTrue($this->userOneHasAdminRole()); + $this->runUpdates(); + $this->assertTrue($this->userOneHasLegacyAdminRole(), 'User one received the legacy admin role.'); + + // The legacy admin role should have the permissions of the old admin role. + $legacy_admin_role = Role::load($this->getLegacyAdminRoleId()); + $this->assertEqual(['access content'], $legacy_admin_role->getPermissions(), 'Legacy admin role has the right permissions.'); + } + + /** + * Checks whether user 1 has the administrator role. + * + * @return bool + * Whether user 1 has the administrator role. + */ + protected function userOneHasAdminRole() { + $user1 = User::load(1); + return in_array('administrator', $user1->getRoles(), TRUE); + } + + /** + * Checks whether user 1 has the legacy administrator role. + * + * @return bool + * Whether user 1 has the legacy administrator role. + */ + protected function userOneHasLegacyAdminRole() { + $user1 = User::load(1); + return in_array($this->getLegacyAdminRoleId(), $user1->getRoles(), TRUE); + } + + /** + * Retrieves the legacy administrator role ID. + * + * By default this is administrator_legacy but in the rare event of a naming + * collision, people may choose an ID themselves by setting it to the + * user_update_8101_legacy_admin_role setting in settings.php. + * + * @return string + * The legacy administrator role ID. + */ + protected function getLegacyAdminRoleId() { + return Settings::get('user_update_8101_legacy_admin_role', 'administrator_legacy'); + } + +}