| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace Illuminate\Tests\Integration\Auth;
- use Illuminate\Auth\Access\Events\GateEvaluated;
- use Illuminate\Support\Facades\Event;
- use Illuminate\Support\Facades\Gate;
- use Illuminate\Tests\Integration\Auth\Fixtures\AuthenticationTestUser;
- use Illuminate\Tests\Integration\Auth\Fixtures\Policies\AuthenticationTestUserPolicy;
- use Orchestra\Testbench\TestCase;
- class GatePolicyResolutionTest extends TestCase
- {
- public function testGateEvaluationEventIsFired()
- {
- Event::fake();
- Gate::check('foo');
- Event::assertDispatched(GateEvaluated::class);
- }
- public function testPolicyCanBeGuessedUsingClassConventions()
- {
- $this->assertInstanceOf(
- AuthenticationTestUserPolicy::class,
- Gate::getPolicyFor(AuthenticationTestUser::class)
- );
- $this->assertInstanceOf(
- AuthenticationTestUserPolicy::class,
- Gate::getPolicyFor(Fixtures\Models\AuthenticationTestUser::class)
- );
- $this->assertNull(
- Gate::getPolicyFor(static::class)
- );
- }
- public function testPolicyCanBeGuessedUsingCallback()
- {
- Gate::guessPolicyNamesUsing(function () {
- return AuthenticationTestUserPolicy::class;
- });
- $this->assertInstanceOf(
- AuthenticationTestUserPolicy::class,
- Gate::getPolicyFor(AuthenticationTestUser::class)
- );
- }
- public function testPolicyCanBeGuessedMultipleTimes()
- {
- Gate::guessPolicyNamesUsing(function () {
- return [
- 'App\\Policies\\TestUserPolicy',
- AuthenticationTestUserPolicy::class,
- ];
- });
- $this->assertInstanceOf(
- AuthenticationTestUserPolicy::class,
- Gate::getPolicyFor(AuthenticationTestUser::class)
- );
- }
- }
|