Completed
Branch master (7c189e)
by Roberto
04:00 queued 01:33
created

testReCaptchaInvisibleHtmlFormSnippetShouldThrowError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2017 - present
4
 * LaravelGoogleRecaptcha - ReCaptchaTest.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 12/9/2018
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
use Biscolab\ReCaptcha\ReCaptchaBuilderInvisible;
15
use Biscolab\ReCaptcha\ReCaptchaBuilderV2;
16
17
/**
18
 * Class ReCaptchaTest
19
 * @package Biscolab\ReCaptcha\Tests
20
 */
21
class ReCaptchaTest extends TestCase {
22
23
    protected $recaptcha_invisible = null;
24
25
    protected $recaptcha_v2        = null;
26
27
    /**
28
     * @tests
29
     */
30
    public function testHtmlScriptTagJsApiGetHtmlScriptTag() {
31
32
        $r = ReCaptcha::htmlScriptTagJsApi();
0 ignored issues
show
Bug introduced by
The method htmlScriptTagJsApi() does not exist on Biscolab\ReCaptcha\Facades\ReCaptcha. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

32
        /** @scrutinizer ignore-call */ 
33
        $r = ReCaptcha::htmlScriptTagJsApi();
Loading history...
33
        $this->assertEquals('<script src=\'https://www.google.com/recaptcha/api.js\' async defer></script>', $r);
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function testReCaptchaInvisibleHtmlFormButtonDefault() {
40
41
        $recaptcha = $this->recaptcha_invisible;
42
        $html_button = $recaptcha->htmlFormButton();
43
        $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>', $html_button);
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function testReCaptchaInvisibleHtmlFormButtonCustom() {
50
51
        $recaptcha = $this->recaptcha_invisible;
52
        $html_button = $recaptcha->htmlFormButton('Custom Text');
53
        $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>', $html_button);
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function testReCaptchaV2HtmlFormSnippet() {
60
61
        $recaptcha = $this->recaptcha_v2;
62
        $html_snippet = $recaptcha->htmlFormSnippet();
63
        $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet);
64
    }
65
66
    /**
67
     * @test
68
     * @expectedException     \Error
69
     */
70
    public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() {
71
72
        $this->recaptcha_invisible->htmlFormSnippet();
73
    }
74
75
    /**
76
     * @test
77
     * @expectedException     \Error
78
     */
79
    public function testReCaptchaV2htmlFormButtonShouldThrowError() {
80
81
        $this->recaptcha_v2->htmlFormButton();
82
    }
83
84
    protected function setUp() {
85
86
        parent::setUp(); // TODO: Change the autogenerated stub
87
88
        $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key', 'invisible');
89
        $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
90
91
    }
92
}