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,51 @@ 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 " => "dark " ,
111+ "size " => "compact " ,
112+ "tabindex " => "2 " ,
113+ "callback " => "callbackFunction " ,
114+ "expired-callback " => "expiredCallbackFunction " ,
115+ "error-callback " => "errorCallbackFunction " ,
116+ "not-allowed-attribute " => "error " ,
117+ ]);
118+ $ this ->assertEquals (
119+ '<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> ' ,
120+ $ html_snippet
121+ );
122+ }
123+
124+ public function testCleanAttributesReturnsOnlyAllowedAttributes ()
125+ {
126+ $ attributes = ReCaptchaBuilderV2::cleanAttributes ([
127+ "theme " => "theme " ,
128+ "size " => "size " ,
129+ "tabindex " => "tabindex " ,
130+ "callback " => "callback " ,
131+ "expired-callback " => "expired-callback " ,
132+ "error-callback " => "error-callback " ,
133+ "not-allowed-attribute " => "error " ,
134+ ]);
135+ $ this ->assertArrayHasKey ("theme " , $ attributes );
136+ $ this ->assertArrayHasKey ("size " , $ attributes );
137+ $ this ->assertArrayHasKey ("tabindex " , $ attributes );
138+ $ this ->assertArrayHasKey ("callback " , $ attributes );
139+ $ this ->assertArrayHasKey ("expired-callback " , $ attributes );
140+ $ this ->assertArrayHasKey ("error-callback " , $ attributes );
141+ $ this ->assertArrayNotHasKey ("not-allowed-attribute " , $ attributes );
101142 }
102143
103144 /**
@@ -121,4 +162,4 @@ protected function getEnvironmentSetUp($app)
121162 'error-callback ' => 'errorCallbackFunction ' ,
122163 ]);
123164 }
124- }
165+ }
0 commit comments