1
1
<?php
2
+
2
3
/**
3
4
* Copyright (c) 2017 - present
4
5
* LaravelGoogleRecaptcha - ReCaptchaHelpersV2Test.php
@@ -27,7 +28,6 @@ public function testHtmlScriptTagJsApiCalledByFacade()
27
28
->with (["key " => "val " ]);
28
29
29
30
htmlScriptTagJsApi (["key " => "val " ]);
30
-
31
31
}
32
32
33
33
/**
@@ -40,7 +40,6 @@ public function testHtmlFormSnippetCalledByFacade()
40
40
->once ();
41
41
42
42
htmlFormSnippet ();
43
-
44
43
}
45
44
46
45
/**
@@ -95,9 +94,51 @@ public function testHtmlFormSnippet()
95
94
{
96
95
97
96
$ 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
+ {
100
108
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 );
101
142
}
102
143
103
144
/**
@@ -121,4 +162,4 @@ protected function getEnvironmentSetUp($app)
121
162
'error-callback ' => 'errorCallbackFunction ' ,
122
163
]);
123
164
}
124
- }
165
+ }
0 commit comments