Skip to content

Commit 2be7d6d

Browse files
committed
Fix UserPermissions unit test
Without having a current user, the permission would be `false` even if the logic test in `canChangeRole()` would not work, thus making the test useless; in fact just adding the impersonation made the test fail because manually creating a user object didn’t trigger the `isLastAdmin()` logic
1 parent 0c080cf commit 2be7d6d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/Cms/Users/UserPermissionsTest.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,24 @@ public function testWithNoAdmin($action)
122122

123123
public function testChangeSingleRole()
124124
{
125-
new App([
125+
$app = new App([
126126
'roots' => [
127127
'index' => '/dev/null'
128128
],
129129
'roles' => [
130130
['name' => 'admin']
131+
],
132+
'users' => [
133+
[
134+
'email' => '[email protected]',
135+
'role' => 'admin'
136+
]
131137
]
132138
]);
133139

134-
$user = new User(['email' => '[email protected]']);
140+
$app->impersonate('kirby');
141+
142+
$user = $app->user('[email protected]');
135143
$perms = $user->permissions();
136144

137145
$this->assertFalse($perms->can('changeRole'));

0 commit comments

Comments
 (0)