Test Failed
Branch master (50e60b)
by Roberto
03:09 queued 32s
created

ReCaptchaV3Test::testValidateController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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