diff --git a/resources/views/components/turnstile.blade.php b/resources/views/components/turnstile.blade.php index 274d202..bc2c03e 100644 --- a/resources/views/components/turnstile.blade.php +++ b/resources/views/components/turnstile.blade.php @@ -1,12 +1,14 @@ @php - $id = $getId(); $statePath = $getStatePath(); + $fieldWrapperView = $getFieldWrapperView(); + $theme = $getTheme(); $size = $getSize(); $language = $getLanguage(); @endphp - + +
+ :data-size="$size" + >
@@ -27,12 +30,12 @@ callback: function(token) { window.Livewire .find('{{$this->id}}') - .$set('{{$getStatePath()}}', token); + .$set('{{$statePath}}', token); }, errorCallback: function () { window.Livewire .find('{{$this->id}}') - .$set('{{$getStatePath()}}', 'error'); + .$set('{{$statePath}}', 'error'); } } diff --git a/src/Forms/Components/Turnstile.php b/src/Forms/Components/Turnstile.php index bd11784..73df2e4 100644 --- a/src/Forms/Components/Turnstile.php +++ b/src/Forms/Components/Turnstile.php @@ -7,6 +7,8 @@ class Turnstile extends Field { + protected string $viewIdentifier = 'turnstile'; + protected string $view = 'turnstile::components.turnstile'; protected string $theme = 'auto'; diff --git a/tests/Database/Migrations/create_contacts_table.php b/tests/Database/Migrations/create_contacts_table.php new file mode 100644 index 0000000..21824c9 --- /dev/null +++ b/tests/Database/Migrations/create_contacts_table.php @@ -0,0 +1,19 @@ +id(); + $table->string('name'); + $table->string('email'); + $table->text('content'); + $table->timestamps(); + }); + } +}; diff --git a/tests/Fixtures/ContactUs.php b/tests/Fixtures/ContactUs.php new file mode 100644 index 0000000..c9675c7 --- /dev/null +++ b/tests/Fixtures/ContactUs.php @@ -0,0 +1,88 @@ +form->fill(); + } + + public function form(Form $form): Form + { + return $form; + } + + protected function getForms(): array + { + return [ + 'form' => $this->form( + $this->makeForm() + ->schema([ + Forms\Components\TextInput::make('name') + ->label('Name') + ->required(), + Forms\Components\TextInput::make('email') + ->label('Email') + ->required(), + Forms\Components\TextInput::make('content') + ->label('Content') + ->required(), + Turnstile::make('turnstile') + // ->id('cf-captcha-field') + ->theme('auto'), + ]) + ) + ->statePath('data') + ->model(Contact::class), + ]; + } + + /** + * @return array + */ + protected function getFormActions(): array + { + return [ + $this->getSendFormAction(), + ]; + } + + protected function getSendFormAction(): Action + { + return Action::make('Send') + ->label(__('Send')) + ->submit('send'); + } + + protected function hasFullWidthFormActions(): bool + { + return true; + } + + public function send() + { + dd($this->form->getState()); + + Contact::create($this->form->getState()); + } + + public function render(): View + { + return view('fixtures.contact-us'); + } +} diff --git a/tests/Fixtures/Login.php b/tests/Fixtures/Login.php deleted file mode 100644 index ea194c1..0000000 --- a/tests/Fixtures/Login.php +++ /dev/null @@ -1,25 +0,0 @@ - $this->form( - $this->makeForm() - ->schema([ - $this->getEmailFormComponent(), - $this->getPasswordFormComponent(), - $this->getRememberFormComponent(), - Turnstile::make('cf-captcha') - ->theme('auto'), - ]) - ->statePath('data'), - ), - ]; - } -} diff --git a/tests/Fixtures/Register.php b/tests/Fixtures/Register.php deleted file mode 100644 index 6abfd68..0000000 --- a/tests/Fixtures/Register.php +++ /dev/null @@ -1,26 +0,0 @@ - $this->form( - $this->makeForm() - ->schema([ - $this->getNameFormComponent(), - $this->getEmailFormComponent(), - $this->getPasswordFormComponent(), - $this->getPasswordConfirmationFormComponent(), - Turnstile::make('cf-captcha') - ->theme('auto'), - ]) - ->statePath('data'), - ), - ]; - } -} diff --git a/tests/Fixtures/TurnstilePanelProvider.php b/tests/Fixtures/TurnstilePanelProvider.php deleted file mode 100644 index c6d4a43..0000000 --- a/tests/Fixtures/TurnstilePanelProvider.php +++ /dev/null @@ -1,20 +0,0 @@ -id('turnstile') - ->path('filament') - ->authMiddleware([ - Authenticate::class, - ]); - } -} diff --git a/tests/Models/Contact.php b/tests/Models/Contact.php new file mode 100644 index 0000000..c45a7d5 --- /dev/null +++ b/tests/Models/Contact.php @@ -0,0 +1,10 @@ +set('app.key', '6rE9Nz59bGRbeMATftriyQjrpF7DcOQm'); + config()->set('turnstile.turnstile_site_key', '2x00000000000000000000AB'); + config()->set('turnstile.turnstile_secret_key', '2x0000000000000000000000000000000AA'); $this->setCurrentFilamentPanel(); } @@ -28,6 +41,18 @@ protected function setUp(): void protected function getPackageProviders($app) { return [ + ActionsServiceProvider::class, + BladeCaptureDirectiveServiceProvider::class, + BladeHeroiconsServiceProvider::class, + BladeIconsServiceProvider::class, + FilamentServiceProvider::class, + FormsServiceProvider::class, + InfolistsServiceProvider::class, + LivewireServiceProvider::class, + NotificationsServiceProvider::class, + SupportServiceProvider::class, + TablesServiceProvider::class, + WidgetsServiceProvider::class, FilamentTurnstileServiceProvider::class, TurnstilePanelProvider::class, ]; @@ -37,8 +62,14 @@ public function getEnvironmentSetUp($app) { config()->set('database.default', 'testing'); + $app['config']->set('view.paths', [ + ...$app['config']->get('view.paths'), + __DIR__.'/resources/views', + ]); + $migrations = [ include __DIR__.'/Database/Migrations/create_users_table.php', + include __DIR__.'/Database/Migrations/create_contacts_table.php', ]; collect($migrations)->each( diff --git a/tests/TurnstilePanelProvider.php b/tests/TurnstilePanelProvider.php new file mode 100644 index 0000000..aa42894 --- /dev/null +++ b/tests/TurnstilePanelProvider.php @@ -0,0 +1,43 @@ +id('turnstile') + ->login() + ->registration() + ->resources([]) + ->pages([]) + ->middleware([ + EncryptCookies::class, + AddQueuedCookiesToResponse::class, + StartSession::class, + AuthenticateSession::class, + ShareErrorsFromSession::class, + VerifyCsrfToken::class, + SubstituteBindings::class, + DisableBladeIconComponents::class, + DispatchServingFilamentEvent::class, + ]) + ->authMiddleware([ + Authenticate::class, + ]); + } +} diff --git a/tests/TurnstileTest.php b/tests/TurnstileTest.php index a1149ac..9a3540d 100644 --- a/tests/TurnstileTest.php +++ b/tests/TurnstileTest.php @@ -1,26 +1,15 @@ assertOk(); }); -it('can render register page', function () { - livewire(Register::class) - ->assertOk(); -}); - -test('login page has captcha field', function () { - livewire(Login::class) - ->assertFormFieldExists('cf-captcha'); -}); - -test('register page has captcha field', function () { - livewire(Register::class) - ->assertFormFieldExists('cf-captcha'); +test('contact page has captcha field', function () { + livewire(ContactUs::class) + ->assertFormFieldExists('cf-captcha', 'form'); }); diff --git a/tests/resources/views/fixtures/contact-us.blade.php b/tests/resources/views/fixtures/contact-us.blade.php new file mode 100644 index 0000000..128dd85 --- /dev/null +++ b/tests/resources/views/fixtures/contact-us.blade.php @@ -0,0 +1,10 @@ + + + {{ $this->form }} + + + + \ No newline at end of file