Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating tests to validate authenticated users #5

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ parameters:
paths:
- src/
level: 5
excludePaths:
- *Test.php
31 changes: 31 additions & 0 deletions tests/Browser/EnvBar/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down