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

ReCaptchaHelpersInvisibleTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 82
rs 10
c 1
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testHtmlFormButtonConfiguration() 0 4 1
A getEnvironmentSetUp() 0 6 1
A testGetFormIdCalledByFacade() 0 7 1
A testHtmlScriptTagJsApiCalledByFacade() 0 8 1
A testHtmlFormSnippetCalledByFacade() 0 7 1
A testHtmlFormButtonCalledByFacade() 0 8 1
A testGetFormIdReturnDefaultFormIdValue() 0 3 1
1
<?php
2
/**
3
 * Copyright (c) 2017 - present
4
 * LaravelGoogleRecaptcha - ReCaptchaHelpersInvisibleTest.phpp
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 8/8/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\Facades\ReCaptcha;
14
15
class ReCaptchaHelpersInvisibleTest extends TestCase
16
{
17
18
    /**
19
     * @test
20
     */
21
    public function testHtmlScriptTagJsApiCalledByFacade()
22
    {
23
24
        ReCaptcha::shouldReceive('htmlScriptTagJsApi')
25
            ->once()
26
            ->with(["form_id" => "test-form"]);
27
28
        htmlScriptTagJsApi(["form_id" => "test-form"]);
29
30
    }
31
32
    /**
33
     * @test
34
     */
35
    public function testHtmlFormButtonCalledByFacade()
36
    {
37
38
        ReCaptcha::shouldReceive('htmlFormButton')
39
            ->once()
40
            ->with("Inner text", ['id' => 'button_id']);
41
42
        htmlFormButton("Inner text", ['id' => 'button_id']);
43
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function testGetFormIdCalledByFacade()
50
    {
51
52
        ReCaptcha::shouldReceive('getFormId')
53
            ->once();
54
55
        getFormId();
56
57
    }
58
59
    public function testHtmlFormButtonConfiguration() {
60
        $button_html = htmlFormButton("Inner text", ['id' => 'button_id', 'class' => 'button_class', 'data-sitekey' => 'custom-data-sitekey', 'data-callback' => 'myCallback']);
61
62
        $this->assertEquals('<button class="button_class g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key" id="button_id">Inner text</button>', $button_html);
63
    }
64
65
    /**
66
     * @test
67
     * @expectedException \TypeError
68
     */
69
    public function testHtmlFormSnippetCalledByFacade()
70
    {
71
72
        ReCaptcha::shouldReceive('htmlFormSnippet')
73
            ->once();
74
75
        htmlFormSnippet();
76
77
    }
78
79
    public function testGetFormIdReturnDefaultFormIdValue()
80
    {
81
        $this->assertEquals('biscolab-recaptcha-invisible-form', getFormId());
82
    }
83
84
    /**
85
     * Define environment setup.
86
     *
87
     * @param  \Illuminate\Foundation\Application $app
88
     *
89
     * @return void
90
     */
91
    protected function getEnvironmentSetUp($app)
92
    {
93
94
        $app['config']->set('recaptcha.api_site_key', 'api_site_key');
95
        $app['config']->set('recaptcha.api_site_key', 'api_site_key');
96
        $app['config']->set('recaptcha.version', 'invisible');
97
    }
98
}