From a219c69cd31db8f90adb8de44d3f06636fe557a2 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 5 Dec 2013 12:41:24 -0500 Subject: [PATCH] Improve TestUser group handling There's no need for TestUser to remove all groups only to add some back on. We should be able to speed things up (see bug 43762) by only removing the groups that aren't wanted and only adding the ones that aren't already possessed. Change-Id: I50dd9b117a8a21c8a6170520b3bbf98e3030ae47 --- tests/phpunit/includes/TestUser.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/includes/TestUser.php b/tests/phpunit/includes/TestUser.php index 23e65031e0..7d182065de 100644 --- a/tests/phpunit/includes/TestUser.php +++ b/tests/phpunit/includes/TestUser.php @@ -45,14 +45,14 @@ class TestUser { $this->user->setPassword( $this->password ); $this->user->setEmail( $this->email ); $this->user->setRealName( $this->realname ); - // remove all groups, replace with any groups specified - foreach ( $this->user->getGroups() as $group ) { - $this->user->removeGroup( $group ); + + // Adjust groups by adding any missing ones and removing any extras + $currentGroups = $this->user->getGroups(); + foreach ( array_diff( $this->groups, $currentGroups ) as $group ) { + $this->user->addGroup( $group ); } - if ( count( $this->groups ) ) { - foreach ( $this->groups as $group ) { - $this->user->addGroup( $group ); - } + foreach ( array_diff( $currentGroups, $this->groups ) as $group ) { + $this->user->removeGroup( $group ); } $this->user->saveSettings(); } -- 2.20.1