X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FTestUser.php;h=610a6acdc8ad9f5437a67bce5f0078ac73d7a90b;hb=2bcbc311b49af248b9f4882ae5da787a8b91a8a5;hp=23e65031e0d50aee851fe8aaa471bb3271a3503d;hpb=a36b3c44ed0a950efbd4e01557db6014701d71e6;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/TestUser.php b/tests/phpunit/includes/TestUser.php index 23e65031e0..610a6acdc8 100644 --- a/tests/phpunit/includes/TestUser.php +++ b/tests/phpunit/includes/TestUser.php @@ -1,7 +1,8 @@ username = $username; $this->realname = $realname; $this->email = $email; @@ -45,14 +48,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(); }