@@ -20,67 +20,67 @@ |
||
20 | 20 | class ReCaptchaConfigurationTest extends TestCase |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var ReCaptchaBuilder |
|
25 | - */ |
|
26 | - protected $recaptcha; |
|
23 | + /** |
|
24 | + * @var ReCaptchaBuilder |
|
25 | + */ |
|
26 | + protected $recaptcha; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @test |
|
30 | - */ |
|
31 | - public function testGetApiSiteKey() { |
|
32 | - $this->assertEquals("api_site_key", $this->recaptcha->getApiSiteKey()); |
|
33 | - } |
|
28 | + /** |
|
29 | + * @test |
|
30 | + */ |
|
31 | + public function testGetApiSiteKey() { |
|
32 | + $this->assertEquals("api_site_key", $this->recaptcha->getApiSiteKey()); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @test |
|
37 | - */ |
|
38 | - public function testGetApiSecretKey() { |
|
39 | - $this->assertEquals("api_secret_key", $this->recaptcha->getApiSecretKey()); |
|
40 | - } |
|
35 | + /** |
|
36 | + * @test |
|
37 | + */ |
|
38 | + public function testGetApiSecretKey() { |
|
39 | + $this->assertEquals("api_secret_key", $this->recaptcha->getApiSecretKey()); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @test |
|
44 | - */ |
|
45 | - public function testSkipIpWhiteListIsArray() |
|
46 | - { |
|
42 | + /** |
|
43 | + * @test |
|
44 | + */ |
|
45 | + public function testSkipIpWhiteListIsArray() |
|
46 | + { |
|
47 | 47 | |
48 | - $ip_whitelist = $this->recaptcha->getIpWhitelist(); |
|
49 | - $this->assertTrue(is_array($ip_whitelist)); |
|
50 | - $this->assertCount(2, $ip_whitelist); |
|
51 | - } |
|
48 | + $ip_whitelist = $this->recaptcha->getIpWhitelist(); |
|
49 | + $this->assertTrue(is_array($ip_whitelist)); |
|
50 | + $this->assertCount(2, $ip_whitelist); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @test |
|
55 | - */ |
|
56 | - public function testCurlTimeoutIsSet() |
|
57 | - { |
|
53 | + /** |
|
54 | + * @test |
|
55 | + */ |
|
56 | + public function testCurlTimeoutIsSet() |
|
57 | + { |
|
58 | 58 | |
59 | - $this->assertEquals(3, $this->recaptcha->getCurlTimeout()); |
|
60 | - } |
|
59 | + $this->assertEquals(3, $this->recaptcha->getCurlTimeout()); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Define environment setup. |
|
64 | - * |
|
65 | - * @param \Illuminate\Foundation\Application $app |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - protected function getEnvironmentSetUp($app) |
|
70 | - { |
|
62 | + /** |
|
63 | + * Define environment setup. |
|
64 | + * |
|
65 | + * @param \Illuminate\Foundation\Application $app |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + protected function getEnvironmentSetUp($app) |
|
70 | + { |
|
71 | 71 | |
72 | - $app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2'); |
|
73 | - $app['config']->set('recaptcha.curl_timeout', 3); |
|
74 | - } |
|
72 | + $app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2'); |
|
73 | + $app['config']->set('recaptcha.curl_timeout', 3); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Setup the test environment. |
|
78 | - */ |
|
79 | - protected function setUp(): void |
|
80 | - { |
|
76 | + /** |
|
77 | + * Setup the test environment. |
|
78 | + */ |
|
79 | + protected function setUp(): void |
|
80 | + { |
|
81 | 81 | |
82 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
82 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
83 | 83 | |
84 | - $this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
85 | - } |
|
84 | + $this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
85 | + } |
|
86 | 86 | } |
87 | 87 | \ No newline at end of file |
@@ -23,169 +23,169 @@ |
||
23 | 23 | class ReCaptchaTest extends TestCase |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var ReCaptchaBuilderInvisible |
|
28 | - */ |
|
29 | - protected $recaptcha_invisible = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var ReCaptchaBuilderV2 |
|
33 | - */ |
|
34 | - protected $recaptcha_v2 = null; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var ReCaptchaBuilderV3 |
|
38 | - */ |
|
39 | - protected $recaptcha_v3 = null; |
|
40 | - |
|
41 | - /** |
|
42 | - * @tests |
|
43 | - */ |
|
44 | - public function testHtmlScriptTagJsApiGetHtmlScriptTag() |
|
45 | - { |
|
46 | - |
|
47 | - $r = ReCaptcha::htmlScriptTagJsApi(); |
|
48 | - $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @test |
|
53 | - */ |
|
54 | - public function testReCaptchaInvisibleHtmlFormButtonDefault() |
|
55 | - { |
|
56 | - |
|
57 | - $recaptcha = $this->recaptcha_invisible; |
|
58 | - $html_button = $recaptcha->htmlFormButton(); |
|
59 | - $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>', |
|
60 | - $html_button); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * @test |
|
65 | - */ |
|
66 | - public function testReCaptchaInvisibleHtmlFormButtonCustom() |
|
67 | - { |
|
68 | - |
|
69 | - $recaptcha = $this->recaptcha_invisible; |
|
70 | - $html_button = $recaptcha->htmlFormButton('Custom Text'); |
|
71 | - $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>', |
|
72 | - $html_button); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @test |
|
77 | - */ |
|
78 | - public function testReCaptchaV2HtmlFormSnippet() |
|
79 | - { |
|
80 | - |
|
81 | - $recaptcha = $this->recaptcha_v2; |
|
82 | - $html_snippet = $recaptcha->htmlFormSnippet(); |
|
83 | - $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @test |
|
88 | - * @expectedException \Error |
|
89 | - */ |
|
90 | - public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() |
|
91 | - { |
|
92 | - |
|
93 | - $this->recaptcha_invisible->htmlFormSnippet(); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @test |
|
98 | - */ |
|
99 | - public function testSkipByIpAndReturnArrayReturnsDefaultArray() |
|
100 | - { |
|
101 | - |
|
102 | - $mock = $this->getMockBuilder(ReCaptchaBuilder::class) |
|
103 | - ->setConstructorArgs([ |
|
104 | - "api_site_key", |
|
105 | - "api_secret_key" |
|
106 | - ]) |
|
107 | - ->setMethods([ |
|
108 | - 'returnArray' |
|
109 | - ]) |
|
110 | - ->getMock(); |
|
111 | - |
|
112 | - $mock->method('returnArray') |
|
113 | - ->willReturn(true); |
|
114 | - |
|
115 | - $this->setSkipByIp($this->recaptcha_v3, true); |
|
116 | - |
|
117 | - $validate = $this->recaptcha_v3->validate(""); |
|
118 | - |
|
119 | - $this->assertEquals([ |
|
120 | - "skip_by_ip" => true, |
|
121 | - "score" => 0.9, |
|
122 | - "success" => true |
|
123 | - ], $validate); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @test |
|
128 | - */ |
|
129 | - public function testSlipByIpReturnsValidResponse() |
|
130 | - { |
|
131 | - |
|
132 | - $this->setSkipByIp($this->recaptcha_invisible, true); |
|
133 | - $validate = $this->recaptcha_invisible->validate(""); |
|
134 | - |
|
135 | - $this->assertTrue($validate); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @test |
|
140 | - * @expectedException \Exception |
|
141 | - */ |
|
142 | - public function testReCaptchaInvisibleHtmlScriptTagJsApiShouldThrowError() |
|
143 | - { |
|
144 | - |
|
145 | - $this->recaptcha_invisible->htmlScriptTagJsApi(); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @test |
|
150 | - */ |
|
151 | - public function testDefaultCurlTimeout() |
|
152 | - { |
|
153 | - |
|
154 | - $this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
155 | - $this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
156 | - $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @test |
|
161 | - * @expectedException \Error |
|
162 | - */ |
|
163 | - public function testReCaptchaV2htmlFormButtonShouldThrowError() |
|
164 | - { |
|
165 | - |
|
166 | - $this->recaptcha_v2->htmlFormButton(); |
|
167 | - } |
|
168 | - |
|
169 | - protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value) |
|
170 | - { |
|
171 | - |
|
172 | - $reflection = new \ReflectionClass($builder); |
|
173 | - $reflection_property = $reflection->getProperty('skip_by_ip'); |
|
174 | - $reflection_property->setAccessible(true); |
|
175 | - $reflection_property->setValue($builder, $value); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @inheritdoc |
|
180 | - */ |
|
181 | - protected function setUp(): void |
|
182 | - { |
|
183 | - |
|
184 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
185 | - |
|
186 | - $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
187 | - $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
188 | - $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); |
|
189 | - |
|
190 | - } |
|
26 | + /** |
|
27 | + * @var ReCaptchaBuilderInvisible |
|
28 | + */ |
|
29 | + protected $recaptcha_invisible = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var ReCaptchaBuilderV2 |
|
33 | + */ |
|
34 | + protected $recaptcha_v2 = null; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var ReCaptchaBuilderV3 |
|
38 | + */ |
|
39 | + protected $recaptcha_v3 = null; |
|
40 | + |
|
41 | + /** |
|
42 | + * @tests |
|
43 | + */ |
|
44 | + public function testHtmlScriptTagJsApiGetHtmlScriptTag() |
|
45 | + { |
|
46 | + |
|
47 | + $r = ReCaptcha::htmlScriptTagJsApi(); |
|
48 | + $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @test |
|
53 | + */ |
|
54 | + public function testReCaptchaInvisibleHtmlFormButtonDefault() |
|
55 | + { |
|
56 | + |
|
57 | + $recaptcha = $this->recaptcha_invisible; |
|
58 | + $html_button = $recaptcha->htmlFormButton(); |
|
59 | + $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>', |
|
60 | + $html_button); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * @test |
|
65 | + */ |
|
66 | + public function testReCaptchaInvisibleHtmlFormButtonCustom() |
|
67 | + { |
|
68 | + |
|
69 | + $recaptcha = $this->recaptcha_invisible; |
|
70 | + $html_button = $recaptcha->htmlFormButton('Custom Text'); |
|
71 | + $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>', |
|
72 | + $html_button); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @test |
|
77 | + */ |
|
78 | + public function testReCaptchaV2HtmlFormSnippet() |
|
79 | + { |
|
80 | + |
|
81 | + $recaptcha = $this->recaptcha_v2; |
|
82 | + $html_snippet = $recaptcha->htmlFormSnippet(); |
|
83 | + $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @test |
|
88 | + * @expectedException \Error |
|
89 | + */ |
|
90 | + public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() |
|
91 | + { |
|
92 | + |
|
93 | + $this->recaptcha_invisible->htmlFormSnippet(); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @test |
|
98 | + */ |
|
99 | + public function testSkipByIpAndReturnArrayReturnsDefaultArray() |
|
100 | + { |
|
101 | + |
|
102 | + $mock = $this->getMockBuilder(ReCaptchaBuilder::class) |
|
103 | + ->setConstructorArgs([ |
|
104 | + "api_site_key", |
|
105 | + "api_secret_key" |
|
106 | + ]) |
|
107 | + ->setMethods([ |
|
108 | + 'returnArray' |
|
109 | + ]) |
|
110 | + ->getMock(); |
|
111 | + |
|
112 | + $mock->method('returnArray') |
|
113 | + ->willReturn(true); |
|
114 | + |
|
115 | + $this->setSkipByIp($this->recaptcha_v3, true); |
|
116 | + |
|
117 | + $validate = $this->recaptcha_v3->validate(""); |
|
118 | + |
|
119 | + $this->assertEquals([ |
|
120 | + "skip_by_ip" => true, |
|
121 | + "score" => 0.9, |
|
122 | + "success" => true |
|
123 | + ], $validate); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @test |
|
128 | + */ |
|
129 | + public function testSlipByIpReturnsValidResponse() |
|
130 | + { |
|
131 | + |
|
132 | + $this->setSkipByIp($this->recaptcha_invisible, true); |
|
133 | + $validate = $this->recaptcha_invisible->validate(""); |
|
134 | + |
|
135 | + $this->assertTrue($validate); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @test |
|
140 | + * @expectedException \Exception |
|
141 | + */ |
|
142 | + public function testReCaptchaInvisibleHtmlScriptTagJsApiShouldThrowError() |
|
143 | + { |
|
144 | + |
|
145 | + $this->recaptcha_invisible->htmlScriptTagJsApi(); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @test |
|
150 | + */ |
|
151 | + public function testDefaultCurlTimeout() |
|
152 | + { |
|
153 | + |
|
154 | + $this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
155 | + $this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
156 | + $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @test |
|
161 | + * @expectedException \Error |
|
162 | + */ |
|
163 | + public function testReCaptchaV2htmlFormButtonShouldThrowError() |
|
164 | + { |
|
165 | + |
|
166 | + $this->recaptcha_v2->htmlFormButton(); |
|
167 | + } |
|
168 | + |
|
169 | + protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value) |
|
170 | + { |
|
171 | + |
|
172 | + $reflection = new \ReflectionClass($builder); |
|
173 | + $reflection_property = $reflection->getProperty('skip_by_ip'); |
|
174 | + $reflection_property->setAccessible(true); |
|
175 | + $reflection_property->setValue($builder, $value); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @inheritdoc |
|
180 | + */ |
|
181 | + protected function setUp(): void |
|
182 | + { |
|
183 | + |
|
184 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
185 | + |
|
186 | + $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
187 | + $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
188 | + $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); |
|
189 | + |
|
190 | + } |
|
191 | 191 | } |
192 | 192 | \ No newline at end of file |
@@ -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 | } |
@@ -17,71 +17,71 @@ |
||
17 | 17 | class ReCaptchaHelpersInvisibleTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @test |
|
22 | - */ |
|
23 | - public function testHtmlScriptTagJsApiCalledByFacade() |
|
24 | - { |
|
25 | - ReCaptcha::shouldReceive('htmlScriptTagJsApi') |
|
26 | - ->once() |
|
27 | - ->with("key"); |
|
28 | - |
|
29 | - htmlScriptTagJsApi("key"); |
|
30 | - |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @test |
|
35 | - */ |
|
36 | - public function testHtmlScriptTagJsApiV3CalledByFacade() |
|
37 | - { |
|
38 | - ReCaptcha::shouldReceive('htmlScriptTagJsApiV3') |
|
39 | - ->once() |
|
40 | - ->with([]); |
|
41 | - |
|
42 | - htmlScriptTagJsApiV3([]); |
|
43 | - |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * @test |
|
48 | - */ |
|
49 | - public function testHtmlFormButtonCalledByFacade() |
|
50 | - { |
|
51 | - ReCaptcha::shouldReceive('htmlFormButton') |
|
52 | - ->once() |
|
53 | - ->with("key"); |
|
54 | - |
|
55 | - htmlFormButton("key"); |
|
56 | - |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @test |
|
61 | - * @expectedException \TypeError |
|
62 | - */ |
|
63 | - public function testHtmlFormSnippetCalledByFacade() |
|
64 | - { |
|
65 | - ReCaptcha::shouldReceive('htmlFormSnippet') |
|
66 | - ->once(); |
|
67 | - |
|
68 | - htmlFormSnippet(); |
|
69 | - |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Define environment setup. |
|
75 | - * |
|
76 | - * @param \Illuminate\Foundation\Application $app |
|
77 | - * |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - protected function getEnvironmentSetUp($app) |
|
81 | - { |
|
82 | - |
|
83 | - $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
84 | - $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
85 | - $app['config']->set('recaptcha.version', 'invisible'); |
|
86 | - } |
|
20 | + /** |
|
21 | + * @test |
|
22 | + */ |
|
23 | + public function testHtmlScriptTagJsApiCalledByFacade() |
|
24 | + { |
|
25 | + ReCaptcha::shouldReceive('htmlScriptTagJsApi') |
|
26 | + ->once() |
|
27 | + ->with("key"); |
|
28 | + |
|
29 | + htmlScriptTagJsApi("key"); |
|
30 | + |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @test |
|
35 | + */ |
|
36 | + public function testHtmlScriptTagJsApiV3CalledByFacade() |
|
37 | + { |
|
38 | + ReCaptcha::shouldReceive('htmlScriptTagJsApiV3') |
|
39 | + ->once() |
|
40 | + ->with([]); |
|
41 | + |
|
42 | + htmlScriptTagJsApiV3([]); |
|
43 | + |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * @test |
|
48 | + */ |
|
49 | + public function testHtmlFormButtonCalledByFacade() |
|
50 | + { |
|
51 | + ReCaptcha::shouldReceive('htmlFormButton') |
|
52 | + ->once() |
|
53 | + ->with("key"); |
|
54 | + |
|
55 | + htmlFormButton("key"); |
|
56 | + |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @test |
|
61 | + * @expectedException \TypeError |
|
62 | + */ |
|
63 | + public function testHtmlFormSnippetCalledByFacade() |
|
64 | + { |
|
65 | + ReCaptcha::shouldReceive('htmlFormSnippet') |
|
66 | + ->once(); |
|
67 | + |
|
68 | + htmlFormSnippet(); |
|
69 | + |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Define environment setup. |
|
75 | + * |
|
76 | + * @param \Illuminate\Foundation\Application $app |
|
77 | + * |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + protected function getEnvironmentSetUp($app) |
|
81 | + { |
|
82 | + |
|
83 | + $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
84 | + $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
85 | + $app['config']->set('recaptcha.version', 'invisible'); |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | \ No newline at end of file |
@@ -21,112 +21,112 @@ |
||
21 | 21 | class ReCaptchaV3Test extends TestCase |
22 | 22 | { |
23 | 23 | |
24 | - protected $recaptcha_v3 = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * @test |
|
28 | - */ |
|
29 | - public function testGetApiVersion() |
|
30 | - { |
|
31 | - |
|
32 | - $this->assertEquals($this->recaptcha_v3->getVersion(), 'v3'); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @test |
|
37 | - */ |
|
38 | - public function testHtmlScriptTagJsApiV3GetHtmlScriptTag() |
|
39 | - { |
|
40 | - |
|
41 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(); |
|
42 | - $this->assertRegexp('/csrfToken/', $r); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @test |
|
47 | - */ |
|
48 | - public function testAction() |
|
49 | - { |
|
50 | - |
|
51 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['action' => 'someAction']); |
|
52 | - $this->assertRegexp('/someAction/', $r); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @test |
|
57 | - */ |
|
58 | - public function testFetchCallbackFunction() |
|
59 | - { |
|
60 | - |
|
61 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_then' => 'functionCallbackThen']); |
|
62 | - $this->assertRegexp('/functionCallbackThen\(response\)/', $r); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @test |
|
67 | - */ |
|
68 | - public function testcCatchCallbackFunction() |
|
69 | - { |
|
70 | - |
|
71 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_catch' => 'functionCallbackCatch']); |
|
72 | - $this->assertRegexp('/functionCallbackCatch\(err\)/', $r); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @test |
|
77 | - */ |
|
78 | - public function testCustomValidationFunction() |
|
79 | - { |
|
80 | - |
|
81 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['custom_validation' => 'functionCustomValidation']); |
|
82 | - $this->assertRegexp('/functionCustomValidation\(token\)/', $r); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @test |
|
87 | - */ |
|
88 | - public function testValidateController() |
|
89 | - { |
|
90 | - |
|
91 | - $controller = App::make(ReCaptchaController::class); |
|
92 | - $return = $controller->validateV3(); |
|
93 | - |
|
94 | - $this->assertArrayHasKey("success", $return); |
|
95 | - $this->assertArrayHasKey("error-codes", $return); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @test |
|
100 | - */ |
|
101 | - public function testCurlTimeoutIsSet() |
|
102 | - { |
|
103 | - |
|
104 | - $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), 3); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Define environment setup. |
|
109 | - * |
|
110 | - * @param \Illuminate\Foundation\Application $app |
|
111 | - * |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - protected function getEnvironmentSetUp($app) |
|
115 | - { |
|
116 | - |
|
117 | - $app['config']->set('recaptcha.version', 'v3'); |
|
118 | - $app['config']->set('recaptcha.curl_timeout', 3); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Setup the test environment. |
|
123 | - */ |
|
124 | - protected function setUp(): void |
|
125 | - { |
|
126 | - |
|
127 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
128 | - |
|
129 | - $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); |
|
130 | - |
|
131 | - } |
|
24 | + protected $recaptcha_v3 = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * @test |
|
28 | + */ |
|
29 | + public function testGetApiVersion() |
|
30 | + { |
|
31 | + |
|
32 | + $this->assertEquals($this->recaptcha_v3->getVersion(), 'v3'); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @test |
|
37 | + */ |
|
38 | + public function testHtmlScriptTagJsApiV3GetHtmlScriptTag() |
|
39 | + { |
|
40 | + |
|
41 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(); |
|
42 | + $this->assertRegexp('/csrfToken/', $r); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @test |
|
47 | + */ |
|
48 | + public function testAction() |
|
49 | + { |
|
50 | + |
|
51 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['action' => 'someAction']); |
|
52 | + $this->assertRegexp('/someAction/', $r); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @test |
|
57 | + */ |
|
58 | + public function testFetchCallbackFunction() |
|
59 | + { |
|
60 | + |
|
61 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_then' => 'functionCallbackThen']); |
|
62 | + $this->assertRegexp('/functionCallbackThen\(response\)/', $r); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @test |
|
67 | + */ |
|
68 | + public function testcCatchCallbackFunction() |
|
69 | + { |
|
70 | + |
|
71 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_catch' => 'functionCallbackCatch']); |
|
72 | + $this->assertRegexp('/functionCallbackCatch\(err\)/', $r); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @test |
|
77 | + */ |
|
78 | + public function testCustomValidationFunction() |
|
79 | + { |
|
80 | + |
|
81 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['custom_validation' => 'functionCustomValidation']); |
|
82 | + $this->assertRegexp('/functionCustomValidation\(token\)/', $r); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @test |
|
87 | + */ |
|
88 | + public function testValidateController() |
|
89 | + { |
|
90 | + |
|
91 | + $controller = App::make(ReCaptchaController::class); |
|
92 | + $return = $controller->validateV3(); |
|
93 | + |
|
94 | + $this->assertArrayHasKey("success", $return); |
|
95 | + $this->assertArrayHasKey("error-codes", $return); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @test |
|
100 | + */ |
|
101 | + public function testCurlTimeoutIsSet() |
|
102 | + { |
|
103 | + |
|
104 | + $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), 3); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Define environment setup. |
|
109 | + * |
|
110 | + * @param \Illuminate\Foundation\Application $app |
|
111 | + * |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + protected function getEnvironmentSetUp($app) |
|
115 | + { |
|
116 | + |
|
117 | + $app['config']->set('recaptcha.version', 'v3'); |
|
118 | + $app['config']->set('recaptcha.curl_timeout', 3); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Setup the test environment. |
|
123 | + */ |
|
124 | + protected function setUp(): void |
|
125 | + { |
|
126 | + |
|
127 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
128 | + |
|
129 | + $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); |
|
130 | + |
|
131 | + } |
|
132 | 132 | } |
133 | 133 | \ No newline at end of file |
@@ -17,71 +17,71 @@ |
||
17 | 17 | class ReCaptchaHelpersV2Test extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @test |
|
22 | - */ |
|
23 | - public function testHtmlScriptTagJsApiCalledByFacade() |
|
24 | - { |
|
25 | - ReCaptcha::shouldReceive('htmlScriptTagJsApi') |
|
26 | - ->once() |
|
27 | - ->with("key"); |
|
28 | - |
|
29 | - htmlScriptTagJsApi("key"); |
|
30 | - |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @test |
|
35 | - */ |
|
36 | - public function testHtmlScriptTagJsApiV3CalledByFacade() |
|
37 | - { |
|
38 | - ReCaptcha::shouldReceive('htmlScriptTagJsApiV3') |
|
39 | - ->once() |
|
40 | - ->with([]); |
|
41 | - |
|
42 | - htmlScriptTagJsApiV3([]); |
|
43 | - |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * @test |
|
48 | - * @expectedException \TypeError |
|
49 | - */ |
|
50 | - public function testHtmlFormButtonCalledByFacade() |
|
51 | - { |
|
52 | - ReCaptcha::shouldReceive('htmlFormButton') |
|
53 | - ->once() |
|
54 | - ->with("key"); |
|
55 | - |
|
56 | - htmlFormButton("key"); |
|
57 | - |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @test |
|
62 | - */ |
|
63 | - public function testHtmlFormSnippetCalledByFacade() |
|
64 | - { |
|
65 | - ReCaptcha::shouldReceive('htmlFormSnippet') |
|
66 | - ->once(); |
|
67 | - |
|
68 | - htmlFormSnippet(); |
|
69 | - |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Define environment setup. |
|
75 | - * |
|
76 | - * @param \Illuminate\Foundation\Application $app |
|
77 | - * |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - protected function getEnvironmentSetUp($app) |
|
81 | - { |
|
82 | - |
|
83 | - $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
84 | - $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
85 | - $app['config']->set('recaptcha.version', 'v2'); |
|
86 | - } |
|
20 | + /** |
|
21 | + * @test |
|
22 | + */ |
|
23 | + public function testHtmlScriptTagJsApiCalledByFacade() |
|
24 | + { |
|
25 | + ReCaptcha::shouldReceive('htmlScriptTagJsApi') |
|
26 | + ->once() |
|
27 | + ->with("key"); |
|
28 | + |
|
29 | + htmlScriptTagJsApi("key"); |
|
30 | + |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @test |
|
35 | + */ |
|
36 | + public function testHtmlScriptTagJsApiV3CalledByFacade() |
|
37 | + { |
|
38 | + ReCaptcha::shouldReceive('htmlScriptTagJsApiV3') |
|
39 | + ->once() |
|
40 | + ->with([]); |
|
41 | + |
|
42 | + htmlScriptTagJsApiV3([]); |
|
43 | + |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * @test |
|
48 | + * @expectedException \TypeError |
|
49 | + */ |
|
50 | + public function testHtmlFormButtonCalledByFacade() |
|
51 | + { |
|
52 | + ReCaptcha::shouldReceive('htmlFormButton') |
|
53 | + ->once() |
|
54 | + ->with("key"); |
|
55 | + |
|
56 | + htmlFormButton("key"); |
|
57 | + |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @test |
|
62 | + */ |
|
63 | + public function testHtmlFormSnippetCalledByFacade() |
|
64 | + { |
|
65 | + ReCaptcha::shouldReceive('htmlFormSnippet') |
|
66 | + ->once(); |
|
67 | + |
|
68 | + htmlFormSnippet(); |
|
69 | + |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Define environment setup. |
|
75 | + * |
|
76 | + * @param \Illuminate\Foundation\Application $app |
|
77 | + * |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + protected function getEnvironmentSetUp($app) |
|
81 | + { |
|
82 | + |
|
83 | + $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
84 | + $app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
|
85 | + $app['config']->set('recaptcha.version', 'v2'); |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | \ No newline at end of file |
@@ -17,49 +17,49 @@ |
||
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 | - * Define environment setup. |
|
42 | - * |
|
43 | - * @param \Illuminate\Foundation\Application $app |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - protected function getEnvironmentSetUp($app) |
|
48 | - { |
|
40 | + /** |
|
41 | + * Define environment setup. |
|
42 | + * |
|
43 | + * @param \Illuminate\Foundation\Application $app |
|
44 | + * |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + protected function getEnvironmentSetUp($app) |
|
48 | + { |
|
49 | 49 | |
50 | - $app['config']->set('recaptcha.default_language', 'it'); |
|
51 | - } |
|
50 | + $app['config']->set('recaptcha.default_language', 'it'); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Setup the test environment. |
|
55 | - */ |
|
56 | - protected function setUp(): void |
|
57 | - { |
|
53 | + /** |
|
54 | + * Setup the test environment. |
|
55 | + */ |
|
56 | + protected function setUp(): void |
|
57 | + { |
|
58 | 58 | |
59 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
59 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
60 | 60 | |
61 | - $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
62 | - $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
61 | + $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
62 | + $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
63 | 63 | |
64 | - } |
|
64 | + } |
|
65 | 65 | } |
66 | 66 | \ No newline at end of file |
@@ -21,109 +21,109 @@ |
||
21 | 21 | class ReCaptchaServiceProvider extends ServiceProvider |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Indicates if loading of the provider is deferred. |
|
26 | - * |
|
27 | - * @var bool |
|
28 | - */ |
|
29 | - protected $defer = false; |
|
30 | - |
|
31 | - /** |
|
32 | - * |
|
33 | - */ |
|
34 | - public function boot() |
|
35 | - { |
|
36 | - |
|
37 | - $this->addValidationRule(); |
|
24 | + /** |
|
25 | + * Indicates if loading of the provider is deferred. |
|
26 | + * |
|
27 | + * @var bool |
|
28 | + */ |
|
29 | + protected $defer = false; |
|
30 | + |
|
31 | + /** |
|
32 | + * |
|
33 | + */ |
|
34 | + public function boot() |
|
35 | + { |
|
36 | + |
|
37 | + $this->addValidationRule(); |
|
38 | 38 | // $this->loadRoutesFrom(__DIR__ . '/routes/routes.php'); |
39 | - $this->registerRoutes(); |
|
40 | - $this->publishes([ |
|
41 | - __DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
42 | - ]); |
|
43 | - |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Extends Validator to include a recaptcha type |
|
48 | - */ |
|
49 | - public function addValidationRule() |
|
50 | - { |
|
51 | - |
|
52 | - Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) { |
|
53 | - |
|
54 | - return app('recaptcha')->validate($value); |
|
55 | - }, trans('validation.recaptcha')); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Register the service provider. |
|
60 | - * |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function register() |
|
64 | - { |
|
65 | - |
|
66 | - $this->mergeConfigFrom( |
|
67 | - __DIR__ . '/../config/recaptcha.php', 'recaptcha' |
|
68 | - ); |
|
69 | - |
|
70 | - $this->registerReCaptchaBuilder(); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Get the services provided by the provider. |
|
75 | - * |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public function provides(): array |
|
79 | - { |
|
80 | - |
|
81 | - return ['recaptcha']; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @return ReCaptchaServiceProvider |
|
86 | - * |
|
87 | - * @since v3.4.1 |
|
88 | - */ |
|
89 | - protected function registerRoutes(): ReCaptchaServiceProvider |
|
90 | - { |
|
91 | - |
|
92 | - Route::get( |
|
93 | - config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate'), |
|
94 | - ['uses' => 'Biscolab\ReCaptcha\Controllers\ReCaptchaController@validateV3'] |
|
95 | - )->middleware('web'); |
|
96 | - |
|
97 | - return $this; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Register the HTML builder instance. |
|
102 | - * |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - protected function registerReCaptchaBuilder() |
|
106 | - { |
|
107 | - |
|
108 | - $this->app->singleton('recaptcha', function ($app) { |
|
109 | - |
|
110 | - $recaptcha_class = ''; |
|
111 | - |
|
112 | - switch (config('recaptcha.version')) { |
|
113 | - case 'v3' : |
|
114 | - $recaptcha_class = ReCaptchaBuilderV3::class; |
|
115 | - break; |
|
116 | - case 'v2' : |
|
117 | - $recaptcha_class = ReCaptchaBuilderV2::class; |
|
118 | - break; |
|
119 | - case 'invisible': |
|
120 | - $recaptcha_class = ReCaptchaBuilderInvisible::class; |
|
121 | - break; |
|
122 | - } |
|
123 | - |
|
124 | - return new $recaptcha_class(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key')); |
|
125 | - |
|
126 | - }); |
|
127 | - } |
|
39 | + $this->registerRoutes(); |
|
40 | + $this->publishes([ |
|
41 | + __DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
42 | + ]); |
|
43 | + |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Extends Validator to include a recaptcha type |
|
48 | + */ |
|
49 | + public function addValidationRule() |
|
50 | + { |
|
51 | + |
|
52 | + Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) { |
|
53 | + |
|
54 | + return app('recaptcha')->validate($value); |
|
55 | + }, trans('validation.recaptcha')); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Register the service provider. |
|
60 | + * |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function register() |
|
64 | + { |
|
65 | + |
|
66 | + $this->mergeConfigFrom( |
|
67 | + __DIR__ . '/../config/recaptcha.php', 'recaptcha' |
|
68 | + ); |
|
69 | + |
|
70 | + $this->registerReCaptchaBuilder(); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Get the services provided by the provider. |
|
75 | + * |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public function provides(): array |
|
79 | + { |
|
80 | + |
|
81 | + return ['recaptcha']; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @return ReCaptchaServiceProvider |
|
86 | + * |
|
87 | + * @since v3.4.1 |
|
88 | + */ |
|
89 | + protected function registerRoutes(): ReCaptchaServiceProvider |
|
90 | + { |
|
91 | + |
|
92 | + Route::get( |
|
93 | + config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate'), |
|
94 | + ['uses' => 'Biscolab\ReCaptcha\Controllers\ReCaptchaController@validateV3'] |
|
95 | + )->middleware('web'); |
|
96 | + |
|
97 | + return $this; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Register the HTML builder instance. |
|
102 | + * |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + protected function registerReCaptchaBuilder() |
|
106 | + { |
|
107 | + |
|
108 | + $this->app->singleton('recaptcha', function ($app) { |
|
109 | + |
|
110 | + $recaptcha_class = ''; |
|
111 | + |
|
112 | + switch (config('recaptcha.version')) { |
|
113 | + case 'v3' : |
|
114 | + $recaptcha_class = ReCaptchaBuilderV3::class; |
|
115 | + break; |
|
116 | + case 'v2' : |
|
117 | + $recaptcha_class = ReCaptchaBuilderV2::class; |
|
118 | + break; |
|
119 | + case 'invisible': |
|
120 | + $recaptcha_class = ReCaptchaBuilderInvisible::class; |
|
121 | + break; |
|
122 | + } |
|
123 | + |
|
124 | + return new $recaptcha_class(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key')); |
|
125 | + |
|
126 | + }); |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
@@ -17,16 +17,16 @@ |
||
17 | 17 | class ReCaptchaBuilderV3 extends ReCaptchaBuilder |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * ReCaptchaBuilderV3 constructor. |
|
22 | - * |
|
23 | - * @param string $api_site_key |
|
24 | - * @param string $api_secret_key |
|
25 | - */ |
|
26 | - public function __construct(string $api_site_key, string $api_secret_key) |
|
27 | - { |
|
20 | + /** |
|
21 | + * ReCaptchaBuilderV3 constructor. |
|
22 | + * |
|
23 | + * @param string $api_site_key |
|
24 | + * @param string $api_secret_key |
|
25 | + */ |
|
26 | + public function __construct(string $api_site_key, string $api_secret_key) |
|
27 | + { |
|
28 | 28 | |
29 | - parent::__construct($api_site_key, $api_secret_key, 'v3'); |
|
30 | - } |
|
29 | + parent::__construct($api_site_key, $api_secret_key, 'v3'); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | } |
33 | 33 | \ No newline at end of file |