Skip to content

Commit

Permalink
Fix UserPermissions unit test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lukasbestle committed Dec 19, 2024
1 parent 0c080cf commit 2be7d6d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/Cms/Users/UserPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,24 @@ public function testWithNoAdmin($action)

public function testChangeSingleRole()
{
new App([
$app = new App([
'roots' => [
'index' => '/dev/null'
],
'roles' => [
['name' => 'admin']
],
'users' => [
[
'email' => '[email protected]',
'role' => 'admin'
]
]
]);

$user = new User(['email' => '[email protected]']);
$app->impersonate('kirby');

$user = $app->user('[email protected]');
$perms = $user->permissions();

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

0 comments on commit 2be7d6d

Please sign in to comment.