Skip to content

Commit

Permalink
Add Gate::after test
Browse files Browse the repository at this point in the history
  • Loading branch information
drbyte committed Oct 24, 2023
1 parent 9073f54 commit dddc7b1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/GateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,29 @@ public function it_allows_other_gate_before_callbacks_to_run_if_a_user_does_not_
$this->assertFalse($this->testUser->can('edit-articles'));

app(Gate::class)->before(function () {
// this Gate-before intercept overrides everything to true ... like a typical Super-Admin might use
return true;
});

$this->assertTrue($this->testUser->can('edit-articles'));
}

/** @test */
public function it_allows_gate_after_callback_to_deny_granted_privileges()
{
$this->assertFalse($this->testUser->can('edit-articles'));

$this->testUser->givePermissionTo($this->testUserPermission);
$this->assertTrue($this->testUser->can('edit-articles'));

app(Gate::class)->after(function () {
// always deny
return false;
});

$this->assertFalse($this->testUser->can('edit-articles'));
}

/** @test */
public function it_can_determine_if_a_user_has_a_direct_permission()
{
Expand Down

0 comments on commit dddc7b1

Please sign in to comment.