Skip to content

Commit 40bccc8

Browse files
FIX blade directive
1 parent 7123b55 commit 40bccc8

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/GoogleRecaptchaV3.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class GoogleRecaptchaV3
1313
{
1414
public function boot(): void
1515
{
16-
Blade::directive('recaptcha', fn (Badge $badge) => (
17-
$this->toHtml($badge)
16+
Blade::directive('recaptcha', fn (string $expression) => (
17+
"<?php echo app(".static::class.")->renderHtml({$expression}); ?>"
1818
));
1919

2020
Rule::macro('googleRecaptchaV3', fn (?float $scoreThreshold = null) => (
@@ -69,7 +69,7 @@ private function getHiddenBadgeStyle(): string
6969
CSS;
7070
}
7171

72-
private function toHtml(Badge $badge): string
72+
public function renderHtml(Badge $badge): string
7373
{
7474
if (! Config::isEnabled()) {
7575
return '';

tests/GoogleRecaptchaV3Test.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
it('renders recaptcha HTML with badge parameter', function (Badge $badge, bool $shouldContainBadgeParam) {
1313
$recaptcha = new GoogleRecaptchaV3;
1414

15-
$html = (fn () => $this->toHtml($badge))->call($recaptcha);
15+
$html = $recaptcha->renderHtml($badge);
1616

1717
expect($html)
1818
->toContain('https://www.google.com/recaptcha/api.js')
@@ -35,7 +35,7 @@
3535
it('renders hidden badge style for hidden badge', function () {
3636
$recaptcha = new GoogleRecaptchaV3;
3737

38-
$html = (fn () => $this->toHtml(Badge::HIDDEN))->call($recaptcha);
38+
$html = $recaptcha->renderHtml(Badge::HIDDEN);
3939

4040
expect($html)
4141
->toContain('.grecaptcha-badge')
@@ -47,7 +47,7 @@
4747
it('does not render hidden badge style for non-hidden badges', function (Badge $badge) {
4848
$recaptcha = new GoogleRecaptchaV3;
4949

50-
$html = (fn () => $this->toHtml($badge))->call($recaptcha);
50+
$html = $recaptcha->renderHtml($badge);
5151

5252
expect($html)
5353
->not->toContain('.grecaptcha-badge')
@@ -62,7 +62,7 @@
6262
config()->set('google-recaptcha-v3.enabled', false);
6363

6464
$recaptcha = new GoogleRecaptchaV3;
65-
$html = (fn () => $this->toHtml(Badge::BOTTOMRIGHT))->call($recaptcha);
65+
$html = $recaptcha->renderHtml(Badge::BOTTOMRIGHT);
6666

6767
expect($html)->toBe('');
6868
});
@@ -71,7 +71,7 @@
7171
config()->set('google-recaptcha-v3.site_key', null);
7272

7373
$recaptcha = new GoogleRecaptchaV3;
74-
$html = (fn () => $this->toHtml(Badge::BOTTOMRIGHT))->call($recaptcha);
74+
$html = $recaptcha->renderHtml(Badge::BOTTOMRIGHT);
7575

7676
expect($html)->toBe('');
7777
});
@@ -80,15 +80,15 @@
8080
config()->set('google-recaptcha-v3.secret_key', null);
8181

8282
$recaptcha = new GoogleRecaptchaV3;
83-
$html = (fn () => $this->toHtml(Badge::BOTTOMRIGHT))->call($recaptcha);
83+
$html = $recaptcha->renderHtml(Badge::BOTTOMRIGHT);
8484

8585
expect($html)->toBe('');
8686
});
8787

8888
it('includes window.recaptcha function in output', function () {
8989
$recaptcha = new GoogleRecaptchaV3;
9090

91-
$html = (fn () => $this->toHtml(Badge::BOTTOMRIGHT))->call($recaptcha);
91+
$html = $recaptcha->renderHtml(Badge::BOTTOMRIGHT);
9292

9393
expect($html)
9494
->toContain('window.recaptcha = function')
@@ -100,15 +100,15 @@
100100
it('includes site key in grecaptcha execute call', function () {
101101
$recaptcha = new GoogleRecaptchaV3;
102102

103-
$html = (fn () => $this->toHtml(Badge::BOTTOMRIGHT))->call($recaptcha);
103+
$html = $recaptcha->renderHtml(Badge::BOTTOMRIGHT);
104104

105105
expect($html)->toContain("grecaptcha.execute('test-site-key'");
106106
});
107107

108108
it('wraps scripts in script tags', function () {
109109
$recaptcha = new GoogleRecaptchaV3;
110110

111-
$html = (fn () => $this->toHtml(Badge::BOTTOMRIGHT))->call($recaptcha);
111+
$html = $recaptcha->renderHtml(Badge::BOTTOMRIGHT);
112112

113113
expect($html)
114114
->toMatch('/<script>.*?<\/script>/s')

0 commit comments

Comments
 (0)