This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from apility/feature/catpchav2-test-suite
Test suite for CaptchaV2
- Loading branch information
Showing
8 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Netflex\Site\Support\CaptchaV2; | ||
use Spatie\Snapshots\MatchesSnapshots; | ||
|
||
final class CaptchaV2_CheckBoxTest extends TestCase | ||
{ | ||
use MatchesSnapshots; | ||
|
||
/** | ||
* Call this template method before each test method is run. | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
require_once('src/Netflex/Site/Support/CaptchaV2.php'); | ||
require_once('src/functions/common/functions_system.php'); | ||
require_once('src/Netflex/Site/Support/GoogleResponseException.php'); | ||
require_once('src/Netflex/Site/Support/ResponseMissingException.php'); | ||
require_once('src/Netflex/Site/Support/ConfigurationMissingException.php'); | ||
} | ||
|
||
public function testThrowsExceptionWhenConfiguationMissing (): void { | ||
$this->expectException('Netflex\Site\Support\ConfigurationMissingException'); | ||
CaptchaV2::checkBox(); | ||
} | ||
|
||
public function testMatchesSnapshot (): void { | ||
NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff'); | ||
NF::$site->mockVariable('captcha_site_secret', '112233445566'); | ||
$this->assertMatchesSnapshot(CaptchaV2::checkBox(), new TextDriver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use PHPUnit\Framework\TestCase; | ||
use Netflex\Site\Support\CaptchaV2; | ||
|
||
final class CaptchaV2_IsValidTest extends TestCase | ||
{ | ||
/** | ||
* Call this template method before each test method is run. | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
require_once('src/Netflex/Site/Support/CaptchaV2.php'); | ||
require_once('src/functions/common/functions_system.php'); | ||
require_once('src/Netflex/Site/Support/GoogleResponseException.php'); | ||
require_once('src/Netflex/Site/Support/ResponseMissingException.php'); | ||
require_once('src/Netflex/Site/Support/ConfigurationMissingException.php'); | ||
} | ||
|
||
public function testThrowsExceptionWhenParametersMissing (): void { | ||
$this->expectException('Netflex\Site\Support\ResponseMissingException'); | ||
CaptchaV2::isValid(); | ||
} | ||
|
||
public function testHandlesRequestException (): void { | ||
$_GET['g-recaptcha-response'] = 'test'; | ||
NF::$capi->mockResponse(new Response(500)); | ||
NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff'); | ||
NF::$site->mockVariable('captcha_site_secret', '112233445566'); | ||
$this->expectException('GuzzleHttp\Exception\ServerException'); | ||
CaptchaV2::isValid(); | ||
} | ||
|
||
public function testHandlesValidCase (): void { | ||
$_GET['g-recaptcha-response'] = 'test'; | ||
NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff'); | ||
NF::$site->mockVariable('captcha_site_secret', '112233445566'); | ||
NF::$capi->mockResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode([ | ||
'success' => false, | ||
'error-codes' => [ | ||
'Task failed successfully' | ||
] | ||
]))); | ||
|
||
$this->expectException('Netflex\Site\Support\GoogleResponseException'); | ||
CaptchaV2::isValid(); | ||
} | ||
|
||
public function testHandlesInvalidCase (): void { | ||
$_GET['g-recaptcha-response'] = 'test'; | ||
NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff'); | ||
NF::$site->mockVariable('captcha_site_secret', '112233445566'); | ||
NF::$capi->mockResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode([ | ||
'success' => true | ||
]))); | ||
|
||
$this->assertTrue(CaptchaV2::isValid()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Netflex\Site\Support\CaptchaV2; | ||
use Spatie\Snapshots\MatchesSnapshots; | ||
|
||
final class CaptchaV2_ScriptTagTest extends TestCase | ||
{ | ||
use MatchesSnapshots; | ||
|
||
/** | ||
* Call this template method before each test method is run. | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
require_once('src/Netflex/Site/Support/CaptchaV2.php'); | ||
require_once('src/functions/common/functions_system.php'); | ||
require_once('src/Netflex/Site/Support/GoogleResponseException.php'); | ||
require_once('src/Netflex/Site/Support/ResponseMissingException.php'); | ||
require_once('src/Netflex/Site/Support/ConfigurationMissingException.php'); | ||
} | ||
|
||
public function testMatchesSnapshots (): void { | ||
$this->assertMatchesSnapshot(CaptchaV2::scriptTag(), new TextDriver); | ||
$this->assertMatchesSnapshot(CaptchaV2::scriptTag(true), new TextDriver); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
tests/TestSuites/CaptchaV2/__snapshots__/CaptchaV2_CheckBoxTest__testMatchesSnapshot__1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="g-recaptcha" data-sitekey="aabbccddeeff"></div> |
Empty file.
1 change: 1 addition & 0 deletions
1
...s/TestSuites/CaptchaV2/__snapshots__/CaptchaV2_ScriptTagTest__testMatchesSnapshots__2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script src="https://www.google.com/recaptcha/api.js"></script> |