@@ -22,40 +22,40 @@  | 
                                                    ||
| 22 | 22 | */  | 
                                                        
| 23 | 23 |  class ReCaptchaConfigurationTest extends TestCase { | 
                                                        
| 24 | 24 | |
| 25 | - /**  | 
                                                        |
| 26 | - * @var ReCaptchaBuilder  | 
                                                        |
| 27 | - */  | 
                                                        |
| 28 | - protected $recaptcha;  | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | - /**  | 
                                                        |
| 31 | - * @test  | 
                                                        |
| 32 | - */  | 
                                                        |
| 33 | -	public function testSkipIpWhiteListIsArray() { | 
                                                        |
| 34 | -  | 
                                                        |
| 35 | - $ip_whitelist = $this->recaptcha->getIpWhitelist();  | 
                                                        |
| 36 | - $this->assertTrue(is_array($ip_whitelist));  | 
                                                        |
| 37 | - $this->assertCount(2, $ip_whitelist);  | 
                                                        |
| 38 | - }  | 
                                                        |
| 39 | -  | 
                                                        |
| 40 | - /**  | 
                                                        |
| 41 | - * Define environment setup.  | 
                                                        |
| 42 | - *  | 
                                                        |
| 43 | - * @param \Illuminate\Foundation\Application $app  | 
                                                        |
| 44 | - *  | 
                                                        |
| 45 | - * @return void  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | -	protected function getEnvironmentSetUp($app) { | 
                                                        |
| 48 | -  | 
                                                        |
| 49 | -		$app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2'); | 
                                                        |
| 50 | - }  | 
                                                        |
| 51 | -  | 
                                                        |
| 52 | - /**  | 
                                                        |
| 53 | - * Setup the test environment.  | 
                                                        |
| 54 | - */  | 
                                                        |
| 55 | -	protected function setUp(): void { | 
                                                        |
| 56 | -  | 
                                                        |
| 57 | - parent::setUp(); // TODO: Change the autogenerated stub  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | -		$this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); | 
                                                        |
| 60 | - }  | 
                                                        |
| 25 | + /**  | 
                                                        |
| 26 | + * @var ReCaptchaBuilder  | 
                                                        |
| 27 | + */  | 
                                                        |
| 28 | + protected $recaptcha;  | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | + /**  | 
                                                        |
| 31 | + * @test  | 
                                                        |
| 32 | + */  | 
                                                        |
| 33 | +    public function testSkipIpWhiteListIsArray() { | 
                                                        |
| 34 | +  | 
                                                        |
| 35 | + $ip_whitelist = $this->recaptcha->getIpWhitelist();  | 
                                                        |
| 36 | + $this->assertTrue(is_array($ip_whitelist));  | 
                                                        |
| 37 | + $this->assertCount(2, $ip_whitelist);  | 
                                                        |
| 38 | + }  | 
                                                        |
| 39 | +  | 
                                                        |
| 40 | + /**  | 
                                                        |
| 41 | + * Define environment setup.  | 
                                                        |
| 42 | + *  | 
                                                        |
| 43 | + * @param \Illuminate\Foundation\Application $app  | 
                                                        |
| 44 | + *  | 
                                                        |
| 45 | + * @return void  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | +    protected function getEnvironmentSetUp($app) { | 
                                                        |
| 48 | +  | 
                                                        |
| 49 | +        $app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2'); | 
                                                        |
| 50 | + }  | 
                                                        |
| 51 | +  | 
                                                        |
| 52 | + /**  | 
                                                        |
| 53 | + * Setup the test environment.  | 
                                                        |
| 54 | + */  | 
                                                        |
| 55 | +    protected function setUp(): void { | 
                                                        |
| 56 | +  | 
                                                        |
| 57 | + parent::setUp(); // TODO: Change the autogenerated stub  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | +        $this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); | 
                                                        |
| 60 | + }  | 
                                                        |
| 61 | 61 | }  | 
                                                        
| 62 | 62 | \ No newline at end of file  | 
                                                        
@@ -20,93 +20,93 @@  | 
                                                    ||
| 20 | 20 | */  | 
                                                        
