1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright (c) 2017 - present |
5
|
|
|
* LaravelGoogleRecaptcha - ReCaptchaHelpersV2ExplicitTest.php |
6
|
|
|
* author: Roberto Belotti - [email protected] |
7
|
|
|
* web : robertobelotti.com, github.com/biscolab |
8
|
|
|
* Initial version created on: 2/9/2019 |
9
|
|
|
* MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Biscolab\ReCaptcha\Tests; |
13
|
|
|
|
14
|
|
|
use Biscolab\ReCaptcha\ReCaptchaBuilderV2; |
15
|
|
|
|
16
|
|
|
class ReCaptchaHelpersV2ExplicitTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @test |
21
|
|
|
*/ |
22
|
|
|
public function testGetOnLoadCallbackFunction() |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
$recaptcha = \recaptcha(); |
26
|
|
|
/** @scrutinizer ignore-call */ |
27
|
|
|
$callback = $recaptcha->getOnLoadCallback(); |
28
|
|
|
|
29
|
|
|
$this->assertEquals( |
30
|
|
|
'<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>', |
31
|
|
|
$callback |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @test |
37
|
|
|
*/ |
38
|
|
|
public function testHtmlScriptTagJsApiHasJavascriptRenderFunction() |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
$html = htmlScriptTagJsApi(); |
42
|
|
|
|
43
|
|
|
$this->assertEquals( |
44
|
|
|
'<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>', |
45
|
|
|
$html |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @test |
51
|
|
|
*/ |
52
|
|
|
public function testTagAttributes() |
53
|
|
|
{ |
54
|
|
|
|
55
|
|
|
$recaptcha = \recaptcha(); |
56
|
|
|
/** @scrutinizer ignore-call */ |
57
|
|
|
$tag_attributes = $recaptcha->getTagAttributes(); |
58
|
|
|
|
59
|
|
|
$this->assertArrayHasKey('sitekey', $tag_attributes); |
60
|
|
|
$this->assertArrayHasKey('theme', $tag_attributes); |
61
|
|
|
$this->assertArrayHasKey('size', $tag_attributes); |
62
|
|
|
$this->assertArrayHasKey('tabindex', $tag_attributes); |
63
|
|
|
$this->assertArrayHasKey('callback', $tag_attributes); |
64
|
|
|
$this->assertArrayHasKey('expired-callback', $tag_attributes); |
65
|
|
|
$this->assertArrayHasKey('error-callback', $tag_attributes); |
66
|
|
|
|
67
|
|
|
$this->assertEquals($tag_attributes['sitekey'], 'api_site_key'); |
68
|
|
|
$this->assertEquals($tag_attributes['theme'], 'dark'); |
69
|
|
|
$this->assertEquals($tag_attributes['size'], 'compact'); |
70
|
|
|
$this->assertEquals($tag_attributes['tabindex'], '2'); |
71
|
|
|
$this->assertEquals($tag_attributes['callback'], 'callbackFunction'); |
72
|
|
|
$this->assertEquals($tag_attributes['expired-callback'], 'expiredCallbackFunction'); |
73
|
|
|
$this->assertEquals($tag_attributes['error-callback'], 'errorCallbackFunction'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @test |
78
|
|
|
*/ |
79
|
|
|
public function testExpectReCaptchaInstanceOfReCaptchaBuilderV2() |
80
|
|
|
{ |
81
|
|
|
|
82
|
|
|
$this->assertInstanceOf(ReCaptchaBuilderV2::class, \recaptcha()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @test |
87
|
|
|
*/ |
88
|
|
|
public function testHtmlFormSnippet() |
89
|
|
|
{ |
90
|
|
|
|
91
|
|
|
/** @scrutinizer ignore-call */ |
92
|
|
|
$html_snippet = \recaptcha()->htmlFormSnippet(); |
93
|
|
|
$this->assertEquals( |
94
|
|
|
'<div class="g-recaptcha" data-callback="callbackFunction" data-error-callback="errorCallbackFunction" data-expired-callback="expiredCallbackFunction" data-sitekey="api_site_key" data-size="compact" data-tabindex="2" data-theme="dark" id="recaptcha-element"></div>', |
95
|
|
|
$html_snippet |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Define environment setup. |
101
|
|
|
* |
102
|
|
|
* @param \Illuminate\Foundation\Application $app |
103
|
|
|
* |
104
|
|
|
* @return void |
105
|
|
|
*/ |
106
|
|
|
protected function getEnvironmentSetUp($app) |
107
|
|
|
{ |
108
|
|
|
|
109
|
|
|
$app['config']->set('recaptcha.api_site_key', 'api_site_key'); |
110
|
|
|
$app['config']->set('recaptcha.version', 'v2'); |
111
|
|
|
$app['config']->set('recaptcha.explicit', true); |
112
|
|
|
$app['config']->set('recaptcha.tag_attributes', [ |
113
|
|
|
'theme' => 'dark', |
114
|
|
|
'size' => 'compact', |
115
|
|
|
'tabindex' => '2', |
116
|
|
|
'callback' => 'callbackFunction', |
117
|
|
|
'expired-callback' => 'expiredCallbackFunction', |
118
|
|
|
'error-callback' => 'errorCallbackFunction', |
119
|
|
|
]); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|