Skip to content

Commit

Permalink
Merge pull request #6918 from getkirby/fix/6167-roles-blueprint-extend
Browse files Browse the repository at this point in the history
Roles: fix extending blueprint
  • Loading branch information
distantnative authored Jan 20, 2025
2 parents efad7c1 + be3be83 commit 1594122
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Cms/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public function description(): string|null

public static function factory(array $props, array $inject = []): static
{
return new static($props + $inject);
// ensure to properly extend the blueprint
$props = $props + $inject;
$props = Blueprint::extend($props);

return new static($props);
}

public function id(): string
Expand Down
1 change: 1 addition & 0 deletions tests/Cms/Roles/RoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testFactory()

$this->assertSame('editor', $role->name());
$this->assertSame('Editor', $role->title());
$this->assertSame('This should be inherited', $role->description());
}

public function testMissingRole()
Expand Down
5 changes: 3 additions & 2 deletions tests/Cms/Roles/RolesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public function testLoad()

$this->assertInstanceOf(Roles::class, $roles);

// should contain the editor role from fixtures and the default admin role
$this->assertCount(2, $roles);
// should contain the base and editor role from fixtures
// and the default admin role
$this->assertCount(3, $roles);
$this->assertSame('admin', $roles->first()->name());
$this->assertSame('editor', $roles->last()->name());
}
Expand Down
1 change: 1 addition & 0 deletions tests/Cms/Roles/fixtures/blueprints/users/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
description: This should be inherited
2 changes: 2 additions & 0 deletions tests/Cms/Roles/fixtures/blueprints/users/editor.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
title: Editor

extends: users/base

0 comments on commit 1594122

Please sign in to comment.