Skip to content

Commit 02f393d

Browse files
committed
updated ci/cd
1 parent efef647 commit 02f393d

File tree

4 files changed

+88
-14
lines changed

4 files changed

+88
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ This package requires the following dependencies:
5656
Via Composer
5757

5858
``` sh
59-
$ composer require timehunter/laravel-google-recaptcha-v3 "~1.2.4"
59+
$ composer require timehunter/laravel-google-recaptcha-v3 "~1.3.1"
6060
```
6161

6262
If your Laravel framework version <= 5.4, please register the service provider in your config file: /config/app.php, otherwise please skip it.

src/GoogleReCaptchaV3.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,35 @@ public function __construct(ReCaptchaConfigV3Interface $config, RequestClientInt
2828

2929
/**
3030
* @param $mappers
31-
* @return mixed
31+
* @return array
3232
*/
33-
public function render($mappers)
33+
public function prepareViewData($mappers)
3434
{
3535
$prepareData = [];
3636
foreach ($mappers as $id => $action) {
3737
$prepareData[$action][] = $id;
3838
}
3939

40-
return app('view')->make(
41-
$this->getView(),
42-
[
43-
'publicKey' => $this->getConfig()->getSiteKey(),
44-
'mappers' => $prepareData,
45-
'inline' => $this->config->isInline(),
46-
'language' => $this->config->getLanguage()
47-
]
48-
);
40+
$data = [
41+
'publicKey' => $this->getConfig()->getSiteKey(),
42+
'mappers' => $prepareData,
43+
'inline' => $this->config->isInline(),
44+
'language' => $this->config->getLanguage()
45+
];
46+
47+
return $data;
48+
}
49+
50+
/**
51+
* @param $mappers
52+
* @return \Illuminate\Contracts\View\View|null
53+
*/
54+
public function render($mappers){
55+
if (!$this->config->isServiceEnabled()) {
56+
return null;
57+
}
58+
$data = $this->prepareViewData($mappers);
59+
return app('view')->make($this->getView(), $data);
4960
}
5061

5162
/**

tests/RequestTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use TimeHunter\LaravelGoogleCaptchaV3\Core\CurlRequestClient;
77
use TimeHunter\LaravelGoogleCaptchaV3\Core\GoogleReCaptchaV3Response;
88
use TimeHunter\LaravelGoogleCaptchaV3\Core\GuzzleRequestClient;
9-
use TimeHunter\LaravelGoogleCaptchaV3\GoogleReCaptchaV3;
10-
use TimeHunter\LaravelGoogleCaptchaV3\Configurations\ReCaptchaConfigV3;
119

1210

1311
class RequestTest extends TestCase

tests/ViewTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace TimeHunter\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use TimeHunter\LaravelGoogleCaptchaV3\Core\GuzzleRequestClient;
7+
use TimeHunter\LaravelGoogleCaptchaV3\GoogleReCaptchaV3;
8+
use TimeHunter\LaravelGoogleCaptchaV3\Configurations\ReCaptchaConfigV3;
9+
10+
11+
class ViewTest extends TestCase
12+
{
13+
14+
15+
public function testView()
16+
{
17+
// Create a stub for the SomeClass class.
18+
$configStub = $this->createMock(ReCaptchaConfigV3::class);
19+
20+
// Configure the stub.
21+
$configStub->method('isServiceEnabled')
22+
->willReturn(false);
23+
24+
25+
$clientStub = $this->createMock(GuzzleRequestClient::class);
26+
27+
$service = new GoogleReCaptchaV3($configStub, $clientStub);
28+
29+
$data = $service->render(['contact_us_id' => 'contact_us']);
30+
$this->assertEquals(null, $data);
31+
}
32+
33+
34+
public function testView2()
35+
{
36+
// Create a stub for the SomeClass class.
37+
$configStub = $this->createMock(ReCaptchaConfigV3::class);
38+
39+
// Configure the stub.
40+
$configStub->method('isServiceEnabled')
41+
->willReturn(true);
42+
43+
$configStub->method('getSiteKey')
44+
->willReturn('test1');
45+
46+
$configStub->method('isInline')
47+
->willReturn(false);
48+
49+
$configStub->method('getLanguage')
50+
->willReturn('en');
51+
52+
53+
$clientStub = $this->createMock(GuzzleRequestClient::class);
54+
55+
$service = new GoogleReCaptchaV3($configStub, $clientStub);
56+
57+
$data = $service->prepareViewData(['contact_us_id' => 'contact_us']);
58+
$this->assertEquals('test1', $data['publicKey']);
59+
$this->assertEquals('contact_us_id', $data['mappers']['contact_us'][0]);
60+
$this->assertEquals(false, $data['inline']);
61+
$this->assertEquals('en', $data['language']);
62+
}
63+
64+
65+
}

0 commit comments

Comments
 (0)