@@ -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 |
@@ -23,173 +23,173 @@ |
||
| 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-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">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-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">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" data-theme="light" data-size="normal" id="recaptcha-element"></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 | - */ |
|
| 141 | - public function testDefaultCurlTimeout() |
|
| 142 | - { |
|
| 143 | - |
|
| 144 | - $this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
| 145 | - $this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
| 146 | - $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @test |
|
| 151 | - * @expectedException \Error |
|
| 152 | - */ |
|
| 153 | - public function testReCaptchaV2htmlFormButtonShouldThrowError() |
|
| 154 | - { |
|
| 155 | - |
|
| 156 | - $this->recaptcha_v2->htmlFormButton(); |
|
| 157 | - } |
|
| 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 | + } |
|
| 158 | 50 | |
| 159 | 51 | /** |
| 160 | 52 | * @test |
| 161 | 53 | */ |
| 162 | - public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName() { |
|
| 54 | + public function testReCaptchaInvisibleHtmlFormButtonDefault() |
|
| 55 | + { |
|
| 56 | + |
|
| 57 | + $recaptcha = $this->recaptcha_invisible; |
|
| 58 | + $html_button = $recaptcha->htmlFormButton(); |
|
| 59 | + $this->assertEquals('<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">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-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">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" data-theme="light" data-size="normal" id="recaptcha-element"></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 | + */ |
|
| 141 | + public function testDefaultCurlTimeout() |
|
| 142 | + { |
|
| 143 | + |
|
| 144 | + $this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
| 145 | + $this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
| 146 | + $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @test |
|
| 151 | + * @expectedException \Error |
|
| 152 | + */ |
|
| 153 | + public function testReCaptchaV2htmlFormButtonShouldThrowError() |
|
| 154 | + { |
|
| 155 | + |
|
| 156 | + $this->recaptcha_v2->htmlFormButton(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @test |
|
| 161 | + */ |
|
| 162 | + public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName() { |
|
| 163 | 163 | $this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME, recaptchaFieldName()); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | * @test |
| 168 | 168 | */ |
| 169 | - public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName() { |
|
| 169 | + public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName() { |
|
| 170 | 170 | $this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME, recaptchaRuleName()); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value) |
|
| 174 | - { |
|
| 173 | + protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value) |
|
| 174 | + { |
|
| 175 | 175 | |
| 176 | - $reflection = new \ReflectionClass($builder); |
|
| 177 | - $reflection_property = $reflection->getProperty('skip_by_ip'); |
|
| 178 | - $reflection_property->setAccessible(true); |
|
| 179 | - $reflection_property->setValue($builder, $value); |
|
| 180 | - } |
|
| 176 | + $reflection = new \ReflectionClass($builder); |
|
| 177 | + $reflection_property = $reflection->getProperty('skip_by_ip'); |
|
| 178 | + $reflection_property->setAccessible(true); |
|
| 179 | + $reflection_property->setValue($builder, $value); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * @inheritdoc |
|
| 184 | - */ |
|
| 185 | - protected function setUp(): void |
|
| 186 | - { |
|
| 182 | + /** |
|
| 183 | + * @inheritdoc |
|
| 184 | + */ |
|
| 185 | + protected function setUp(): void |
|
| 186 | + { |
|
| 187 | 187 | |
| 188 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
| 188 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
| 189 | 189 | |
| 190 | - $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
| 191 | - $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
| 192 | - $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); |
|
| 190 | + $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); |
|
| 191 | + $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); |
|
| 192 | + $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); |
|
| 193 | 193 | |
| 194 | - } |
|
| 194 | + } |
|
| 195 | 195 | } |
| 196 | 196 | \ 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 |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $whitelist = explode(',', $whitelist); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - $whitelist = array_map(function ($item) { |
|
| 180 | + $whitelist = array_map(function($item) { |
|
| 181 | 181 | |
| 182 | 182 | return trim($item); |
| 183 | 183 | }, $whitelist); |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // Create query string |
| 234 | - $query = ($query) ? '?' . http_build_query($query) : ""; |
|
| 235 | - $html .= "<script src=\"https://www.google.com/recaptcha/api.js" . $query . "\" async defer></script>"; |
|
| 234 | + $query = ($query) ? '?'.http_build_query($query) : ""; |
|
| 235 | + $html .= "<script src=\"https://www.google.com/recaptcha/api.js".$query."\" async defer></script>"; |
|
| 236 | 236 | |
| 237 | 237 | return $html; |
| 238 | 238 | } |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | 'response' => $response, |
| 267 | 267 | ]); |
| 268 | 268 | |
| 269 | - $url = $this->api_url . '?' . $params; |
|
| 269 | + $url = $this->api_url.'?'.$params; |
|
| 270 | 270 | |
| 271 | 271 | if (function_exists('curl_version')) { |
| 272 | 272 | |
@@ -45,11 +45,11 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | foreach ($config_data_attributes as $k => $v) { |
| 47 | 47 | if ($v) { |
| 48 | - $data_attributes[] = 'data-' . $k . '="' . $v . '"'; |
|
| 48 | + $data_attributes[] = 'data-'.$k.'="'.$v.'"'; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - $html = '<div class="g-recaptcha" ' . implode(" ", $data_attributes) . ' id="recaptcha-element"></div>'; |
|
| 52 | + $html = '<div class="g-recaptcha" '.implode(" ", $data_attributes).' id="recaptcha-element"></div>'; |
|
| 53 | 53 | |
| 54 | 54 | return $html; |
| 55 | 55 | } |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | $tag_attributes = array_merge($tag_attributes, config('recaptcha.tag_attributes', [])); |
| 69 | 69 | |
| 70 | 70 | if (Arr::get($tag_attributes, 'callback') === ReCaptchaBuilder::DEFAULT_ONLOAD_JS_FUNCTION) { |
| 71 | - throw new InvalidConfigurationException('Property "callback" ("data-callback") must be different from "' . ReCaptchaBuilder::DEFAULT_ONLOAD_JS_FUNCTION . '"'); |
|
| 71 | + throw new InvalidConfigurationException('Property "callback" ("data-callback") must be different from "'.ReCaptchaBuilder::DEFAULT_ONLOAD_JS_FUNCTION.'"'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | if (Arr::get($tag_attributes, 'expired-callback') === ReCaptchaBuilder::DEFAULT_ONLOAD_JS_FUNCTION) { |
| 75 | - throw new InvalidConfigurationException('Property "expired-callback" ("data-expired-callback") must be different from "' . ReCaptchaBuilder::DEFAULT_ONLOAD_JS_FUNCTION . '"'); |
|
| 75 | + throw new InvalidConfigurationException('Property "expired-callback" ("data-expired-callback") must be different from "'.ReCaptchaBuilder::DEFAULT_ONLOAD_JS_FUNCTION.'"'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | if (Arr::get($tag_attributes, 'error-callback') === ReCaptchaBuilder::DEFAULT_ONLOAD_JS_FUNCTION) { |
| 79 | - throw new InvalidConfigurationException('Property "error-callback" ("data-error-callback") must be different from "' . ReCaptchaBuilder::DEFAULT_ONLOAD_JS_FUNCTION . '"'); |
|
| 79 | + throw new InvalidConfigurationException('Property "error-callback" ("data-error-callback") must be different from "'.ReCaptchaBuilder::DEFAULT_ONLOAD_JS_FUNCTION.'"'); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return $tag_attributes; |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | $attributes = $this->getTagAttributes(); |
| 92 | 92 | |
| 93 | - return "<script>var biscolabOnloadCallback = function() {grecaptcha.render('recaptcha-element', " . json_encode($attributes) . ");};</script>"; |
|
| 93 | + return "<script>var biscolabOnloadCallback = function() {grecaptcha.render('recaptcha-element', ".json_encode($attributes).");};</script>"; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | \ 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 | /** |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $this->addValidationRule(); |
| 38 | 38 | $this->registerRoutes(); |
| 39 | 39 | $this->publishes([ |
| 40 | - __DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
| 40 | + __DIR__.'/../config/recaptcha.php' => config_path('recaptcha.php'), |
|
| 41 | 41 | ], 'config'); |
| 42 | 42 | |
| 43 | 43 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | public function addValidationRule() |
| 49 | 49 | { |
| 50 | 50 | |
| 51 | - Validator::extendImplicit(recaptchaRuleName(), function ($attribute, $value) { |
|
| 51 | + Validator::extendImplicit(recaptchaRuleName(), function($attribute, $value) { |
|
| 52 | 52 | |
| 53 | 53 | return app('recaptcha')->validate($value); |
| 54 | 54 | }, trans('validation.recaptcha')); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | { |
| 64 | 64 | |
| 65 | 65 | $this->mergeConfigFrom( |
| 66 | - __DIR__ . '/../config/recaptcha.php', 'recaptcha' |
|
| 66 | + __DIR__.'/../config/recaptcha.php', 'recaptcha' |
|
| 67 | 67 | ); |
| 68 | 68 | |
| 69 | 69 | $this->registerReCaptchaBuilder(); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | protected function registerReCaptchaBuilder() |
| 105 | 105 | { |
| 106 | 106 | |
| 107 | - $this->app->singleton('recaptcha', function ($app) { |
|
| 107 | + $this->app->singleton('recaptcha', function($app) { |
|
| 108 | 108 | |
| 109 | 109 | $recaptcha_class = ''; |
| 110 | 110 | |
@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | // http_build_query($properties, null, '" ', PHP_QUERY_RFC3986)) . '"'; |
| 70 | 70 | $temp_properties = []; |
| 71 | 71 | foreach ($properties as $k => $v) { |
| 72 | - $temp_properties[] = $k . '="' . $v . '"'; |
|
| 72 | + $temp_properties[] = $k.'="'.$v.'"'; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $tag_properties = implode(" ", $temp_properties); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - return ($this->version == 'invisible') ? '<button ' . $tag_properties . '>' . $button_label . '</button>' : ''; |
|
| 78 | + return ($this->version == 'invisible') ? '<button '.$tag_properties.'>'.$button_label.'</button>' : ''; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | $html .= '<script> |
| 102 | 102 | function biscolabLaravelReCaptcha(token) { |
| 103 | - document.getElementById("' . $form_id . '").submit(); |
|
| 103 | + document.getElementById("' . $form_id.'").submit(); |
|
| 104 | 104 | } |
| 105 | 105 | </script>'; |
| 106 | 106 | |
@@ -66,8 +66,8 @@ |
||
| 66 | 66 | |
| 67 | 67 | $validate_function = " |
| 68 | 68 | fetch('/" . config('recaptcha.default_validation_route', |
| 69 | - 'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name', |
|
| 70 | - 'token') . "=' + token, { |
|
| 69 | + 'biscolab-recaptcha/validate')."?".config('recaptcha.default_token_parameter_name', |
|
| 70 | + 'token')."=' + token, { |
|
| 71 | 71 | headers: { |
| 72 | 72 | \"X-Requested-With\": \"XMLHttpRequest\", |
| 73 | 73 | \"X-CSRF-TOKEN\": csrfToken.content |