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

Commit 975e572

Browse files
committed
Test coverage increased
1 parent 9c289cd commit 975e572

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

tests/ReCaptchaConfigurationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ class ReCaptchaConfigurationTest extends TestCase
2525
*/
2626
protected $recaptcha;
2727

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+
2842
/**
2943
* @test
3044
*/

tests/ReCaptchaTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,58 @@ public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError()
9393
$this->recaptcha_invisible->htmlFormSnippet();
9494
}
9595

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+
* @expectedException \Exception
141+
*/
142+
public function testReCaptchaInvisibleHtmlScriptTagJsApiShouldThrowError()
143+
{
144+
145+
$this->recaptcha_invisible->htmlScriptTagJsApi();
146+
}
147+
96148
/**
97149
* @test
98150
*/
@@ -114,6 +166,15 @@ public function testReCaptchaV2htmlFormButtonShouldThrowError()
114166
$this->recaptcha_v2->htmlFormButton();
115167
}
116168

169+
protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value)
170+
{
171+
172+
$reflection = new \ReflectionClass($builder);
173+
$reflection_property = $reflection->getProperty('skip_by_ip');
174+
$reflection_property->setAccessible(true);
175+
$reflection_property->setValue($builder, $value);
176+
}
177+
117178
/**
118179
* @inheritdoc
119180
*/

0 commit comments

Comments
 (0)