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

ReCaptchaHelpersV2ExplicitTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 37
dl 0
loc 96
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testExpectReCaptchaInstanceOfReCaptchaBuilderV2() 0 4 1
A testHtmlScriptTagJsApiHasJavascriptRenderFunction() 0 7 1
A getEnvironmentSetUp() 0 13 1
A testTagAttributes() 0 22 1
A testGetOnLoadCallbackFunction() 0 8 1
A testHtmlFormSnippet() 0 6 1
1
<?php
2
/**
3
 * Copyright (c) 2017 - present
4
 * LaravelGoogleRecaptcha - ReCaptchaHelpersV2ExplicitTest.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 2/9/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\ReCaptchaBuilderV2;
14
15
class ReCaptchaHelpersV2ExplicitTest extends TestCase
16
{
17
18
    /**
19
     * @test
20
     */
21
    public function testGetOnLoadCallbackFunction()
22
    {
23
24
        $recaptcha = \recaptcha();
25
26
        $callback = $recaptcha->getOnLoadCallback();
0 ignored issues
show
Bug introduced by
The method getOnLoadCallback() does not exist on Biscolab\ReCaptcha\ReCaptchaBuilder. It seems like you code against a sub-type of Biscolab\ReCaptcha\ReCaptchaBuilder such as Biscolab\ReCaptcha\ReCaptchaBuilderV2. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        /** @scrutinizer ignore-call */ 
27
        $callback = $recaptcha->getOnLoadCallback();
Loading history...
27
28
        $this->assertEquals('<script>var biscolabOnloadCallback = function() {grecaptcha.render(\'recaptcha-element\', {"sitekey":"api_site_key","theme":"dark","size":"compact","tabindex":"2","callback":"callbackFunction","expired-callback":"expiredCallbackFunction","error-callback":"errorCallbackFunction"});};</script>', $callback);
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function testHtmlScriptTagJsApiHasJavascriptRenderFunction()
35
    {
36
37
        $html = htmlScriptTagJsApi();
38
39
        $this->assertEquals('<script>var biscolabOnloadCallback = function() {grecaptcha.render(\'recaptcha-element\', {"sitekey":"api_site_key","theme":"dark","size":"compact","tabindex":"2","callback":"callbackFunction","expired-callback":"expiredCallbackFunction","error-callback":"errorCallbackFunction"});};</script><script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=biscolabOnloadCallback" async defer></script>',
40
            $html);
41
    }
42
43
    /**
44
     * @test
45
     */
46
    public function testTagAttributes()
47
    {
48
49
        $recaptcha = \recaptcha();
50
51
        $tag_attributes = $recaptcha->getTagAttributes();
0 ignored issues
show
Bug introduced by
The method getTagAttributes() does not exist on Biscolab\ReCaptcha\ReCaptchaBuilder. It seems like you code against a sub-type of Biscolab\ReCaptcha\ReCaptchaBuilder such as Biscolab\ReCaptcha\ReCaptchaBuilderV2. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        /** @scrutinizer ignore-call */ 
52
        $tag_attributes = $recaptcha->getTagAttributes();
Loading history...
52
53
        $this->assertArrayHasKey('sitekey', $tag_attributes);
54
        $this->assertArrayHasKey('theme', $tag_attributes);
55
        $this->assertArrayHasKey('size', $tag_attributes);
56
        $this->assertArrayHasKey('tabindex', $tag_attributes);
57
        $this->assertArrayHasKey('callback', $tag_attributes);
58
        $this->assertArrayHasKey('expired-callback', $tag_attributes);
59
        $this->assertArrayHasKey('error-callback', $tag_attributes);
60
61
        $this->assertEquals($tag_attributes['sitekey'], 'api_site_key');
62
        $this->assertEquals($tag_attributes['theme'], 'dark');
63
        $this->assertEquals($tag_attributes['size'], 'compact');
64
        $this->assertEquals($tag_attributes['tabindex'], '2');
65
        $this->assertEquals($tag_attributes['callback'], 'callbackFunction');
66
        $this->assertEquals($tag_attributes['expired-callback'], 'expiredCallbackFunction');
67
        $this->assertEquals($tag_attributes['error-callback'], 'errorCallbackFunction');
68
    }
69
70
    /**
71
     * @test
72
     */
73
    public function testExpectReCaptchaInstanceOfReCaptchaBuilderV2()
74
    {
75
76
        $this->assertInstanceOf(ReCaptchaBuilderV2::class, \recaptcha());
77
    }
78
79
    /**
80
     * @test
81
     */
82
    public function testHtmlFormSnippet()
83
    {
84
85
        $html_snippet = \recaptcha()->htmlFormSnippet();
0 ignored issues
show
Bug introduced by
The method htmlFormSnippet() does not exist on Biscolab\ReCaptcha\ReCaptchaBuilder. It seems like you code against a sub-type of Biscolab\ReCaptcha\ReCaptchaBuilder such as Biscolab\ReCaptcha\ReCaptchaBuilderV2. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
        $html_snippet = \recaptcha()->/** @scrutinizer ignore-call */ htmlFormSnippet();
Loading history...
86
        $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key" data-theme="dark" data-size="compact" data-tabindex="2" data-callback="callbackFunction" data-expired-callback="expiredCallbackFunction" data-error-callback="errorCallbackFunction" id="recaptcha-element"></div>',
87
            $html_snippet);
88
89
    }
90
91
    /**
92
     * Define environment setup.
93
     *
94
     * @param  \Illuminate\Foundation\Application $app
95
     *
96
     * @return void
97
     */
98
    protected function getEnvironmentSetUp($app)
99
    {
100
101
        $app['config']->set('recaptcha.api_site_key', 'api_site_key');
102
        $app['config']->set('recaptcha.version', 'v2');
103
        $app['config']->set('recaptcha.explicit', true);
104
        $app['config']->set('recaptcha.tag_attributes', [
105
            'theme'            => 'dark',
106
            'size'             => 'compact',
107
            'tabindex'         => '2',
108
            'callback'         => 'callbackFunction',
109
            'expired-callback' => 'expiredCallbackFunction',
110
            'error-callback'   => 'errorCallbackFunction',
111
        ]);
112
    }
113
}