Passed
Branch master (7b9b82)
by Roberto
15:23
created

ReCaptchaTest::testDefaultCurlTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
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\ReCaptchaBuilder;
15
use Biscolab\ReCaptcha\ReCaptchaBuilderInvisible;
16
use Biscolab\ReCaptcha\ReCaptchaBuilderV2;
17
use Biscolab\ReCaptcha\ReCaptchaBuilderV3;
18
19
/**
20
 * Class ReCaptchaTest
21
 * @package Biscolab\ReCaptcha\Tests
22
 */
23
class ReCaptchaTest extends TestCase {
24
25
	/**
26
	 * @var ReCaptchaBuilderInvisible
27
	 */
28
	protected $recaptcha_invisible = null;
29
30
	/**
31
	 * @var ReCaptchaBuilderV2
32
	 */
33
	protected $recaptcha_v2 = null;
34
35
	/**
36
	 * @var ReCaptchaBuilderV3
37
	 */
38
	protected $recaptcha_v3 = null;
39
40
	/**
41
	 * @tests
42
	 */
43
	public function testHtmlScriptTagJsApiGetHtmlScriptTag() {
44
45
		$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

45
		/** @scrutinizer ignore-call */ 
46
  $r = ReCaptcha::htmlScriptTagJsApi();
Loading history...
46
		$this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r);
47
	}
48
49
	/**
50
	 * @test
51
	 */
52
	public function testReCaptchaInvisibleHtmlFormButtonDefault() {
53
54
		$recaptcha = $this->recaptcha_invisible;
55
		$html_button = $recaptcha->htmlFormButton();
56
		$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>',
57
			$html_button);
58
	}
59
60
	/**
61
	 * @test
62
	 */
63
	public function testReCaptchaInvisibleHtmlFormButtonCustom() {
64
65
		$recaptcha = $this->recaptcha_invisible;
66
		$html_button = $recaptcha->htmlFormButton('Custom Text');
67
		$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>',
68
			$html_button);
69
	}
70
71
	/**
72
	 * @test
73
	 */
74
	public function testReCaptchaV2HtmlFormSnippet() {
75
76
		$recaptcha = $this->recaptcha_v2;
77
		$html_snippet = $recaptcha->htmlFormSnippet();
78
		$this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet);
79
	}
80
81
	/**
82
	 * @test
83
	 * @expectedException     \Error
84
	 */
85
	public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() {
86
87
		$this->recaptcha_invisible->htmlFormSnippet();
0 ignored issues
show
Bug introduced by
The method htmlFormSnippet() does not exist on Biscolab\ReCaptcha\ReCaptchaBuilderInvisible. ( Ignorable by Annotation )

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

87
		$this->recaptcha_invisible->/** @scrutinizer ignore-call */ 
88
                              htmlFormSnippet();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
	}
89
90
	/**
91
	 * @test
92
	 */
93
	public function testDefaultCurlTimeout() {
94
95
		$this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
96
		$this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
97
		$this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
98
	}
99
100
	/**
101
	 * @test
102
	 * @expectedException     \Error
103
	 */
104
	public function testReCaptchaV2htmlFormButtonShouldThrowError() {
105
106
		$this->recaptcha_v2->htmlFormButton();
0 ignored issues
show
Bug introduced by
The method htmlFormButton() does not exist on 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

106
		$this->recaptcha_v2->/** @scrutinizer ignore-call */ 
107
                       htmlFormButton();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
107
	}
108
109
	protected function setUp(): void {
110
111
		parent::setUp(); // TODO: Change the autogenerated stub
112
113
		$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
114
		$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
115
		$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
116
117
	}
118
}