11<?php
2+
23/**
34 * Copyright (c) 2017 - present
45 * LaravelGoogleRecaptcha - ReCaptchaHelpersV2Test.php
@@ -27,7 +28,6 @@ public function testHtmlScriptTagJsApiCalledByFacade()
2728 ->with (["key " => "val " ]);
2829
2930 htmlScriptTagJsApi (["key " => "val " ]);
30-
3131 }
3232
3333 /**
@@ -40,7 +40,6 @@ public function testHtmlFormSnippetCalledByFacade()
4040 ->once ();
4141
4242 htmlFormSnippet ();
43-
4443 }
4544
4645 /**
@@ -95,9 +94,70 @@ public function testHtmlFormSnippet()
9594 {
9695
9796 $ html_snippet = \recaptcha ()->htmlFormSnippet ();
98- $ this ->assertEquals ('<div class="g-recaptcha" data-sitekey="api_site_key" data-theme="dark" data-size="compact" data-tabindex="2" data-callback="callbackFunction" data-expired-callback="expiredCallbackFunction" data-error-callback="errorCallbackFunction" id="recaptcha-element"></div> ' ,
99- $ html_snippet );
97+ $ this ->assertEquals (
98+ '<div class="g-recaptcha" data-callback="callbackFunction" data-error-callback="errorCallbackFunction" data-expired-callback="expiredCallbackFunction" data-sitekey="api_site_key" data-size="compact" data-tabindex="2" data-theme="dark" id="recaptcha-element"></div> ' ,
99+ $ html_snippet
100+ );
101+ }
102+
103+ /**
104+ * @test
105+ */
106+ public function testHtmlFormSnippetOverridesDefaultAttributes ()
107+ {
100108
109+ $ html_snippet = \recaptcha ()->htmlFormSnippet ([
110+ "theme " => "light " ,
111+ "size " => "normal " ,
112+ "tabindex " => "3 " ,
113+ "callback " => "callbackFunctionNew " ,
114+ "expired-callback " => "expiredCallbackFunctionNew " ,
115+ "error-callback " => "errorCallbackFunctionNew " ,
116+ "not-allowed-attribute " => "error " ,
117+ ]);
118+ $ this ->assertEquals (
119+ '<div class="g-recaptcha" data-callback="callbackFunctionNew" data-error-callback="errorCallbackFunctionNew" data-expired-callback="expiredCallbackFunctionNew" data-sitekey="api_site_key" data-size="normal" data-tabindex="3" data-theme="light" id="recaptcha-element"></div> ' ,
120+ $ html_snippet
121+ );
122+ }
123+
124+ /**
125+ * @test
126+ */
127+ public function testCleanAttributesReturnsOnlyAllowedAttributes ()
128+ {
129+ $ attributes = ReCaptchaBuilderV2::cleanAttributes ([
130+ "theme " => "theme " ,
131+ "size " => "size " ,
132+ "tabindex " => "tabindex " ,
133+ "callback " => "callback " ,
134+ "expired-callback " => "expired-callback " ,
135+ "error-callback " => "error-callback " ,
136+ "not-allowed-attribute " => "error " ,
137+ ]);
138+ $ this ->assertArrayHasKey ("theme " , $ attributes );
139+ $ this ->assertArrayHasKey ("size " , $ attributes );
140+ $ this ->assertArrayHasKey ("tabindex " , $ attributes );
141+ $ this ->assertArrayHasKey ("callback " , $ attributes );
142+ $ this ->assertArrayHasKey ("expired-callback " , $ attributes );
143+ $ this ->assertArrayHasKey ("error-callback " , $ attributes );
144+ $ this ->assertArrayNotHasKey ("not-allowed-attribute " , $ attributes );
145+ }
146+
147+ /**
148+ * @test
149+ */
150+ public function testHtmlFormSnippetKeepsDefaultConfigValuesUnlessOtherwiseStated ()
151+ {
152+ $ html_snippet = \recaptcha ()->htmlFormSnippet ([
153+ 'callback ' => 'callbackFunction ' ,
154+ 'expired-callback ' => 'expiredCallbackFunction ' ,
155+ 'error-callback ' => 'errorCallbackFunction ' ,
156+ ]);
157+ $ this ->assertEquals (
158+ '<div class="g-recaptcha" data-callback="callbackFunction" data-error-callback="errorCallbackFunction" data-expired-callback="expiredCallbackFunction" data-sitekey="api_site_key" data-size="compact" data-tabindex="2" data-theme="dark" id="recaptcha-element"></div> ' ,
159+ $ html_snippet
160+ );
101161 }
102162
103163 /**
@@ -121,4 +181,4 @@ protected function getEnvironmentSetUp($app)
121181 'error-callback ' => 'errorCallbackFunction ' ,
122182 ]);
123183 }
124- }
184+ }
0 commit comments