Skip to content

Commit 8a87a6a

Browse files
committed
updated tests
1 parent 1b8ffc1 commit 8a87a6a

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

readme.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
[![StyleCI][ico-styleci]][link-styleci]
1616
[![Latest Unstable Version][ico-unstable]][link-unstable]
1717

18-
I will be super happy if you think this package is good and also star me. ^.^
19-
20-
PS: The version "~3.*" contains vue component which is unstable and incomplete right now, feel free to install it if you really want to use vue. It will be released soon.
21-
18+
This is a package for Google reCAPTCHA v2
2219
# DEMO
2320

2421
## Invisible

src/GoogleReCaptchaV2.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public function __construct(GoogleReCaptchaV2Service $service)
3333
* @param $ids
3434
* @return array
3535
*/
36-
public function prepareViewData($ids)
36+
public function prepareViewData(...$ids)
3737
{
3838

3939
$data = [
4040
'publicKey' => $this->getConfig()->getSiteKey(),
4141
'ids' => $ids,
4242
'inline' => $this->getConfig()->isInline(),
43-
'language' => $this->getConfig()->getLanguage(),
43+
'language' => $this->getConfig()->getLanguage(),
4444
'theme' => $this->getConfig()->getTheme(),
4545
'badge' => $this->getConfig()->getBadge(),
4646
'size' => $this->getConfig()->getSize()
@@ -71,7 +71,7 @@ public function render(...$ids)
7171
*/
7272
public function verifyResponse($response, $ip = null)
7373
{
74-
return $this->service->verifyResponse($response,$ip);
74+
return $this->service->verifyResponse($response, $ip);
7575
}
7676

7777
/**

tests/ViewTest.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testView()
2525
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
2626
$service = new GoogleReCaptchaV2($_service);
2727

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

@@ -53,9 +53,45 @@ public function testView2()
5353
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
5454
$service = new GoogleReCaptchaV2($_service);
5555

56-
$data = $service->prepareViewData(['contact_us_id' => 'contact_us']);
56+
$data = $service->prepareViewData('contact_us_id');
57+
58+
$this->assertEquals('test1', $data['publicKey']);
59+
$this->assertEquals('contact_us_id', $data['ids'][0]);
60+
$this->assertEquals(false, $data['inline']);
61+
$this->assertEquals('en', $data['language']);
62+
}
63+
64+
65+
66+
public function testView3()
67+
{
68+
// Create a stub for the SomeClass class.
69+
$configStub = $this->createMock(ReCaptchaConfigV2::class);
70+
71+
// Configure the stub.
72+
$configStub->method('isServiceEnabled')
73+
->willReturn(true);
74+
75+
$configStub->method('getSiteKey')
76+
->willReturn('test1');
77+
78+
$configStub->method('isInline')
79+
->willReturn(false);
80+
81+
$configStub->method('getLanguage')
82+
->willReturn('en');
83+
84+
$clientStub = $this->createMock(GuzzleRequestClient::class);
85+
86+
87+
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
88+
$service = new GoogleReCaptchaV2($_service);
89+
90+
$data = $service->prepareViewData('contact_us_id','contact_us_id2');
91+
5792
$this->assertEquals('test1', $data['publicKey']);
58-
$this->assertEquals('contact_us_id', $data['mappers']['contact_us'][0]);
93+
$this->assertEquals('contact_us_id', $data['ids'][0]);
94+
$this->assertEquals('contact_us_id2', $data['ids'][1]);
5995
$this->assertEquals(false, $data['inline']);
6096
$this->assertEquals('en', $data['language']);
6197
}

0 commit comments

Comments
 (0)