Skip to content

Commit

Permalink
updated ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanDaDeng committed Dec 25, 2018
1 parent efef647 commit 02f393d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ This package requires the following dependencies:
Via Composer

``` sh
$ composer require timehunter/laravel-google-recaptcha-v3 "~1.2.4"
$ composer require timehunter/laravel-google-recaptcha-v3 "~1.3.1"
```

If your Laravel framework version <= 5.4, please register the service provider in your config file: /config/app.php, otherwise please skip it.
Expand Down
33 changes: 22 additions & 11 deletions src/GoogleReCaptchaV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,35 @@ public function __construct(ReCaptchaConfigV3Interface $config, RequestClientInt

/**
* @param $mappers
* @return mixed
* @return array
*/
public function render($mappers)
public function prepareViewData($mappers)
{
$prepareData = [];
foreach ($mappers as $id => $action) {
$prepareData[$action][] = $id;
}

return app('view')->make(
$this->getView(),
[
'publicKey' => $this->getConfig()->getSiteKey(),
'mappers' => $prepareData,
'inline' => $this->config->isInline(),
'language' => $this->config->getLanguage()
]
);
$data = [
'publicKey' => $this->getConfig()->getSiteKey(),
'mappers' => $prepareData,
'inline' => $this->config->isInline(),
'language' => $this->config->getLanguage()
];

return $data;
}

/**
* @param $mappers
* @return \Illuminate\Contracts\View\View|null
*/
public function render($mappers){
if (!$this->config->isServiceEnabled()) {
return null;
}
$data = $this->prepareViewData($mappers);
return app('view')->make($this->getView(), $data);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use TimeHunter\LaravelGoogleCaptchaV3\Core\CurlRequestClient;
use TimeHunter\LaravelGoogleCaptchaV3\Core\GoogleReCaptchaV3Response;
use TimeHunter\LaravelGoogleCaptchaV3\Core\GuzzleRequestClient;
use TimeHunter\LaravelGoogleCaptchaV3\GoogleReCaptchaV3;
use TimeHunter\LaravelGoogleCaptchaV3\Configurations\ReCaptchaConfigV3;


class RequestTest extends TestCase
Expand Down
65 changes: 65 additions & 0 deletions tests/ViewTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace TimeHunter\Tests;

use PHPUnit\Framework\TestCase;
use TimeHunter\LaravelGoogleCaptchaV3\Core\GuzzleRequestClient;
use TimeHunter\LaravelGoogleCaptchaV3\GoogleReCaptchaV3;
use TimeHunter\LaravelGoogleCaptchaV3\Configurations\ReCaptchaConfigV3;


class ViewTest extends TestCase
{


public function testView()
{
// Create a stub for the SomeClass class.
$configStub = $this->createMock(ReCaptchaConfigV3::class);

// Configure the stub.
$configStub->method('isServiceEnabled')
->willReturn(false);


$clientStub = $this->createMock(GuzzleRequestClient::class);

$service = new GoogleReCaptchaV3($configStub, $clientStub);

$data = $service->render(['contact_us_id' => 'contact_us']);
$this->assertEquals(null, $data);
}


public function testView2()
{
// Create a stub for the SomeClass class.
$configStub = $this->createMock(ReCaptchaConfigV3::class);

// Configure the stub.
$configStub->method('isServiceEnabled')
->willReturn(true);

$configStub->method('getSiteKey')
->willReturn('test1');

$configStub->method('isInline')
->willReturn(false);

$configStub->method('getLanguage')
->willReturn('en');


$clientStub = $this->createMock(GuzzleRequestClient::class);

$service = new GoogleReCaptchaV3($configStub, $clientStub);

$data = $service->prepareViewData(['contact_us_id' => 'contact_us']);
$this->assertEquals('test1', $data['publicKey']);
$this->assertEquals('contact_us_id', $data['mappers']['contact_us'][0]);
$this->assertEquals(false, $data['inline']);
$this->assertEquals('en', $data['language']);
}


}

0 comments on commit 02f393d

Please sign in to comment.