From 53a57f58f15418dd6a85b82ddf15fa0b82dbb698 Mon Sep 17 00:00:00 2001 From: Falko Woudstra Date: Sat, 3 Jan 2026 13:17:40 +0100 Subject: [PATCH 1/5] Add onlyAuthenticated, guard options and automated tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Features: - Add only_authenticated config option (default: true) - Add ->onlyAuthenticated() method for per-panel override - Add guard config option with panel auth guard fallback - Add ->guard() method for per-panel override Testing: - Add Pest test suite with Orchestra Testbench - Add tests for plugin instantiation, configuration fallbacks, and view rendering 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .gitignore | 4 +- CLAUDE.md | 9 +++ composer.json | 18 ++++++ config/filament-userback.php | 28 +++++++++ phpunit.xml | 18 ++++++ resources/views/userback.blade.php | 2 +- src/UserbackPlugin.php | 45 ++++++++++++++ tests/ConfigurationTest.php | 83 +++++++++++++++++++++++++ tests/Pest.php | 7 +++ tests/TestCase.php | 33 ++++++++++ tests/UserbackPluginTest.php | 62 +++++++++++++++++++ tests/ViewTest.php | 98 ++++++++++++++++++++++++++++++ 12 files changed, 405 insertions(+), 2 deletions(-) create mode 100644 phpunit.xml create mode 100644 tests/ConfigurationTest.php create mode 100644 tests/Pest.php create mode 100644 tests/TestCase.php create mode 100644 tests/UserbackPluginTest.php create mode 100644 tests/ViewTest.php diff --git a/.gitignore b/.gitignore index cb756e9..8f3f3ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ vendor -.idea \ No newline at end of file +.idea +.phpunit.cache +composer.lock diff --git a/CLAUDE.md b/CLAUDE.md index 1a57d6a..2fd77c3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -32,6 +32,15 @@ The `accessToken` can be set: 1. **Globally** via `config/filament-userback.php` - applies to all panels 2. **Per-panel** via `->accessToken()` method - overrides global config +The `only_authenticated` setting controls whether the widget is shown only to authenticated users: +1. **Globally** via `config/filament-userback.php` (default: `true`) +2. **Per-panel** via `->onlyAuthenticated()` method - overrides global config + +The `guard` setting specifies which authentication guard to use: +1. **Per-panel** via `->guard()` method - highest priority +2. **Globally** via `config/filament-userback.php` +3. **Fallback** to the panel's configured auth guard (`$panel->getAuthGuard()`) + ## Common Tasks ### Testing the plugin locally diff --git a/composer.json b/composer.json index 00d9c71..01b0d7d 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,21 @@ "illuminate/contracts": "^11.0|^12.0", "spatie/laravel-package-tools": "^1.16" }, + "require-dev": { + "orchestra/testbench": "^9.0|^10.0", + "pestphp/pest": "^3.0", + "pestphp/pest-plugin-laravel": "^3.0" + }, "autoload": { "psr-4": { "CoddinWeb\\FilamentUserback\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "CoddinWeb\\FilamentUserback\\Tests\\": "tests/" + } + }, "extra": { "laravel": { "providers": [ @@ -27,6 +37,14 @@ ] } }, + "scripts": { + "test": "vendor/bin/pest" + }, + "config": { + "allow-plugins": { + "pestphp/pest-plugin": true + } + }, "minimum-stability": "dev", "prefer-stable": true } diff --git a/config/filament-userback.php b/config/filament-userback.php index 422ea6c..5864062 100644 --- a/config/filament-userback.php +++ b/config/filament-userback.php @@ -17,4 +17,32 @@ */ 'access_token' => env('USERBACK_ACCESS_TOKEN'), + + /* + |-------------------------------------------------------------------------- + | Only Authenticated Users + |-------------------------------------------------------------------------- + | + | When set to true, the Userback widget will only be rendered for + | authenticated users. Set to false to show the widget to all visitors. + | + | This can be overridden per-panel using the ->onlyAuthenticated() method. + | + */ + + 'only_authenticated' => env('USERBACK_ONLY_AUTHENTICATED', true), + + /* + |-------------------------------------------------------------------------- + | Authentication Guard + |-------------------------------------------------------------------------- + | + | The authentication guard to use when checking if a user is authenticated. + | If not set, it will fall back to the panel's configured auth guard. + | + | This can be overridden per-panel using the ->guard() method. + | + */ + + 'guard' => env('USERBACK_GUARD'), ]; diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..8848452 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + tests + + + + + src + + + diff --git a/resources/views/userback.blade.php b/resources/views/userback.blade.php index 4cd7989..bbef6e3 100644 --- a/resources/views/userback.blade.php +++ b/resources/views/userback.blade.php @@ -1,4 +1,4 @@ -@if(\is_string($accessToken)) +@if(\is_string($accessToken) && (!$onlyAuthenticated || auth($guard)->check()))