Skip to content

Commit

Permalink
Merge branch 'release/v3'
Browse files Browse the repository at this point in the history
* release/v3:
  recaptcha_v3 default timeout test created
  curl_timeout tests
  setCurlTimeout method default value
  default curl_timeout in ReCaptchaBuilderInvisible and ReCaptchaBuilderV2 class constructor
  • Loading branch information
biscolab committed Jul 22, 2019
2 parents 2636b05 + 18e2c0e commit 7b9b822
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 22 deletions.
7 changes: 5 additions & 2 deletions src/ReCaptchaBuilder.php
Expand Up @@ -115,12 +115,15 @@ public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
}

/**
* @param int $curl_timeout
* @param int|null $curl_timeout
*
* @return ReCaptchaBuilder
*/
public function setCurlTimeout(int $curl_timeout): ReCaptchaBuilder {
public function setCurlTimeout(?int $curl_timeout = null): ReCaptchaBuilder {

if($curl_timeout === null) {
$curl_timeout = config('recaptcha.curl_timeout', ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
}
$this->curl_timeout = $curl_timeout;

return $this;
Expand Down
8 changes: 4 additions & 4 deletions src/ReCaptchaBuilderInvisible.php
Expand Up @@ -19,11 +19,11 @@ class ReCaptchaBuilderInvisible extends ReCaptchaBuilder {
/**
* ReCaptchaBuilderInvisible constructor.
*
* @param string $api_site_key
* @param string $api_secret_key
* @param int $curl_timeout
* @param string $api_site_key
* @param string $api_secret_key
* @param int|null $curl_timeout
*/
public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) {
public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {

parent::__construct($api_site_key, $api_secret_key, 'invisible', $curl_timeout);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ReCaptchaBuilderV2.php
Expand Up @@ -19,11 +19,11 @@ class ReCaptchaBuilderV2 extends ReCaptchaBuilder {
/**
* ReCaptchaBuilderV2 constructor.
*
* @param string $api_site_key
* @param string $api_secret_key
* @param int $curl_timeout
* @param string $api_site_key
* @param string $api_secret_key
* @param int|null $curl_timeout
*/
public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) {
public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {

parent::__construct($api_site_key, $api_secret_key, 'v2', $curl_timeout);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ReCaptchaBuilderV3.php
Expand Up @@ -19,11 +19,11 @@ class ReCaptchaBuilderV3 extends ReCaptchaBuilder {
/**
* ReCaptchaBuilderV3 constructor.
*
* @param string $api_site_key
* @param string $api_secret_key
* @param int $curl_timeout
* @param string $api_site_key
* @param string $api_secret_key
* @param int|null $curl_timeout
*/
public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) {
public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {

parent::__construct($api_site_key, $api_secret_key, 'v3', $curl_timeout);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/ReCaptchaConfigurationTest.php
Expand Up @@ -41,7 +41,7 @@ public function testSkipIpWhiteListIsArray() {
* @test
*/
public function testCurlTimeoutIsSet() {
$this->assertEquals($this->recaptcha->getCurlTimeout(), 3);
$this->assertEquals(3, $this->recaptcha->getCurlTimeout());
}

/**
Expand All @@ -54,6 +54,7 @@ public function testCurlTimeoutIsSet() {
protected function getEnvironmentSetUp($app) {

$app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2');
$app['config']->set('recaptcha.curl_timeout', 3);
}

/**
Expand All @@ -63,6 +64,6 @@ protected function setUp(): void {

parent::setUp(); // TODO: Change the autogenerated stub

$this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key', 3);
$this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
}
}
36 changes: 31 additions & 5 deletions tests/ReCaptchaTest.php
Expand Up @@ -11,18 +11,31 @@
namespace Biscolab\ReCaptcha\Tests;

use Biscolab\ReCaptcha\Facades\ReCaptcha;
use Biscolab\ReCaptcha\ReCaptchaBuilder;
use Biscolab\ReCaptcha\ReCaptchaBuilderInvisible;
use Biscolab\ReCaptcha\ReCaptchaBuilderV2;
use Biscolab\ReCaptcha\ReCaptchaBuilderV3;

/**
* Class ReCaptchaTest
* @package Biscolab\ReCaptcha\Tests
*/
class ReCaptchaTest extends TestCase {

/**
* @var ReCaptchaBuilderInvisible
*/
protected $recaptcha_invisible = null;

protected $recaptcha_v2 = null;
/**
* @var ReCaptchaBuilderV2
*/
protected $recaptcha_v2 = null;

/**
* @var ReCaptchaBuilderV3
*/
protected $recaptcha_v3 = null;

/**
* @tests
Expand All @@ -40,7 +53,8 @@ public function testReCaptchaInvisibleHtmlFormButtonDefault() {

$recaptcha = $this->recaptcha_invisible;
$html_button = $recaptcha->htmlFormButton();
$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>', $html_button);
$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>',
$html_button);
}

/**
Expand All @@ -50,7 +64,8 @@ public function testReCaptchaInvisibleHtmlFormButtonCustom() {

$recaptcha = $this->recaptcha_invisible;
$html_button = $recaptcha->htmlFormButton('Custom Text');
$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>', $html_button);
$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>',
$html_button);
}

/**
Expand All @@ -72,6 +87,16 @@ public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() {
$this->recaptcha_invisible->htmlFormSnippet();
}

/**
* @test
*/
public function testDefaultCurlTimeout() {

$this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
$this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
$this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
}

/**
* @test
* @expectedException \Error
Expand All @@ -85,8 +110,9 @@ protected function setUp(): void {

parent::setUp(); // TODO: Change the autogenerated stub

$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key', 3);
$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key', 3);
$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');

}
}
10 changes: 9 additions & 1 deletion tests/ReCaptchaV3Test.php
Expand Up @@ -87,6 +87,13 @@ public function testValidateController() {
$this->assertArrayHasKey("error-codes", $return);
}

/**
* @test
*/
public function testCurlTimeoutIsSet() {
$this->assertEquals($this->recaptcha_v3->getCurlTimeout(), 3);
}

/**
* Define environment setup.
*
Expand All @@ -97,6 +104,7 @@ public function testValidateController() {
protected function getEnvironmentSetUp($app) {

$app['config']->set('recaptcha.version', 'v3');
$app['config']->set('recaptcha.curl_timeout', 3);
}

/**
Expand All @@ -106,7 +114,7 @@ protected function setUp(): void {

parent::setUp(); // TODO: Change the autogenerated stub

$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key', 3);
$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');

}
}

0 comments on commit 7b9b822

Please sign in to comment.