@@ -21,31 +21,31 @@ |
||
21 | 21 | class TestCase extends OrchestraTestCase |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Load package alias |
|
26 | - * |
|
27 | - * @param \Illuminate\Foundation\Application $app |
|
28 | - * |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - protected function getPackageAliases($app) |
|
32 | - { |
|
24 | + /** |
|
25 | + * Load package alias |
|
26 | + * |
|
27 | + * @param \Illuminate\Foundation\Application $app |
|
28 | + * |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + protected function getPackageAliases($app) |
|
32 | + { |
|
33 | 33 | |
34 | - return [ |
|
35 | - 'ReCaptcha' => ReCaptcha::class, |
|
36 | - ]; |
|
37 | - } |
|
34 | + return [ |
|
35 | + 'ReCaptcha' => ReCaptcha::class, |
|
36 | + ]; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Load package service provider |
|
41 | - * |
|
42 | - * @param \Illuminate\Foundation\Application $app |
|
43 | - * |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - protected function getPackageProviders($app) |
|
47 | - { |
|
39 | + /** |
|
40 | + * Load package service provider |
|
41 | + * |
|
42 | + * @param \Illuminate\Foundation\Application $app |
|
43 | + * |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + protected function getPackageProviders($app) |
|
47 | + { |
|
48 | 48 | |
49 | - return [ReCaptchaServiceProvider::class]; |
|
50 | - } |
|
49 | + return [ReCaptchaServiceProvider::class]; |
|
50 | + } |
|
51 | 51 | } |
@@ -19,14 +19,14 @@ |
||
19 | 19 | class ReCaptchaController extends Controller |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @return array |
|
24 | - */ |
|
25 | - public function validateV3(): array |
|
26 | - { |
|
22 | + /** |
|
23 | + * @return array |
|
24 | + */ |
|
25 | + public function validateV3(): array |
|
26 | + { |
|
27 | 27 | |
28 | - $token = request()->input(config('recaptcha.default_token_parameter_name', 'token'), ''); |
|
28 | + $token = request()->input(config('recaptcha.default_token_parameter_name', 'token'), ''); |
|
29 | 29 | |
30 | - return recaptcha()->validate($token); |
|
31 | - } |
|
30 | + return recaptcha()->validate($token); |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | \ No newline at end of file |
@@ -20,72 +20,72 @@ |
||
20 | 20 | class ReCaptchaConfigurationTest extends TestCase |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var ReCaptchaBuilder |
|
25 | - */ |
|
26 | - protected $recaptcha; |
|
27 | - |
|
28 | - /** |
|
29 | - * @test |
|
30 | - */ |
|
31 | - public function testGetApiSiteKey() { |
|
32 | - $this->assertEquals("api_site_key", $this->recaptcha->getApiSiteKey()); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @test |
|
37 | - */ |
|
38 | - public function testGetApiSecretKey() { |
|
39 | - $this->assertEquals("api_secret_key", $this->recaptcha->getApiSecretKey()); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @test |
|
44 | - */ |
|
45 | - public function testSkipIpWhiteListIsArray() |
|
46 | - { |
|
47 | - |
|
48 | - $ip_whitelist = $this->recaptcha->getIpWhitelist(); |
|
49 | - $this->assertTrue(is_array($ip_whitelist)); |
|
50 | - $this->assertCount(2, $ip_whitelist); |
|
51 | - |
|
52 | - $this->assertEquals('10.0.0.1', $ip_whitelist[0]); |
|
53 | - $this->assertEquals('10.0.0.2', $ip_whitelist[1]); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @test |
|
58 | - */ |
|
59 | - public function testCurlTimeoutIsSet() |
|
60 | - { |
|
61 | - |
|
62 | - $this->assertEquals(3, $this->recaptcha->getCurlTimeout()); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Define environment setup. |
|
67 | - * |
|
68 | - * @param \Illuminate\Foundation\Application $app |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - protected function getEnvironmentSetUp($app) |
|
73 | - { |
|
74 | - |
|
75 | - $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
76 | - $app['config']->set('recaptcha.api_secret_key', 'api_secret_key'); |
|
77 | - $app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2'); |
|
78 | - $app['config']->set('recaptcha.curl_timeout', 3); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Setup the test environment. |
|
83 | - */ |
|
84 | - protected function setUp(): void |
|
85 | - { |
|
86 | - |
|
87 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
88 | - |
|
89 | - $this->recaptcha = recaptcha(); |
|
90 | - } |
|
23 | + /** |
|
24 | + * @var ReCaptchaBuilder |
|
25 | + */ |
|
26 | + protected $recaptcha; |
|
27 | + |
|
28 | + /** |
|
29 | + * @test |
|
30 | + */ |
|
31 | + public function testGetApiSiteKey() { |
|
32 | + $this->assertEquals("api_site_key", $this->recaptcha->getApiSiteKey()); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @test |
|
37 | + */ |
|
38 | + public function testGetApiSecretKey() { |
|
39 | + $this->assertEquals("api_secret_key", $this->recaptcha->getApiSecretKey()); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @test |
|
44 | + */ |
|
45 | + public function testSkipIpWhiteListIsArray() |
|
46 | + { |
|
47 | + |
|
48 | + $ip_whitelist = $this->recaptcha->getIpWhitelist(); |
|
49 | + $this->assertTrue(is_array($ip_whitelist)); |
|
50 | + $this->assertCount(2, $ip_whitelist); |
|
51 | + |
|
52 | + $this->assertEquals('10.0.0.1', $ip_whitelist[0]); |
|
53 | + $this->assertEquals('10.0.0.2', $ip_whitelist[1]); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @test |
|
58 | + */ |
|
59 | + public function testCurlTimeoutIsSet() |
|
60 | + { |
|
61 | + |
|
62 | + $this->assertEquals(3, $this->recaptcha->getCurlTimeout()); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Define environment setup. |
|
67 | + * |
|
68 | + * @param \Illuminate\Foundation\Application $app |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + protected function getEnvironmentSetUp($app) |
|
73 | + { |
|
74 | + |
|
75 | + $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
76 | + $app['config']->set('recaptcha.api_secret_key', 'api_secret_key'); |
|
77 | + $app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2'); |
|
78 | + $app['config']->set('recaptcha.curl_timeout', 3); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Setup the test environment. |
|
83 | + */ |
|
84 | + protected function setUp(): void |
|
85 | + { |
|
86 | + |
|
87 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
88 | + |
|
89 | + $this->recaptcha = recaptcha(); |
|
90 | + } |
|
91 | 91 | } |
92 | 92 | \ No newline at end of file |
@@ -51,7 +51,7 @@ |
||
51 | 51 | Validator::extendImplicit(recaptchaRuleName(), function ($attribute, $value) { |
52 | 52 | |
53 | 53 | return app('recaptcha')->validate($value); |
54 | - }, trans('validation.recaptcha')); |
|
54 | + }, trans('validation.recaptcha')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -17,59 +17,59 @@ |
||
17 | 17 | class ReCaptchaLangTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var ReCaptchaBuilderInvisible |
|
22 | - */ |
|
23 | - protected $recaptcha_invisible; |
|
20 | + /** |
|
21 | + * @var ReCaptchaBuilderInvisible |
|
22 | + */ |
|
23 | + protected $recaptcha_invisible; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var ReCaptchaBuilderV2 |
|
27 | - */ |
|
28 | - protected $recaptcha_v2; |
|
25 | + /** |
|
26 | + * @var ReCaptchaBuilderV2 |
|
27 | + */ |
|
28 | + protected $recaptcha_v2; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @tests |
|
32 | - */ |
|
33 | - public function testHtmlScriptTagJsApiGetHtmlScriptWithHlParam() |
|
34 | - { |
|
30 | + /** |
|
31 | + * @tests |
|
32 | + */ |
|
33 | + public function testHtmlScriptTagJsApiGetHtmlScriptWithHlParam() |
|
34 | + { |
|
35 | 35 | |
36 | - $r = ReCaptcha::htmlScriptTagJsApi(); |
|
37 | - $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js?hl=it" async defer></script>', $r); |
|
38 | - } |
|
36 | + $r = ReCaptcha::htmlScriptTagJsApi(); |
|
37 | + $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js?hl=it" async defer></script>', $r); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @tests |
|
42 | - */ |
|
43 | - public function testHtmlScriptTagJsApiGetHtmlScriptOverridingHlParam() |
|
44 | - { |
|
40 | + /** |
|
41 | + * @tests |
|
42 | + */ |
|
43 | + public function testHtmlScriptTagJsApiGetHtmlScriptOverridingHlParam() |
|
44 | + { |
|
45 | 45 | |
46 | - $r = ReCaptcha::htmlScriptTagJsApi(['lang' => 'en']); |
|
47 | - $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js?hl=en" async defer></script>', $r); |
|
48 | - } |
|
46 | + $r = ReCaptcha::htmlScriptTagJsApi(['lang' => 'en']); |
|
47 | + $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js?hl=en" async defer></script>', $r); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Define environment setup. |
|
52 | - * |
|
53 | - * @param \Illuminate\Foundation\Application $app |
|
54 | - * |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - protected function getEnvironmentSetUp($app) |
|
58 | - { |
|
50 | + /** |
|
51 | + * Define environment setup. |
|
52 | + * |
|
53 | + * @param \Illuminate\Foundation\Application $app |
|
54 | + * |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + protected function getEnvironmentSetUp($app) |
|
58 | + { |
|
59 | 59 | |
60 | - $app['config']->set('recaptcha.default_language', 'it'); |
|
61 | - } |
|
60 | + $app['config']->set('recaptcha.default_language', 'it'); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Setup the test environment. |
|
65 | - */ |
|
66 | - protected function setUp(): void |
|
67 | - { |
|
63 | + /** |
|
64 | + * Setup the test environment. |
|
65 | + */ |
|
66 | + protected function setUp(): void |
|
67 | + { |
|
68 | 68 | |
69 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
69 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
70 | 70 | |
71 | - $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
72 | - $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
71 | + $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
72 | + $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
73 | 73 | |
74 | - } |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | \ No newline at end of file |
@@ -24,188 +24,188 @@ |
||
24 | 24 | class ReCaptchaTest extends TestCase |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var ReCaptchaBuilderInvisible |
|
29 | - */ |
|
30 | - protected $recaptcha_invisible = null; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var ReCaptchaBuilderV2 |
|
34 | - */ |
|
35 | - protected $recaptcha_v2 = null; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var ReCaptchaBuilderV3 |
|
39 | - */ |
|
40 | - protected $recaptcha_v3 = null; |
|
41 | - |
|
42 | - /** |
|
43 | - * @tests |
|
44 | - */ |
|
45 | - public function testHtmlScriptTagJsApiGetHtmlScriptTag() |
|
46 | - { |
|
47 | - |
|
48 | - $r = ReCaptcha::htmlScriptTagJsApi(); |
|
49 | - $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @test |
|
54 | - */ |
|
55 | - public function testReCaptchaInvisibleHtmlFormButtonDefault() |
|
56 | - { |
|
57 | - |
|
58 | - $recaptcha = $this->recaptcha_invisible; |
|
59 | - $html_button = $recaptcha->htmlFormButton(); |
|
60 | - $this->assertEquals( |
|
61 | - '<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Submit</button>', |
|
62 | - $html_button |
|
63 | - ); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @test |
|
68 | - */ |
|
69 | - public function testReCaptchaInvisibleHtmlFormButtonCustom() |
|
70 | - { |
|
71 | - |
|
72 | - $recaptcha = $this->recaptcha_invisible; |
|
73 | - $html_button = $recaptcha->htmlFormButton('Custom Text'); |
|
74 | - $this->assertEquals( |
|
75 | - '<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Custom Text</button>', |
|
76 | - $html_button |
|
77 | - ); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @test |
|
82 | - */ |
|
83 | - public function testReCaptchaV2HtmlFormSnippet() |
|
84 | - { |
|
85 | - |
|
86 | - $recaptcha = $this->recaptcha_v2; |
|
87 | - $html_snippet = $recaptcha->htmlFormSnippet(); |
|
88 | - $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key" data-size="normal" data-theme="light" id="recaptcha-element"></div>', $html_snippet); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @test |
|
93 | - * @expectedException \Error |
|
94 | - */ |
|
95 | - public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() |
|
96 | - { |
|
97 | - |
|
98 | - $this->recaptcha_invisible->htmlFormSnippet(); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @test |
|
103 | - */ |
|
104 | - public function testSkipByIpAndReturnArrayReturnsDefaultArray() |
|
105 | - { |
|
106 | - |
|
107 | - $mock = $this->getMockBuilder(ReCaptchaBuilder::class) |
|
108 | - ->setConstructorArgs([ |
|
109 | - "api_site_key", |
|
110 | - "api_secret_key" |
|
111 | - ]) |
|
112 | - ->setMethods([ |
|
113 | - 'returnArray' |
|
114 | - ]) |
|
115 | - ->getMock(); |
|
116 | - |
|
117 | - $mock->method('returnArray') |
|
118 | - ->willReturn(true); |
|
119 | - |
|
120 | - $this->setSkipByIp($this->recaptcha_v3, true); |
|
121 | - |
|
122 | - $validate = $this->recaptcha_v3->validate(""); |
|
123 | - |
|
124 | - $this->assertEquals([ |
|
125 | - "skip_by_ip" => true, |
|
126 | - "score" => 0.9, |
|
127 | - "success" => true |
|
128 | - ], $validate); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @test |
|
133 | - */ |
|
134 | - public function testSlipByIpReturnsValidResponse() |
|
135 | - { |
|
136 | - |
|
137 | - $this->setSkipByIp($this->recaptcha_invisible, true); |
|
138 | - $validate = $this->recaptcha_invisible->validate(""); |
|
139 | - |
|
140 | - $this->assertTrue($validate); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @test |
|
145 | - */ |
|
146 | - public function testDefaultCurlTimeout() |
|
147 | - { |
|
148 | - |
|
149 | - $this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
150 | - $this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
151 | - $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * @test |
|
156 | - * @expectedException \Error |
|
157 | - */ |
|
158 | - public function testReCaptchaV2htmlFormButtonShouldThrowError() |
|
159 | - { |
|
160 | - |
|
161 | - $this->recaptcha_v2->htmlFormButton(); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @test |
|
166 | - */ |
|
167 | - public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName() |
|
168 | - { |
|
169 | - $this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME, recaptchaFieldName()); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * @test |
|
174 | - */ |
|
175 | - public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName() |
|
176 | - { |
|
177 | - $this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME, recaptchaRuleName()); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @test |
|
182 | - */ |
|
183 | - public function testDefaultRecaptchaApiDomainIsGoogleDotCom() |
|
184 | - { |
|
185 | - $this->assertEquals("www.google.com", $this->recaptcha_v2->getApiDomain()); |
|
186 | - $this->assertEquals("www.google.com", $this->recaptcha_invisible->getApiDomain()); |
|
187 | - $this->assertEquals("www.google.com", $this->recaptcha_v3->getApiDomain()); |
|
188 | - } |
|
189 | - |
|
190 | - protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value) |
|
191 | - { |
|
192 | - |
|
193 | - $reflection = new \ReflectionClass($builder); |
|
194 | - $reflection_property = $reflection->getProperty('skip_by_ip'); |
|
195 | - $reflection_property->setAccessible(true); |
|
196 | - $reflection_property->setValue($builder, $value); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @inheritdoc |
|
201 | - */ |
|
202 | - protected function setUp(): void |
|
203 | - { |
|
204 | - |
|
205 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
206 | - |
|
207 | - $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
208 | - $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
209 | - $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); |
|
210 | - } |
|
27 | + /** |
|
28 | + * @var ReCaptchaBuilderInvisible |
|
29 | + */ |
|
30 | + protected $recaptcha_invisible = null; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var ReCaptchaBuilderV2 |
|
34 | + */ |
|
35 | + protected $recaptcha_v2 = null; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var ReCaptchaBuilderV3 |
|
39 | + */ |
|
40 | + protected $recaptcha_v3 = null; |
|
41 | + |
|
42 | + /** |
|
43 | + * @tests |
|
44 | + */ |
|
45 | + public function testHtmlScriptTagJsApiGetHtmlScriptTag() |
|
46 | + { |
|
47 | + |
|
48 | + $r = ReCaptcha::htmlScriptTagJsApi(); |
|
49 | + $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @test |
|
54 | + */ |
|
55 | + public function testReCaptchaInvisibleHtmlFormButtonDefault() |
|
56 | + { |
|
57 | + |
|
58 | + $recaptcha = $this->recaptcha_invisible; |
|
59 | + $html_button = $recaptcha->htmlFormButton(); |
|
60 | + $this->assertEquals( |
|
61 | + '<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Submit</button>', |
|
62 | + $html_button |
|
63 | + ); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @test |
|
68 | + */ |
|
69 | + public function testReCaptchaInvisibleHtmlFormButtonCustom() |
|
70 | + { |
|
71 | + |
|
72 | + $recaptcha = $this->recaptcha_invisible; |
|
73 | + $html_button = $recaptcha->htmlFormButton('Custom Text'); |
|
74 | + $this->assertEquals( |
|
75 | + '<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Custom Text</button>', |
|
76 | + $html_button |
|
77 | + ); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @test |
|
82 | + */ |
|
83 | + public function testReCaptchaV2HtmlFormSnippet() |
|
84 | + { |
|
85 | + |
|
86 | + $recaptcha = $this->recaptcha_v2; |
|
87 | + $html_snippet = $recaptcha->htmlFormSnippet(); |
|
88 | + $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key" data-size="normal" data-theme="light" id="recaptcha-element"></div>', $html_snippet); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @test |
|
93 | + * @expectedException \Error |
|
94 | + */ |
|
95 | + public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() |
|
96 | + { |
|
97 | + |
|
98 | + $this->recaptcha_invisible->htmlFormSnippet(); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @test |
|
103 | + */ |
|
104 | + public function testSkipByIpAndReturnArrayReturnsDefaultArray() |
|
105 | + { |
|
106 | + |
|
107 | + $mock = $this->getMockBuilder(ReCaptchaBuilder::class) |
|
108 | + ->setConstructorArgs([ |
|
109 | + "api_site_key", |
|
110 | + "api_secret_key" |
|
111 | + ]) |
|
112 | + ->setMethods([ |
|
113 | + 'returnArray' |
|
114 | + ]) |
|
115 | + ->getMock(); |
|
116 | + |
|
117 | + $mock->method('returnArray') |
|
118 | + ->willReturn(true); |
|
119 | + |
|
120 | + $this->setSkipByIp($this->recaptcha_v3, true); |
|
121 | + |
|
122 | + $validate = $this->recaptcha_v3->validate(""); |
|
123 | + |
|
124 | + $this->assertEquals([ |
|
125 | + "skip_by_ip" => true, |
|
126 | + "score" => 0.9, |
|
127 | + "success" => true |
|
128 | + ], $validate); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @test |
|
133 | + */ |
|
134 | + public function testSlipByIpReturnsValidResponse() |
|
135 | + { |
|
136 | + |
|
137 | + $this->setSkipByIp($this->recaptcha_invisible, true); |
|
138 | + $validate = $this->recaptcha_invisible->validate(""); |
|
139 | + |
|
140 | + $this->assertTrue($validate); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @test |
|
145 | + */ |
|
146 | + public function testDefaultCurlTimeout() |
|
147 | + { |
|
148 | + |
|
149 | + $this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
150 | + $this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
151 | + $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * @test |
|
156 | + * @expectedException \Error |
|
157 | + */ |
|
158 | + public function testReCaptchaV2htmlFormButtonShouldThrowError() |
|
159 | + { |
|
160 | + |
|
161 | + $this->recaptcha_v2->htmlFormButton(); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @test |
|
166 | + */ |
|
167 | + public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName() |
|
168 | + { |
|
169 | + $this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME, recaptchaFieldName()); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * @test |
|
174 | + */ |
|
175 | + public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName() |
|
176 | + { |
|
177 | + $this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME, recaptchaRuleName()); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @test |
|
182 | + */ |
|
183 | + public function testDefaultRecaptchaApiDomainIsGoogleDotCom() |
|
184 | + { |
|
185 | + $this->assertEquals("www.google.com", $this->recaptcha_v2->getApiDomain()); |
|
186 | + $this->assertEquals("www.google.com", $this->recaptcha_invisible->getApiDomain()); |
|
187 | + $this->assertEquals("www.google.com", $this->recaptcha_v3->getApiDomain()); |
|
188 | + } |
|
189 | + |
|
190 | + protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value) |
|
191 | + { |
|
192 | + |
|
193 | + $reflection = new \ReflectionClass($builder); |
|
194 | + $reflection_property = $reflection->getProperty('skip_by_ip'); |
|
195 | + $reflection_property->setAccessible(true); |
|
196 | + $reflection_property->setValue($builder, $value); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @inheritdoc |
|
201 | + */ |
|
202 | + protected function setUp(): void |
|
203 | + { |
|
204 | + |
|
205 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
206 | + |
|
207 | + $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
208 | + $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
209 | + $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); |
|
210 | + } |
|
211 | 211 | } |