-
Notifications
You must be signed in to change notification settings - Fork 59
/
ReCaptchaV3Test.php
120 lines (94 loc) · 2.66 KB
/
ReCaptchaV3Test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* Copyright (c) 2017 - present
* LaravelGoogleRecaptcha - ReCaptchaV3Test.php
* author: Roberto Belotti - roby.belotti@gmail.com
* web : robertobelotti.com, github.com/biscolab
* Initial version created on: 22/1/2019
* MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE
*/
namespace Biscolab\ReCaptcha\Tests;
use Biscolab\ReCaptcha\Controllers\ReCaptchaController;
use Biscolab\ReCaptcha\ReCaptchaBuilderV3;
use Illuminate\Support\Facades\App;
/**
* Class ReCaptchaV3Test
* @package Biscolab\ReCaptcha\Tests
*/
class ReCaptchaV3Test extends TestCase {
protected $recaptcha_v3 = null;
/**
* @test
*/
public function testGetApiVersion() {
$this->assertEquals($this->recaptcha_v3->getVersion(), 'v3');
}
/**
* @test
*/
public function testHtmlScriptTagJsApiV3GetHtmlScriptTag() {
$r = $this->recaptcha_v3->htmlScriptTagJsApiV3();
$this->assertRegexp('/csrfToken/', $r);
}
/**
* @test
*/
public function testAction() {
$r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['action' => 'someAction']);
$this->assertRegexp('/someAction/', $r);
}
/**
* @test
*/
public function testFetchCallbackFunction() {
$r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_then' => 'functionCallbackThen']);
$this->assertRegexp('/functionCallbackThen\(response\)/', $r);
}
/**
* @test
*/
public function testcCatchCallbackFunction() {
$r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_catch' => 'functionCallbackCatch']);
$this->assertRegexp('/functionCallbackCatch\(err\)/', $r);
}
/**
* @test
*/
public function testCustomValidationFunction() {
$r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['custom_validation' => 'functionCustomValidation']);
$this->assertRegexp('/functionCustomValidation\(token\)/', $r);
}
/**
* @test
*/
public function testValidateController() {
$controller = App::make(ReCaptchaController::class);
$return = $controller->validateV3();
$this->assertArrayHasKey("success", $return);
$this->assertArrayHasKey("error-codes", $return);
}
/**
* @test
*/
public function testCurlTimeoutIsSet() {
$this->assertEquals($this->recaptcha_v3->getCurlTimeout(), 3);
}
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app) {
$app['config']->set('recaptcha.version', 'v3');
$app['config']->set('recaptcha.curl_timeout', 3);
}
/**
* Setup the test environment.
*/
protected function setUp(): void {
parent::setUp(); // TODO: Change the autogenerated stub
$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
}
}