From 3832c97de4ae30972a716f03d6e6be912d0215a0 Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Tue, 17 Dec 2024 21:35:31 +0100 Subject: [PATCH] Move `$app->roles()` to `AppUsers` trait Improves consistency and overview --- src/Cms/App.php | 8 -------- src/Cms/AppUsers.php | 8 ++++++++ tests/Cms/App/AppRolesTest.php | 35 ---------------------------------- tests/Cms/App/AppUsersTest.php | 31 ++++++++++++++++++++++++++++-- 4 files changed, 37 insertions(+), 45 deletions(-) delete mode 100644 tests/Cms/App/AppRolesTest.php diff --git a/src/Cms/App.php b/src/Cms/App.php index 88a9084211..10288260cc 100644 --- a/src/Cms/App.php +++ b/src/Cms/App.php @@ -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 */ diff --git a/src/Cms/AppUsers.php b/src/Cms/AppUsers.php index 6f2f7be524..23b8470dee 100644 --- a/src/Cms/AppUsers.php +++ b/src/Cms/AppUsers.php @@ -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 * diff --git a/tests/Cms/App/AppRolesTest.php b/tests/Cms/App/AppRolesTest.php deleted file mode 100644 index 370ef20f13..0000000000 --- a/tests/Cms/App/AppRolesTest.php +++ /dev/null @@ -1,35 +0,0 @@ - [ - [ - 'name' => 'editor', - 'title' => 'Editor' - ] - ] - ]); - - $this->assertCount(2, $app->roles()); - $this->assertSame('editor', $app->roles()->last()->name()); - } - - public function testLoad() - { - $app = new App([ - 'roots' => [ - 'site' => static::FIXTURES - ] - ]); - - $this->assertCount(2, $app->roles()); - $this->assertSame('editor', $app->roles()->last()->name()); - } -} diff --git a/tests/Cms/App/AppUsersTest.php b/tests/Cms/App/AppUsersTest.php index ba634f80d0..5acaf187a2 100644 --- a/tests/Cms/App/AppUsersTest.php +++ b/tests/Cms/App/AppUsersTest.php @@ -110,7 +110,34 @@ public function testImpersonateErrorMissingUser() $this->app->impersonate('homer@simpsons.com'); } - 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' => [ @@ -122,7 +149,7 @@ public function testLoad() $this->assertSame('user@getkirby.com', $app->users()->first()->email()); } - public function testSet() + public function testUsersSet() { $app = $this->app->clone([ 'users' => [