Skip to content

Commit

Permalink
Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
biscolab committed Sep 13, 2020
1 parent bd4f9bd commit eb1680f
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 18 deletions.
81 changes: 81 additions & 0 deletions tests/ReCaptchaCustomApiDomainTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* Copyright (c) 2017 - present
* LaravelGoogleRecaptcha - ReCaptchaCustomApiDomainTest.php
* author: Roberto Belotti - [email protected]
* web : robertobelotti.com, github.com/biscolab
* Initial version created on: 13/9/2020
* MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE
*/

namespace Biscolab\ReCaptcha\Tests;

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

class ReCaptchaCustomApiDomainTest extends TestCase
{

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

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

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

/**
* @test
*/
public function testRecaptchaApiDomainChangesByConfig()
{
$this->app['config']->set('recaptcha.api_domain', 'www.recaptcha.net');
$this->assertEquals("www.recaptcha.net", $this->recaptcha_v2->getApiDomain());
$this->assertEquals("www.recaptcha.net", $this->recaptcha_invisible->getApiDomain());
$this->assertEquals("www.recaptcha.net", $this->recaptcha_v3->getApiDomain());
}

/**
* @test
*/
public function testRecaptchaApiDomainChangesByConfigInHtmlScriptTagJsApi()
{
$this->assertContains("https://www.recaptcha.net/recaptcha/api.js", $this->recaptcha_v2->htmlScriptTagJsApi());
$this->assertContains("https://www.recaptcha.net/recaptcha/api.js", $this->recaptcha_invisible->htmlScriptTagJsApi());
$this->assertContains("https://www.recaptcha.net/recaptcha/api.js", $this->recaptcha_v3->htmlScriptTagJsApi());
}

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
{

$app['config']->set('recaptcha.api_domain', 'www.recaptcha.net');
}

/**
* @inheritdoc
*/
protected function setUp(): void
{

parent::setUp(); // TODO: Change the autogenerated stub
$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');
}
}
52 changes: 34 additions & 18 deletions tests/ReCaptchaTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (c) 2017 - present
* LaravelGoogleRecaptcha - ReCaptchaTest.php
Expand Down Expand Up @@ -56,8 +57,10 @@ public function testReCaptchaInvisibleHtmlFormButtonDefault()

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

/**
Expand All @@ -68,8 +71,10 @@ public function testReCaptchaInvisibleHtmlFormButtonCustom()

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

/**
Expand Down Expand Up @@ -156,19 +161,31 @@ public function testReCaptchaV2htmlFormButtonShouldThrowError()
$this->recaptcha_v2->htmlFormButton();
}

/**
* @test
*/
public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName() {
$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME, recaptchaFieldName());
}
/**
* @test
*/
public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName()
{
$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME, recaptchaFieldName());
}

/**
* @test
*/
public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName()
{
$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME, recaptchaRuleName());
}

/**
* @test
*/
public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName() {
$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME, recaptchaRuleName());
}
/**
* @test
*/
public function testDefaultRecaptchaApiDomainIsGoogleDotCom()
{
$this->assertEquals("www.google.com", $this->recaptcha_v2->getApiDomain());
$this->assertEquals("www.google.com", $this->recaptcha_invisible->getApiDomain());
$this->assertEquals("www.google.com", $this->recaptcha_v3->getApiDomain());
}

protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value)
{
Expand All @@ -190,6 +207,5 @@ protected function setUp(): void
$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');

}
}
}

0 comments on commit eb1680f

Please sign in to comment.