| 21 | 21 |  class ReCaptchaV3Test extends TestCase { | 
                                                        
| 22 | 22 | |
| 23 | - protected $recaptcha_v3 = null;  | 
                                                        |
| 24 | -  | 
                                                        |
| 25 | - /**  | 
                                                        |
| 26 | - * @test  | 
                                                        |
| 27 | - */  | 
                                                        |
| 28 | -	public function testGetApiVersion() { | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | - $this->assertEquals($this->recaptcha_v3->getVersion(), 'v3');  | 
                                                        |
| 31 | - }  | 
                                                        |
| 32 | -  | 
                                                        |
| 33 | - /**  | 
                                                        |
| 34 | - * @test  | 
                                                        |
| 35 | - */  | 
                                                        |
| 36 | -	public function testHtmlScriptTagJsApiV3GetHtmlScriptTag() { | 
                                                        |
| 37 | -  | 
                                                        |
| 38 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3();  | 
                                                        |
| 39 | -		$this->assertRegexp('/csrfToken/', $r); | 
                                                        |
| 40 | - }  | 
                                                        |
| 41 | -  | 
                                                        |
| 42 | - /**  | 
                                                        |
| 43 | - * @test  | 
                                                        |
| 44 | - */  | 
                                                        |
| 45 | -	public function testAction() { | 
                                                        |
| 46 | -  | 
                                                        |
| 47 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['action' => 'someAction']);  | 
                                                        |
| 48 | -		$this->assertRegexp('/someAction/', $r); | 
                                                        |
| 49 | - }  | 
                                                        |
| 50 | -  | 
                                                        |
| 51 | - /**  | 
                                                        |
| 52 | - * @test  | 
                                                        |
| 53 | - */  | 
                                                        |
| 54 | -	public function testFetchCallbackFunction() { | 
                                                        |
| 55 | -  | 
                                                        |
| 56 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_then' => 'functionCallbackThen']);  | 
                                                        |
| 57 | -		$this->assertRegexp('/functionCallbackThen\(response\)/', $r); | 
                                                        |
| 58 | - }  | 
                                                        |
| 59 | -  | 
                                                        |
| 60 | - /**  | 
                                                        |
| 61 | - * @test  | 
                                                        |
| 62 | - */  | 
                                                        |
| 63 | -	public function testcCatchCallbackFunction() { | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_catch' => 'functionCallbackCatch']);  | 
                                                        |
| 66 | -		$this->assertRegexp('/functionCallbackCatch\(err\)/', $r); | 
                                                        |
| 67 | - }  | 
                                                        |
| 68 | -  | 
                                                        |
| 69 | - /**  | 
                                                        |
| 70 | - * @test  | 
                                                        |
| 71 | - */  | 
                                                        |
| 72 | -	public function testCustomValidationFunction() { | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['custom_validation' => 'functionCustomValidation']);  | 
                                                        |
| 75 | -		$this->assertRegexp('/functionCustomValidation\(token\)/', $r); | 
                                                        |
| 76 | - }  | 
                                                        |
| 77 | -  | 
                                                        |
| 78 | - /**  | 
                                                        |
| 79 | - * @test  | 
                                                        |
| 80 | - */  | 
                                                        |
| 81 | -	public function testValidateController() { | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | - $controller = App::make(ReCaptchaController::class);  | 
                                                        |
| 84 | - $return = $controller->validateV3();  | 
                                                        |
| 85 | -  | 
                                                        |
| 86 | -		$this->assertArrayHasKey("success", $return); | 
                                                        |
| 87 | -		$this->assertArrayHasKey("error-codes", $return); | 
                                                        |
| 88 | - }  | 
                                                        |
| 89 | -  | 
                                                        |
| 90 | - /**  | 
                                                        |
| 91 | - * Define environment setup.  | 
                                                        |
| 92 | - *  | 
                                                        |
| 93 | - * @param \Illuminate\Foundation\Application $app  | 
                                                        |
| 94 | - *  | 
                                                        |
| 95 | - * @return void  | 
                                                        |
| 96 | - */  | 
                                                        |
| 97 | -	protected function getEnvironmentSetUp($app) { | 
                                                        |
| 98 | -  | 
                                                        |
| 99 | -		$app['config']->set('recaptcha.version', 'v3'); | 
                                                        |
| 100 | - }  | 
                                                        |
| 101 | -  | 
                                                        |
| 102 | - /**  | 
                                                        |
| 103 | - * Setup the test environment.  | 
                                                        |
| 104 | - */  | 
                                                        |
