1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2017 - present |
4
|
|
|
* LaravelGoogleRecaptcha - ReCaptchaHelpersV2Test.php |
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
|
|
|
use Biscolab\ReCaptcha\ReCaptchaBuilderV2; |
15
|
|
|
|
16
|
|
|
class ReCaptchaHelpersV2Test extends TestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @test |
21
|
|
|
*/ |
22
|
|
|
public function testHtmlScriptTagJsApiCalledByFacade() |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
ReCaptcha::shouldReceive('htmlScriptTagJsApi') |
26
|
|
|
->once() |
27
|
|
|
->with(["key" => "val"]); |
28
|
|
|
|
29
|
|
|
htmlScriptTagJsApi(["key" => "val"]); |
30
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function testHtmlFormSnippetCalledByFacade() |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
ReCaptcha::shouldReceive('htmlFormSnippet') |
40
|
|
|
->once(); |
41
|
|
|
|
42
|
|
|
htmlFormSnippet(); |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @test |
48
|
|
|
*/ |
49
|
|
|
public function testTagAttributes() |
50
|
|
|
{ |
51
|
|
|
|
52
|
|
|
$recaptcha = \recaptcha(); |
53
|
|
|
|
54
|
|
|
$tag_attributes = $recaptcha->getTagAttributes(); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$this->assertArrayHasKey('sitekey', $recaptcha->getTagAttributes()); |
57
|
|
|
$this->assertArrayHasKey('theme', $recaptcha->getTagAttributes()); |
58
|
|
|
$this->assertArrayHasKey('size', $tag_attributes); |
59
|
|
|
$this->assertArrayHasKey('tabindex', $tag_attributes); |
60
|
|
|
$this->assertArrayHasKey('callback', $tag_attributes); |
61
|
|
|
$this->assertArrayHasKey('expired-callback', $tag_attributes); |
62
|
|
|
$this->assertArrayHasKey('error-callback', $tag_attributes); |
63
|
|
|
|
64
|
|
|
$this->assertEquals($tag_attributes['sitekey'], 'api_site_key'); |
65
|
|
|
$this->assertEquals($tag_attributes['theme'], 'dark'); |
66
|
|
|
$this->assertEquals($tag_attributes['size'], 'compact'); |
67
|
|
|
$this->assertEquals($tag_attributes['tabindex'], '2'); |
68
|
|
|
$this->assertEquals($tag_attributes['callback'], 'callbackFunction'); |
69
|
|
|
$this->assertEquals($tag_attributes['expired-callback'], 'expiredCallbackFunction'); |
70
|
|
|
$this->assertEquals($tag_attributes['error-callback'], 'errorCallbackFunction'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @test |
75
|
|
|
*/ |
76
|
|
|
public function testExpectReCaptchaInstanceOfReCaptchaBuilderV2() |
77
|
|
|
{ |
78
|
|
|
|
79
|
|
|
$this->assertInstanceOf(ReCaptchaBuilderV2::class, \recaptcha()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @expectedException \Error |
84
|
|
|
*/ |
85
|
|
|
public function testExpectExceptionWhenGetFormIdFunctionIsCalled() |
86
|
|
|
{ |
87
|
|
|
|
88
|
|
|
getFormId(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @test |
93
|
|
|
*/ |
94
|
|
|
public function testHtmlFormSnippet() |
95
|
|
|
{ |
96
|
|
|
|
97
|
|
|
$html_snippet = \recaptcha()->htmlFormSnippet(); |
|
|
|
|
98
|
|
|
$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>', |
99
|
|
|
$html_snippet); |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Define environment setup. |
105
|
|
|
* |
106
|
|
|
* @param \Illuminate\Foundation\Application $app |
107
|
|
|
* |
108
|
|
|
* @return void |
109
|
|
|
*/ |
110
|
|
|
protected function getEnvironmentSetUp($app) |
111
|
|
|
{ |
112
|
|
|
|
113
|
|
|
$app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
114
|
|
|
$app['config']->set('recaptcha.version', 'v2'); |
115
|
|
|
$app['config']->set('recaptcha.tag_attributes', [ |
116
|
|
|
'theme' => 'dark', |
117
|
|
|
'size' => 'compact', |
118
|
|
|
'tabindex' => '2', |
119
|
|
|
'callback' => 'callbackFunction', |
120
|
|
|
'expired-callback' => 'expiredCallbackFunction', |
121
|
|
|
'error-callback' => 'errorCallbackFunction', |
122
|
|
|
]); |
123
|
|
|
} |
124
|
|
|
} |