From 9fd650c8cbf17b8a73155b020608793f7e7bce4c Mon Sep 17 00:00:00 2001 From: AJ Meireles Date: Wed, 18 Sep 2024 09:06:02 -0300 Subject: [PATCH] creating tests to validate authenticated users --- phpstan.neon | 2 ++ tests/Browser/EnvBar/IndexTest.php | 31 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 1398dd8..0ccdf5d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,3 +6,5 @@ parameters: paths: - src/ level: 5 + excludePaths: + - *Test.php diff --git a/tests/Browser/EnvBar/IndexTest.php b/tests/Browser/EnvBar/IndexTest.php index bc31848..e04bb2e 100644 --- a/tests/Browser/EnvBar/IndexTest.php +++ b/tests/Browser/EnvBar/IndexTest.php @@ -3,6 +3,7 @@ namespace Tests\Browser\EnvBar; use Illuminate\Config\Repository; +use Illuminate\Support\Facades\Gate; use Laravel\Dusk\Browser; use PHPUnit\Framework\Attributes\Test; use Tests\Browser\BrowserTestCase; @@ -20,6 +21,36 @@ public function is_visible(): void }); } + #[Test] + public function is_visible_for_authenticated_user_only(): void + { + $this->beforeServingApplication(function ($app, Repository $config) { + $config->set('envbar.for_authenticated_users.enabled', true); + + Gate::shouldReceive('allows')->withSomeOfArgs('envbar::view')->andReturnFalse(); + }); + + $this->browse(function (Browser $browser): void { + $browser->visit('/') + ->waitUntilMissingText('Environment') + ->assertDontSee('Environment') + ->assertDontSee('testing'); + }); + + $this->beforeServingApplication(function ($app, Repository $config) { + $config->set('envbar.for_authenticated_users.enabled', true); + + Gate::shouldReceive('allows')->withSomeOfArgs('envbar::view')->andReturnTrue(); + }); + + $this->browse(function (Browser $browser): void { + $browser->visit('/') + ->waitForText('Environment') + ->assertSee('Environment') + ->assertSee('testing'); + }); + } + #[Test] public function warning_visible(): void {