Skip to content

Commit

Permalink
Move $app->roles() to AppUsers trait
Browse files Browse the repository at this point in the history
Improves consistency and overview
  • Loading branch information
lukasbestle committed Dec 17, 2024
1 parent b833bf4 commit 3832c97
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 45 deletions.
8 changes: 0 additions & 8 deletions src/Cms/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -1331,14 +1331,6 @@ public function response(): Responder
return $this->response ??= new Responder();
}

/**
* Returns all user roles
*/
public function roles(): Roles
{
return $this->roles ??= Roles::load($this->root('roles'));
}

/**
* Returns a system root
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Cms/AppUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public function impersonate(
}
}

/**
* Returns all user roles
*/
public function roles(): Roles
{
return $this->roles ??= Roles::load($this->root('roles'));
}

/**
* Set the currently active user id
*
Expand Down
35 changes: 0 additions & 35 deletions tests/Cms/App/AppRolesTest.php

This file was deleted.

31 changes: 29 additions & 2 deletions tests/Cms/App/AppUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,34 @@ public function testImpersonateErrorMissingUser()
$this->app->impersonate('[email protected]');
}

public function testLoad()
public function testRolesSet()
{
$app = new App([
'roles' => [
[
'name' => 'editor',
'title' => 'Editor'
]
]
]);

$this->assertCount(2, $app->roles());
$this->assertSame('editor', $app->roles()->last()->name());
}

public function testRolesLoad()
{
$app = new App([
'roots' => [
'site' => static::FIXTURES
]
]);

$this->assertCount(2, $app->roles());
$this->assertSame('editor', $app->roles()->last()->name());
}

public function testUsersLoad()
{
$app = $this->app->clone([
'roots' => [
Expand All @@ -122,7 +149,7 @@ public function testLoad()
$this->assertSame('[email protected]', $app->users()->first()->email());
}

public function testSet()
public function testUsersSet()
{
$app = $this->app->clone([
'users' => [
Expand Down

0 comments on commit 3832c97

Please sign in to comment.