Passed
Branch master (47c941)
by Roberto
05:04
created
tests/ReCaptchaTest.php 1 patch
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -24,188 +24,188 @@
 block discarded – undo
24 24
 class ReCaptchaTest extends TestCase
25 25
 {
26 26
 
27
-	/**
28
-	 * @var ReCaptchaBuilderInvisible
29
-	 */
30
-	protected $recaptcha_invisible = null;
31
-
32
-	/**
33
-	 * @var ReCaptchaBuilderV2
34
-	 */
35
-	protected $recaptcha_v2 = null;
36
-
37
-	/**
38
-	 * @var ReCaptchaBuilderV3
39
-	 */
40
-	protected $recaptcha_v3 = null;
41
-
42
-	/**
43
-	 * @tests
44
-	 */
45
-	public function testHtmlScriptTagJsApiGetHtmlScriptTag()
46
-	{
47
-
48
-		$r = ReCaptcha::htmlScriptTagJsApi();
49
-		$this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r);
50
-	}
51
-
52
-	/**
53
-	 * @test
54
-	 */
55
-	public function testReCaptchaInvisibleHtmlFormButtonDefault()
56
-	{
57
-
58
-		$recaptcha = $this->recaptcha_invisible;
59
-		$html_button = $recaptcha->htmlFormButton();
60
-		$this->assertEquals(
61
-			'<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Submit</button>',
62
-			$html_button
63
-		);
64
-	}
65
-
66
-	/**
67
-	 * @test
68
-	 */
69
-	public function testReCaptchaInvisibleHtmlFormButtonCustom()
70
-	{
71
-
72
-		$recaptcha = $this->recaptcha_invisible;
73
-		$html_button = $recaptcha->htmlFormButton('Custom Text');
74
-		$this->assertEquals(
75
-			'<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Custom Text</button>',
76
-			$html_button
77
-		);
78
-	}
79
-
80
-	/**
81
-	 * @test
82
-	 */
83
-	public function testReCaptchaV2HtmlFormSnippet()
84
-	{
85
-
86
-		$recaptcha = $this->recaptcha_v2;
87
-		$html_snippet = $recaptcha->htmlFormSnippet();
88
-		$this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key" data-theme="light" data-size="normal" id="recaptcha-element"></div>', $html_snippet);
89
-	}
90
-
91
-	/**
92
-	 * @test
93
-	 * @expectedException     \Error
94
-	 */
95
-	public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError()
96
-	{
97
-
98
-		$this->recaptcha_invisible->htmlFormSnippet();
99
-	}
100
-
101
-	/**
102
-	 * @test
103
-	 */
104
-	public function testSkipByIpAndReturnArrayReturnsDefaultArray()
105
-	{
106
-
107
-		$mock = $this->getMockBuilder(ReCaptchaBuilder::class)
108
-			->setConstructorArgs([
109
-				"api_site_key",
110
-				"api_secret_key"
111
-			])
112
-			->setMethods([
113
-				'returnArray'
114
-			])
115
-			->getMock();
116
-
117
-		$mock->method('returnArray')
118
-			->willReturn(true);
119
-
120
-		$this->setSkipByIp($this->recaptcha_v3, true);
121
-
122
-		$validate = $this->recaptcha_v3->validate("");
123
-
124
-		$this->assertEquals([
125
-			"skip_by_ip" => true,
126
-			"score"      => 0.9,
127
-			"success"    => true
128
-		], $validate);
129
-	}
130
-
131
-	/**
132
-	 * @test
133
-	 */
134
-	public function testSlipByIpReturnsValidResponse()
135
-	{
136
-
137
-		$this->setSkipByIp($this->recaptcha_invisible, true);
138
-		$validate = $this->recaptcha_invisible->validate("");
139
-
140
-		$this->assertTrue($validate);
141
-	}
142
-
143
-	/**
144
-	 * @test
145
-	 */
146
-	public function testDefaultCurlTimeout()
147
-	{
148
-
149
-		$this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
150
-		$this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
151
-		$this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
152
-	}
153
-
154
-	/**
155
-	 * @test
156
-	 * @expectedException     \Error
157
-	 */
158
-	public function testReCaptchaV2htmlFormButtonShouldThrowError()
159
-	{
160
-
161
-		$this->recaptcha_v2->htmlFormButton();
162
-	}
163
-
164
-	/**
165
-	 * @test
166
-	 */
167
-	public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName()
168
-	{
169
-		$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME, recaptchaFieldName());
170
-	}
171
-
172
-	/**
173
-	 * @test
174
-	 */
175
-	public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName()
176
-	{
177
-		$this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME, recaptchaRuleName());
178
-	}
179
-
180
-	/**
181
-	 * @test
182
-	 */
183
-	public function testDefaultRecaptchaApiDomainIsGoogleDotCom()
184
-	{
185
-		$this->assertEquals("www.google.com", $this->recaptcha_v2->getApiDomain());
186
-		$this->assertEquals("www.google.com", $this->recaptcha_invisible->getApiDomain());
187
-		$this->assertEquals("www.google.com", $this->recaptcha_v3->getApiDomain());
188
-	}
189
-
190
-	protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value)
191
-	{
192
-
193
-		$reflection = new \ReflectionClass($builder);
194
-		$reflection_property = $reflection->getProperty('skip_by_ip');
195
-		$reflection_property->setAccessible(true);
196
-		$reflection_property->setValue($builder, $value);
197
-	}
198
-
199
-	/**
200
-	 * @inheritdoc
201
-	 */
202
-	protected function setUp(): void
203
-	{
204
-
205
-		parent::setUp(); // TODO: Change the autogenerated stub
206
-
207
-		$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
208
-		$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
209
-		$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
210
-	}
27
+    /**
28
+     * @var ReCaptchaBuilderInvisible
29
+     */
30
+    protected $recaptcha_invisible = null;
31
+
32
+    /**
33
+     * @var ReCaptchaBuilderV2
34
+     */
35
+    protected $recaptcha_v2 = null;
36
+
37
+    /**
38
+     * @var ReCaptchaBuilderV3
39
+     */
40
+    protected $recaptcha_v3 = null;
41
+
42
+    /**
43
+     * @tests
44
+     */
45
+    public function testHtmlScriptTagJsApiGetHtmlScriptTag()
46
+    {
47
+
48
+        $r = ReCaptcha::htmlScriptTagJsApi();
49
+        $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r);
50
+    }
51
+
52
+    /**
53
+     * @test
54
+     */
55
+    public function testReCaptchaInvisibleHtmlFormButtonDefault()
56
+    {
57
+
58
+        $recaptcha = $this->recaptcha_invisible;
59
+        $html_button = $recaptcha->htmlFormButton();
60
+        $this->assertEquals(
61
+            '<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Submit</button>',
62
+            $html_button
63
+        );
64
+    }
65
+
66
+    /**
67
+     * @test
68
+     */
69
+    public function testReCaptchaInvisibleHtmlFormButtonCustom()
70
+    {
71
+
72
+        $recaptcha = $this->recaptcha_invisible;
73
+        $html_button = $recaptcha->htmlFormButton('Custom Text');
74
+        $this->assertEquals(
75
+            '<button class="g-recaptcha" data-callback="biscolabLaravelReCaptcha" data-sitekey="api_site_key">Custom Text</button>',
76
+            $html_button
77
+        );
78
+    }
79
+
80
+    /**
81
+     * @test
82
+     */
83
+    public function testReCaptchaV2HtmlFormSnippet()
84
+    {
85
+
86
+        $recaptcha = $this->recaptcha_v2;
87
+        $html_snippet = $recaptcha->htmlFormSnippet();
88
+        $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key" data-theme="light" data-size="normal" id="recaptcha-element"></div>', $html_snippet);
89
+    }
90
+
91
+    /**
92
+     * @test
93
+     * @expectedException     \Error
94
+     */
95
+    public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError()
96
+    {
97
+
98
+        $this->recaptcha_invisible->htmlFormSnippet();
99
+    }
100
+
101
+    /**
102
+     * @test
103
+     */
104
+    public function testSkipByIpAndReturnArrayReturnsDefaultArray()
105
+    {
106
+
107
+        $mock = $this->getMockBuilder(ReCaptchaBuilder::class)
108
+            ->setConstructorArgs([
109
+                "api_site_key",
110
+                "api_secret_key"
111
+            ])
112
+            ->setMethods([
113
+                'returnArray'
114
+            ])
115
+            ->getMock();
116
+
117
+        $mock->method('returnArray')
118
+            ->willReturn(true);
119
+
120
+        $this->setSkipByIp($this->recaptcha_v3, true);
121
+
122
+        $validate = $this->recaptcha_v3->validate("");
123
+
124
+        $this->assertEquals([
125
+            "skip_by_ip" => true,
126
+            "score"      => 0.9,
127
+            "success"    => true
128
+        ], $validate);
129
+    }
130
+
131
+    /**
132
+     * @test
133
+     */
134
+    public function testSlipByIpReturnsValidResponse()
135
+    {
136
+
137
+        $this->setSkipByIp($this->recaptcha_invisible, true);
138
+        $validate = $this->recaptcha_invisible->validate("");
139
+
140
+        $this->assertTrue($validate);
141
+    }
142
+
143
+    /**
144
+     * @test
145
+     */
146
+    public function testDefaultCurlTimeout()
147
+    {
148
+
149
+        $this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
150
+        $this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
151
+        $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
152
+    }
153
+
154
+    /**
155
+     * @test
156
+     * @expectedException     \Error
157
+     */
158
+    public function testReCaptchaV2htmlFormButtonShouldThrowError()
159
+    {
160
+
161
+        $this->recaptcha_v2->htmlFormButton();
162
+    }
163
+
164
+    /**
165
+     * @test
166
+     */
167
+    public function testRecaptchaFieldNameHelperReturnsReCaptchaBuilderDefaultFieldName()
168
+    {
169
+        $this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_FIELD_NAME, recaptchaFieldName());
170
+    }
171
+
172
+    /**
173
+     * @test
174
+     */
175
+    public function testRecaptchaRuleNameHelperReturnsReCaptchaBuilderDefaultRuleName()
176
+    {
177
+        $this->assertEquals(ReCaptchaBuilder::DEFAULT_RECAPTCHA_RULE_NAME, recaptchaRuleName());
178
+    }
179
+
180
+    /**
181
+     * @test
182
+     */
183
+    public function testDefaultRecaptchaApiDomainIsGoogleDotCom()
184
+    {
185
+        $this->assertEquals("www.google.com", $this->recaptcha_v2->getApiDomain());
186
+        $this->assertEquals("www.google.com", $this->recaptcha_invisible->getApiDomain());
187
+        $this->assertEquals("www.google.com", $this->recaptcha_v3->getApiDomain());
188
+    }
189
+
190
+    protected function setSkipByIp(ReCaptchaBuilder $builder, bool $value)
191
+    {
192
+
193
+        $reflection = new \ReflectionClass($builder);
194
+        $reflection_property = $reflection->getProperty('skip_by_ip');
195
+        $reflection_property->setAccessible(true);
196
+        $reflection_property->setValue($builder, $value);
197
+    }
198
+
199
+    /**
200
+     * @inheritdoc
201
+     */
202
+    protected function setUp(): void
203
+    {
204
+
205
+        parent::setUp(); // TODO: Change the autogenerated stub
206
+
207
+        $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
208
+        $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
209
+        $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
210
+    }
211 211
 }
