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,70 @@ 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 " => "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
+ );
101
161
}
102
162
103
163
/**
@@ -121,4 +181,4 @@ protected function getEnvironmentSetUp($app)
121
181
'error-callback ' => 'errorCallbackFunction ' ,
122
182
]);
123
183
}
124
- }
184
+ }
0 commit comments