| 105 | -	protected function setUp(): void { | 
                                                        |
| 106 | -  | 
                                                        |
| 107 | - parent::setUp(); // TODO: Change the autogenerated stub  | 
                                                        |
| 108 | -  | 
                                                        |
| 109 | -		$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); | 
                                                        |
| 110 | -  | 
                                                        |
| 111 | - }  | 
                                                        |
| 23 | + protected $recaptcha_v3 = null;  | 
                                                        |
| 24 | +  | 
                                                        |
| 25 | + /**  | 
                                                        |
| 26 | + * @test  | 
                                                        |
| 27 | + */  | 
                                                        |
| 28 | +    public function testGetApiVersion() { | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | + $this->assertEquals($this->recaptcha_v3->getVersion(), 'v3');  | 
                                                        |
| 31 | + }  | 
                                                        |
| 32 | +  | 
                                                        |
| 33 | + /**  | 
                                                        |
| 34 | + * @test  | 
                                                        |
| 35 | + */  | 
                                                        |
| 36 | +    public function testHtmlScriptTagJsApiV3GetHtmlScriptTag() { | 
                                                        |
| 37 | +  | 
                                                        |
| 38 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3();  | 
                                                        |
| 39 | +        $this->assertRegexp('/csrfToken/', $r); | 
                                                        |
| 40 | + }  | 
                                                        |
| 41 | +  | 
                                                        |
| 42 | + /**  | 
                                                        |
| 43 | + * @test  | 
                                                        |
| 44 | + */  | 
                                                        |
| 45 | +    public function testAction() { | 
                                                        |
| 46 | +  | 
                                                        |
| 47 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['action' => 'someAction']);  | 
                                                        |
| 48 | +        $this->assertRegexp('/someAction/', $r); | 
                                                        |
| 49 | + }  | 
                                                        |
| 50 | +  | 
                                                        |
| 51 | + /**  | 
                                                        |
| 52 | + * @test  | 
                                                        |
| 53 | + */  | 
                                                        |
| 54 | +    public function testFetchCallbackFunction() { | 
                                                        |
| 55 | +  | 
                                                        |
| 56 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_then' => 'functionCallbackThen']);  | 
                                                        |
| 57 | +        $this->assertRegexp('/functionCallbackThen\(response\)/', $r); | 
                                                        |
| 58 | + }  | 
                                                        |
| 59 | +  | 
                                                        |
| 60 | + /**  | 
                                                        |
| 61 | + * @test  | 
                                                        |
| 62 | + */  | 
                                                        |
| 63 | +    public function testcCatchCallbackFunction() { | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_catch' => 'functionCallbackCatch']);  | 
                                                        |
| 66 | +        $this->assertRegexp('/functionCallbackCatch\(err\)/', $r); | 
                                                        |
| 67 | + }  | 
                                                        |
| 68 | +  | 
                                                        |
| 69 | + /**  | 
                                                        |
| 70 | + * @test  | 
                                                        |
| 71 | + */  | 
                                                        |
| 72 | +    public function testCustomValidationFunction() { | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['custom_validation' => 'functionCustomValidation']);  | 
                                                        |
| 75 | +        $this->assertRegexp('/functionCustomValidation\(token\)/', $r); | 
                                                        |
| 76 | + }  | 
                                                        |
| 77 | +  | 
                                                        |
| 78 | + /**  | 
                                                        |
| 79 | + * @test  | 
                                                        |
| 80 | + */  | 
                                                        |
| 81 | +    public function testValidateController() { | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | + $controller = App::make(ReCaptchaController::class);  | 
                                                        |
| 84 | + $return = $controller->validateV3();  | 
                                                        |
| 85 | +  | 
                                                        |
| 86 | +        $this->assertArrayHasKey("success", $return); | 
                                                        |
| 87 | +        $this->assertArrayHasKey("error-codes", $return); | 
                                                        |
| 88 | + }  | 
                                                        |
| 89 | +  | 
                                                        |
| 90 | + /**  | 
                                                        |
| 91 | + * Define environment setup.  | 
                                                        |
| 92 | + *  | 
                                                        |
| 93 | + * @param \Illuminate\Foundation\Application $app  | 
                                                        |
| 94 | + *  | 
                                                        |
| 95 | + * @return void  | 
                                                        |
| 96 | + */  | 
                                                        |
