Passed
Push — master ( b01395...c75806 )
by Roberto
05:23 queued 13s
created

ReCaptchaV3Test::testcCatchCallbackFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 1
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\Facades\ReCaptcha;
15
use Biscolab\ReCaptcha\ReCaptchaBuilderV3;
16
use Illuminate\Support\Facades\App;
17
18
/**
19
 * Class ReCaptchaV3Test
20
 * @package Biscolab\ReCaptcha\Tests
21
 */
22
class ReCaptchaV3Test extends TestCase
23
{
24
25
    protected $recaptcha_v3 = null;
26
27
    /**
28
     * @test
29
     */
30
    public function testGetApiVersion()
31
    {
32
33
        $this->assertEquals($this->recaptcha_v3->getVersion(), 'v3');
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function testAction()
40
    {
41
42
        $r = $this->recaptcha_v3->htmlScriptTagJsApi(['action' => 'someAction']);
43
        $this->assertRegexp('/someAction/', $r);
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function testFetchCallbackFunction()
50
    {
51
52
        $r = $this->recaptcha_v3->htmlScriptTagJsApi(['callback_then' => 'functionCallbackThen']);
53
        $this->assertRegexp('/functionCallbackThen\(response\)/', $r);
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function testcCatchCallbackFunction()
60
    {
61
62
        $r = $this->recaptcha_v3->htmlScriptTagJsApi(['callback_catch' => 'functionCallbackCatch']);
63
        $this->assertRegexp('/functionCallbackCatch\(err\)/', $r);
64
    }
65
66
    /**
67
     * @test
68
     */
69
    public function testCustomValidationFunction()
70
    {
71
72
        $r = $this->recaptcha_v3->htmlScriptTagJsApi(['custom_validation' => 'functionCustomValidation']);
73
        $this->assertRegexp('/functionCustomValidation\(token\)/', $r);
74
    }
75
76
    /**
77
     * @test
78
     */
79
    public function testValidateController()
80
    {
81
82
        $controller = App::make(ReCaptchaController::class);
83
        $return = $controller->validateV3();
84
85
        $this->assertArrayHasKey("success", $return);
86
        $this->assertArrayHasKey("error-codes", $return);
87
    }
88
89
    /**
90
     * @test
91
     */
92
    public function testCurlTimeoutIsSet()
93
    {
94
95
        $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), 3);
96
    }
97
98
    /**
99
     * @test
100
     */
101
    public function testHtmlScriptTagJsApiCalledByFacade()
102
    {
103
104
        ReCaptcha::shouldReceive('htmlScriptTagJsApi')
105
            ->once()
106
            ->with([]);
107
108
        htmlScriptTagJsApi([]);
109
110
    }
111
112
    /**
113
     * Define environment setup.
114
     *
115
     * @param  \Illuminate\Foundation\Application $app
116
     *
117
     * @return void
118
     */
119
    protected function getEnvironmentSetUp($app)
120
    {
121
122
        $app['config']->set('recaptcha.version', 'v3');
123
        $app['config']->set('recaptcha.curl_timeout', 3);
124
    }
125
126
    /**
127
     * Setup the test environment.
128
     */
129
    protected function setUp(): void
130
    {
131
132
        parent::setUp(); // TODO: Change the autogenerated stub
133
134
        $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
135
136
    }
137
}