-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
399 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
|
||
use Kirby\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Kirby\Cms\UserPermissions | ||
*/ | ||
class UserPermissionsTest extends TestCase | ||
{ | ||
public static function actionProvider(): array | ||
|
@@ -120,20 +123,131 @@ public function testWithNoAdmin($action) | |
$this->assertFalse($perms->can($action)); | ||
} | ||
|
||
public function testChangeSingleRole() | ||
/** | ||
* @covers ::canChangeRole | ||
*/ | ||
public function testChangeRole() | ||
{ | ||
new App([ | ||
// admin to change role of another admin | ||
$app = new App([ | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
], | ||
'roles' => [ | ||
['name' => 'admin'] | ||
] | ||
['name' => 'admin'], | ||
['name' => 'editor'] | ||
], | ||
'user' => '[email protected]', | ||
'users' => [ | ||
[ | ||
'email' => '[email protected]', | ||
'role' => 'admin' | ||
], | ||
[ | ||
'email' => '[email protected]', | ||
'role' => 'admin' | ||
] | ||
], | ||
]); | ||
|
||
$user = new User(['email' => '[email protected]']); | ||
$perms = $user->permissions(); | ||
$user = $app->user('[email protected]'); | ||
$this->assertTrue($user->permissions()->can('changeRole')); | ||
|
||
// non-admin to change role of an admin | ||
$app = new App([ | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
], | ||
'roles' => [ | ||
['name' => 'admin'], | ||
['name' => 'editor'] | ||
], | ||
'user' => '[email protected]', | ||
'users' => [ | ||
[ | ||
'email' => '[email protected]', | ||
'role' => 'admin' | ||
], | ||
[ | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
]); | ||
|
||
$user = $app->user('[email protected]'); | ||
$this->assertFalse($user->permissions()->can('changeRole')); | ||
|
||
// change role of last admin | ||
$app = new App([ | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
], | ||
'roles' => [ | ||
['name' => 'admin'], | ||
['name' => 'editor'] | ||
], | ||
'user' => '[email protected]', | ||
'users' => [ | ||
[ | ||
'email' => '[email protected]', | ||
'role' => 'admin' | ||
] | ||
], | ||
]); | ||
|
||
$user = $app->user('[email protected]'); | ||
$this->assertFalse($user->permissions()->can('changeRole')); | ||
|
||
// change role if only one role is available | ||
$app = new App([ | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
], | ||
'roles' => [ | ||
['name' => 'admin'], | ||
['name' => 'editor'] | ||
], | ||
'user' => '[email protected]', | ||
'users' => [ | ||
[ | ||
'email' => '[email protected]', | ||
'role' => 'admin' | ||
], | ||
[ | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
]); | ||
|
||
$user = $app->user('[email protected]'); | ||
$this->assertFalse($user->permissions()->can('changeRole')); | ||
|
||
// change role if multiple roles are available | ||
$app = new App([ | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
], | ||
'roles' => [ | ||
['name' => 'admin'], | ||
['name' => 'editor'], | ||
['name' => 'guest'] | ||
], | ||
'user' => '[email protected]', | ||
'users' => [ | ||
[ | ||
'email' => '[email protected]', | ||
'role' => 'admin' | ||
], | ||
[ | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
]); | ||
|
||
$this->assertFalse($perms->can('changeRole')); | ||
$user = $app->user('[email protected]'); | ||
$this->assertTrue($user->permissions()->can('changeRole')); | ||
} | ||
} |
Oops, something went wrong.