| 97 | +    protected function getEnvironmentSetUp($app) { | 
                                                        |
| 98 | +  | 
                                                        |
| 99 | +        $app['config']->set('recaptcha.version', 'v3'); | 
                                                        |
| 100 | + }  | 
                                                        |
| 101 | +  | 
                                                        |
| 102 | + /**  | 
                                                        |
| 103 | + * Setup the test environment.  | 
                                                        |
| 104 | + */  | 
                                                        |
| 105 | +    protected function setUp(): void { | 
                                                        |
| 106 | +  | 
                                                        |
| 107 | + parent::setUp(); // TODO: Change the autogenerated stub  | 
                                                        |
| 108 | +  | 
                                                        |
| 109 | +        $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key'); | 
                                                        |
| 110 | +  | 
                                                        |
| 111 | + }  | 
                                                        |
| 112 | 112 | }  | 
                                                        
| 113 | 113 | \ No newline at end of file  | 
                                                        
@@ -20,73 +20,73 @@  | 
                                                    ||
| 20 | 20 | */  | 
                                                        
| 21 | 21 |  class ReCaptchaTest extends TestCase { | 
                                                        
| 22 | 22 | |
| 23 | - protected $recaptcha_invisible = null;  | 
                                                        |
| 23 | + protected $recaptcha_invisible = null;  | 
                                                        |
| 24 | 24 | |
| 25 | - protected $recaptcha_v2 = null;  | 
                                                        |
| 25 | + protected $recaptcha_v2 = null;  | 
                                                        |
| 26 | 26 | |
| 27 | - /**  | 
                                                        |
| 28 | - * @tests  | 
                                                        |
| 29 | - */  | 
                                                        |
| 30 | -	public function testHtmlScriptTagJsApiGetHtmlScriptTag() { | 
                                                        |
| 27 | + /**  | 
                                                        |
| 28 | + * @tests  | 
                                                        |
| 29 | + */  | 
                                                        |
| 30 | +    public function testHtmlScriptTagJsApiGetHtmlScriptTag() { | 
                                                        |
| 31 | 31 | |
| 32 | - $r = ReCaptcha::htmlScriptTagJsApi();  | 
                                                        |
| 33 | -		$this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r); | 
                                                        |
| 34 | - }  | 
                                                        |
| 32 | + $r = ReCaptcha::htmlScriptTagJsApi();  | 
                                                        |
| 33 | +        $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r); | 
                                                        |
| 34 | + }  | 
                                                        |
| 35 | 35 | |
| 36 | - /**  | 
                                                        |
| 37 | - * @test  | 
                                                        |
| 38 | - */  | 
                                                        |
| 39 | -	public function testReCaptchaInvisibleHtmlFormButtonDefault() { | 
                                                        |
| 36 | + /**  | 
                                                        |
| 37 | + * @test  | 
                                                        |
| 38 | + */  | 
                                                        |
| 39 | +    public function testReCaptchaInvisibleHtmlFormButtonDefault() { | 
                                                        |
| 40 | 40 | |
| 41 | - $recaptcha = $this->recaptcha_invisible;  | 
                                                        |
| 42 | - $html_button = $recaptcha->htmlFormButton();  | 
                                                        |
| 43 | -		$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>', $html_button); | 
                                                        |
| 44 | - }  | 
                                                        |
| 41 | + $recaptcha = $this->recaptcha_invisible;  | 
                                                        |
| 42 | + $html_button = $recaptcha->htmlFormButton();  | 
                                                        |
| 43 | +        $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>', $html_button); | 
                                                        |
| 44 | + }  | 
                                                        |
| 45 | 45 | |
| 46 | - /**  | 
                                                        |
| 47 | - * @test  | 
                                                        |
| 48 | - */  | 
                                                        |
