Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit eb1680f

Browse files
committed
Tests added
1 parent bd4f9bd commit eb1680f

File tree

2 files changed

+115
-18
lines changed

2 files changed

+115
-18
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/**
4+
* Copyright (c) 2017 - present
5+
* LaravelGoogleRecaptcha - ReCaptchaCustomApiDomainTest.php
6+
* author: Roberto Belotti - [email protected]
7+
* web : robertobelotti.com, github.com/biscolab
8+
* Initial version created on: 13/9/2020
9+
* MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE
10+
*/
11+
12+
namespace Biscolab\ReCaptcha\Tests;
13+
14+
use Biscolab\ReCaptcha\ReCaptchaBuilderInvisible;
15+
use Biscolab\ReCaptcha\ReCaptchaBuilderV2;
16+
use Biscolab\ReCaptcha\ReCaptchaBuilderV3;
17+
18+
class ReCaptchaCustomApiDomainTest extends TestCase
19+
{
20+
21+
/**
22+
* @var ReCaptchaBuilderInvisible
23+
*/
24+
protected $recaptcha_invisible;
25+
26+
/**
27+
* @var ReCaptchaBuilderV2
28+
*/
29+
protected $recaptcha_v2;
30+
31+
/**
32+
* @var ReCaptchaBuilderV3
33+
*/
34+
protected $recaptcha_v3;
35+
36+
/**
37+
* @test
38+
*/
39+
public function testRecaptchaApiDomainChangesByConfig()
40+
{
41+
$this->app['config']->set('recaptcha.api_domain', 'www.recaptcha.net');
42+
$this->assertEquals("www.recaptcha.net", $this->recaptcha_v2->getApiDomain());
43+
$this->assertEquals("www.recaptcha.net", $this->recaptcha_invisible->getApiDomain());
44+
$this->assertEquals("www.recaptcha.net", $this->recaptcha_v3->getApiDomain());
45+
}
46+
47+
/**
48+
* @test
49+
*/
50+
public function testRecaptchaApiDomainChangesByConfigInHtmlScriptTagJsApi()
51+
{
52+
$this->assertContains("https://www.recaptcha.net/recaptcha/api.js", $this->recaptcha_v2->htmlScriptTagJsApi());
53+
$this->assertContains("https://www.recaptcha.net/recaptcha/api.js", $this->recaptcha_invisible->htmlScriptTagJsApi());
54+
$this->assertContains("https://www.recaptcha.net/recaptcha/api.js", $this->recaptcha_v3->htmlScriptTagJsApi());
55+
}
56+
57+
/**
58+
* Define environment setup.
59+
*
60+
* @param \Illuminate\Foundation\Application $app
61+
*
62+
* @return void
63+
*/
64+
protected function getEnvironmentSetUp($app)
65+
{
66+
67+
$app['config']->set('recaptcha.api_domain', 'www.recaptcha.net');
68+
}
69+
70+
/**
71+
* @inheritdoc
72+
*/
73+
protected function setUp(): void
74+
{
75+
76+
parent::setUp(); // TODO: Change the autogenerated stub
77+
$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
78+
$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
79+
$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
80+
}
81+
}

tests/ReCaptchaTest.php

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright (c) 2017 - present
45
* LaravelGoogleRecaptcha - ReCaptchaTest.php
@@ -56,8 +57,10 @@ public function testReCaptchaInvisibleHtmlFormButtonDefault()
5657

5758
$recaptcha = $this->recaptcha_invisible;
5859
$html_button = $recaptcha->htmlFormButton();
59-
$this->assertEquals('<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Submit</button>',
60-
$html_button);
60+
$this->assertEquals(
61+
'<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Submit</button>',
62+
$html_button
63+
);
6164
}
6265

6366
/**
@@ -68,8 +71,10 @@ public function testReCaptchaInvisibleHtmlFormButtonCustom()
6871

6972
$recaptcha = $this->recaptcha_invisible;
7073
$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);
74+
$this->assertEquals(
75+
'<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Custom Text</button>',
76+
$html_button
77+
);
7378
}
7479

7580
/**
@@ -156,19 +161,31 @@ public function testReCaptchaV2htmlFormButtonShouldThrowError()
156161
$this->recaptcha_v2->htmlFormButton();
157162
}
158163

159-
/**
160-
* @test
161-
*/
162-
public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName() {
163-
$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME, recaptchaFieldName());
164-
}
164+
/**
165+
* @test
166+
*/
167+
public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName()
168+
{
169+
$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME, recaptchaFieldName());
170+
}
171+
172+
/**
173+
* @test
174+
*/
175+
public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName()
176+
{
177+
$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME, recaptchaRuleName());
178+
}
165179

166-
/**
167-
* @test
168-
*/
169-
public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName() {
170-
$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME, recaptchaRuleName());
171-
}
180+
/**
181+
* @test
182+
*/
183+
public function testDefaultRecaptchaApiDomainIsGoogleDotCom()
184+
{
185+
$this->assertEquals("www.google.com", $this->recaptcha_v2->getApiDomain());
186+
$this->assertEquals("www.google.com", $this->recaptcha_invisible->getApiDomain());
187+
$this->assertEquals("www.google.com", $this->recaptcha_v3->getApiDomain());
188+
}
172189

173190
protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value)
174191
{
@@ -190,6 +207,5 @@ protected function setUp(): void
190207
$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
191208
$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
192209
$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
193-
194210
}
195-
}
211+
}

0 commit comments

Comments
 (0)