Please login to merge, or discard this patch.
src/ReCaptchaBuilder.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
     public function setApiUrls(): ReCaptchaBuilder
215 215
     {
216 216
 
217
-        $this->api_url = 'https://' . $this->api_domain . '/recaptcha/api/siteverify';
218
-        $this->api_js_url = 'https://' . $this->api_domain . '/recaptcha/api.js';
217
+        $this->api_url = 'https://'.$this->api_domain.'/recaptcha/api/siteverify';
218
+        $this->api_js_url = 'https://'.$this->api_domain.'/recaptcha/api.js';
219 219
 
220 220
         return $this;
221 221
     }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
             $whitelist = explode(',', $whitelist);
233 233
         }
234 234
 
235
-        $whitelist = array_map(function ($item) {
235
+        $whitelist = array_map(function($item) {
236 236
 
237 237
             return trim($item);
238 238
         }, $whitelist);
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
         }
288 288
 
289 289
         // Create query string
290
-        $query = ($query) ? '?' . http_build_query($query) : "";
291
-        $html .= "<script src=\"" . $this->api_js_url .  $query . "\" async defer></script>";
290
+        $query = ($query) ? '?'.http_build_query($query) : "";
291
+        $html .= "<script src=\"".$this->api_js_url.$query."\" async defer></script>";
292 292
 
293 293
         return $html;
294 294
     }
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
             'response' => $response,
323 323
         ]);
324 324
 
325
-        $url = $this->api_url . '?' . $params;
325
+        $url = $this->api_url.'?'.$params;
326 326
 
327 327
         if (function_exists('curl_version')) {
328 328
 
Please login to merge, or discard this patch.
src/ReCaptchaBuilderV3.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             return '';
48 48
         }
49 49
 
50
-        $html = "<script src=\"" . $this->api_js_url . "?render={$this->api_site_key}\"></script>";
50
+        $html = "<script src=\"".$this->api_js_url."?render={$this->api_site_key}\"></script>";
51 51
 
52 52
         $action = Arr::get($configuration, 'action', 'homepage');
53 53
 
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
                 fetch('/" . config(
70 70
                 'recaptcha.default_validation_route',
71 71
                 'biscolab-recaptcha/validate'
72
-            ) . "?" . config(
72
+            )."?".config(
73 73
                 'recaptcha.default_token_parameter_name',
74 74
                 'token'
75
-            ) . "=' + token, {
75
+            )."=' + token, {
76 76
                     headers: {
77 77
                         \"X-Requested-With\": \"XMLHttpRequest\",
78 78
                         \"X-CSRF-TOKEN\": csrfToken.content
Please login to merge, or discard this patch.