| 49 | -	public function testReCaptchaInvisibleHtmlFormButtonCustom() { | 
                                                        |
| 46 | + /**  | 
                                                        |
| 47 | + * @test  | 
                                                        |
| 48 | + */  | 
                                                        |
| 49 | +    public function testReCaptchaInvisibleHtmlFormButtonCustom() { | 
                                                        |
| 50 | 50 | |
| 51 | - $recaptcha = $this->recaptcha_invisible;  | 
                                                        |
| 52 | -		$html_button = $recaptcha->htmlFormButton('Custom Text'); | 
                                                        |
| 53 | -		$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>', $html_button); | 
                                                        |
| 54 | - }  | 
                                                        |
| 51 | + $recaptcha = $this->recaptcha_invisible;  | 
                                                        |
| 52 | +        $html_button = $recaptcha->htmlFormButton('Custom Text'); | 
                                                        |
| 53 | +        $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>', $html_button); | 
                                                        |
| 54 | + }  | 
                                                        |
| 55 | 55 | |
| 56 | - /**  | 
                                                        |
| 57 | - * @test  | 
                                                        |
| 58 | - */  | 
                                                        |
| 59 | -	public function testReCaptchaV2HtmlFormSnippet() { | 
                                                        |
| 56 | + /**  | 
                                                        |
| 57 | + * @test  | 
                                                        |
| 58 | + */  | 
                                                        |
| 59 | +    public function testReCaptchaV2HtmlFormSnippet() { | 
                                                        |
| 60 | 60 | |
| 61 | - $recaptcha = $this->recaptcha_v2;  | 
                                                        |
| 62 | - $html_snippet = $recaptcha->htmlFormSnippet();  | 
                                                        |
| 63 | -		$this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet); | 
                                                        |
| 64 | - }  | 
                                                        |
| 61 | + $recaptcha = $this->recaptcha_v2;  | 
                                                        |
| 62 | + $html_snippet = $recaptcha->htmlFormSnippet();  | 
                                                        |
| 63 | +        $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet); | 
                                                        |
| 64 | + }  | 
                                                        |
| 65 | 65 | |
| 66 | - /**  | 
                                                        |
| 67 | - * @test  | 
                                                        |
| 68 | - * @expectedException \Error  | 
                                                        |
| 69 | - */  | 
                                                        |
| 70 | -	public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() { | 
                                                        |
| 66 | + /**  | 
                                                        |
| 67 | + * @test  | 
                                                        |
| 68 | + * @expectedException \Error  | 
                                                        |
| 69 | + */  | 
                                                        |
| 70 | +    public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() { | 
                                                        |
| 71 | 71 | |
| 72 | - $this->recaptcha_invisible->htmlFormSnippet();  | 
                                                        |
| 73 | - }  | 
                                                        |
| 72 | + $this->recaptcha_invisible->htmlFormSnippet();  | 
                                                        |
| 73 | + }  | 
                                                        |
| 74 | 74 | |
| 75 | - /**  | 
                                                        |
| 76 | - * @test  | 
                                                        |
| 77 | - * @expectedException \Error  | 
                                                        |
| 78 | - */  | 
                                                        |
| 79 | -	public function testReCaptchaV2htmlFormButtonShouldThrowError() { | 
                                                        |
| 75 | + /**  | 
                                                        |
| 76 | + * @test  | 
                                                        |
| 77 | + * @expectedException \Error  | 
                                                        |
| 78 | + */  | 
                                                        |
| 79 | +    public function testReCaptchaV2htmlFormButtonShouldThrowError() { | 
                                                        |
| 80 | 80 | |
| 81 | - $this->recaptcha_v2->htmlFormButton();  | 
                                                        |
| 82 | - }  | 
                                                        |
| 81 | + $this->recaptcha_v2->htmlFormButton();  | 
                                                        |
| 82 | + }  | 
                                                        |
| 83 | 83 | |
| 84 | -	protected function setUp(): void { | 
                                                        |
| 84 | +    protected function setUp(): void { | 
                                                        |
| 85 | 85 | |
| 86 | - parent::setUp(); // TODO: Change the autogenerated stub  | 
                                                        |
| 86 | + parent::setUp(); // TODO: Change the autogenerated stub  | 
                                                        |
| 87 | 87 | |
| 88 | -		$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); | 
                                                        |
| 89 | -		$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); | 
                                                        |
| 88 | +        $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key'); | 
                                                        |
| 89 | +        $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key'); | 
                                                        |
| 90 | 90 | |
| 91 | - }  | 
                                                        |
| 91 | + }  | 
                                                        |
| 92 | 92 | }  | 
                                                        
| 93 | 93 | \ No newline at end of file  |