File tree Expand file tree Collapse file tree 4 files changed +50
-28
lines changed
resources/views/googlerecaptchav3 Expand file tree Collapse file tree 4 files changed +50
-28
lines changed Original file line number Diff line number Diff line change 1
- @if (\TimeHunter \LaravelGoogleReCaptchaV3 \GoogleReCaptchaV3:: $hasAction === false )
2
- @if ($display === false )
3
- <style >
4
- .grecaptcha-badge {
5
- display : none ;
6
- }
7
- </style >
8
- @endif
9
- <script >
10
- if (! document .getElementById (' gReCaptchaScript' )) {
11
- let reCaptchaScript = document .createElement (' script' );
12
- reCaptchaScript .setAttribute (' src' , ' https://www.google.com/recaptcha/api.js?render={{ $publicKey } }' );
13
- reCaptchaScript .async = true ;
14
- reCaptchaScript .defer = true ;
15
- document .head .appendChild (reCaptchaScript);
1
+ @if ($display === false )
2
+ <style >
3
+ .grecaptcha-badge {
4
+ display : none ;
16
5
}
17
- </script >
6
+ </style >
18
7
@endif
8
+ <script >
9
+ if (! document .getElementById (' gReCaptchaScript' )) {
10
+ let reCaptchaScript = document .createElement (' script' );
11
+ reCaptchaScript .setAttribute (' src' , ' https://www.google.com/recaptcha/api.js?render={{ $publicKey } }' );
12
+ reCaptchaScript .async = true ;
13
+ reCaptchaScript .defer = true ;
14
+ document .head .appendChild (reCaptchaScript);
15
+ }
16
+ </script >
17
+
Original file line number Diff line number Diff line change 1
- {{ \TimeHunter \LaravelGoogleReCaptchaV3 \GoogleReCaptchaV3:: setHasAction (true ) } }
2
1
<script >
3
2
4
3
function onloadCallback () {
Original file line number Diff line number Diff line change @@ -17,30 +17,20 @@ class GoogleReCaptchaV3
17
17
private $ service ;
18
18
private $ defaultTemplate = 'GoogleReCaptchaV3::googlerecaptchav3.template ' ;
19
19
private $ defaultBackgroundTemplate = 'GoogleReCaptchaV3::googlerecaptchav3.background ' ;
20
-
21
20
public static $ hasAction = false ;
22
21
23
22
public function __construct (GoogleReCaptchaV3Service $ service )
24
23
{
25
24
$ this ->service = $ service ;
26
25
}
27
26
28
- /**
29
- * @param $value
30
- * @return bool
31
- */
32
- public static function setHasAction ($ value )
33
- {
34
- self ::$ hasAction = $ value ;
35
- return self ::$ hasAction ;
36
- }
37
-
38
27
/**
39
28
* @param $mappers
40
29
* @return array
41
30
*/
42
31
public function prepareViewData ($ mappers )
43
32
{
33
+ self ::$ hasAction = true ;
44
34
$ prepareData = [];
45
35
foreach ($ mappers as $ id => $ action ) {
46
36
$ prepareData [$ action ][] = $ id ;
@@ -72,6 +62,10 @@ public function prepareBackgroundData()
72
62
*/
73
63
public function background ()
74
64
{
65
+ if (self ::$ hasAction ){
66
+ return ;
67
+ }
68
+
75
69
return app ('view ' )
76
70
->make (
77
71
$ this ->getBackgroundView (),
Original file line number Diff line number Diff line change @@ -57,4 +57,34 @@ public function testView2()
57
57
$ this ->assertEquals (false , $ data ['inline ' ]);
58
58
$ this ->assertEquals ('en ' , $ data ['language ' ]);
59
59
}
60
+
61
+
62
+ public function testView3 ()
63
+ {
64
+ // Create a stub for the SomeClass class.
65
+ $ configStub = $ this ->createMock (ReCaptchaConfigV3::class);
66
+
67
+ // Configure the stub.
68
+ $ configStub ->method ('isServiceEnabled ' )
69
+ ->willReturn (true );
70
+
71
+ $ configStub ->method ('getSiteKey ' )
72
+ ->willReturn ('test1 ' );
73
+
74
+ $ configStub ->method ('isInline ' )
75
+ ->willReturn (false );
76
+
77
+ $ configStub ->method ('getLanguage ' )
78
+ ->willReturn ('en ' );
79
+
80
+ $ clientStub = $ this ->createMock (GuzzleRequestClient::class);
81
+
82
+ $ _service = new GoogleReCaptchaV3Service ($ configStub , $ clientStub );
83
+ $ service = new GoogleReCaptchaV3 ($ _service );
84
+
85
+ $ service ->prepareViewData (['contact_us_id ' => 'contact_us ' ]);
86
+ $ background = $ service ->background ();
87
+ $ this ->assertEquals ('' , $ background );
88
+
89
+ }
60
90
}
You can’t perform that action at this time.
0 commit comments