diff --git a/framework/core/src/User/AbstractPolicy.php b/framework/core/src/User/AbstractPolicy.php index 3f6d6e939..451fca699 100644 --- a/framework/core/src/User/AbstractPolicy.php +++ b/framework/core/src/User/AbstractPolicy.php @@ -35,7 +35,7 @@ abstract class AbstractPolicy */ public function getPermission(GetPermission $event) { - if (! $event->model instanceof $this->model) { + if (! $event->model instanceof $this->model && $event->model !== $this->model) { return; } diff --git a/framework/core/tests/unit/User/AbstractPolicyTest.php b/framework/core/tests/unit/User/AbstractPolicyTest.php new file mode 100644 index 000000000..96553fa7f --- /dev/null +++ b/framework/core/tests/unit/User/AbstractPolicyTest.php @@ -0,0 +1,48 @@ +policy = m::mock(UserPolicy::class)->makePartial(); + $this->dispatcher = new Dispatcher(); + $this->dispatcher->subscribe($this->policy); + User::setEventDispatcher($this->dispatcher); + } + + public function test_policy_can_be_called_with_object() + { + $this->policy->shouldReceive('edit')->andReturn(true); + + $allowed = $this->dispatcher->until(new GetPermission(new User(), 'edit', new User())); + + $this->assertTrue($allowed); + } + + public function test_policy_can_be_called_with_class() + { + $this->policy->shouldReceive('create')->andReturn(true); + + $allowed = $this->dispatcher->until(new GetPermission(new User(), 'create', User::class)); + + $this->assertTrue($allowed); + } +} diff --git a/framework/core/tests/unit/User/UserPolicy.php b/framework/core/tests/unit/User/UserPolicy.php new file mode 100644 index 000000000..6718ba6ab --- /dev/null +++ b/framework/core/tests/unit/User/UserPolicy.php @@ -0,0 +1,28 @@ +