-
Notifications
You must be signed in to change notification settings - Fork 4
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 #2 from nswdpc/feat-badge-placement
Badge placement
- Loading branch information
Showing
4 changed files
with
96 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
/tests export-ignore | ||
/docs export-ignore | ||
/client/src export-ignore | ||
/.editorconfig export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.php_cs.dist | ||
/.phpcs.xml.dist | ||
/.phpunit.xml.dist | ||
/.php_cs.dist export-ignore | ||
/phpcs.xml.dist export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.waratah export-ignore | ||
/code_of_conduct.md export-ignore | ||
/CONTRIBUTING.md export-ignore | ||
/README.md export-ignore |
4 changes: 4 additions & 0 deletions
4
templates/NSWDPC/SpamProtection/EditableRecaptchaV3Field_holder.ss
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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
$Field | ||
<% if $Message %><span class="message $MessageType">$Message</span><% end_if %> | ||
|
||
<% if $ReCAPTCHAv3BadgeDisplay=='field' %> | ||
<% include NSWDPC/SpamProtection/FormBadge %> | ||
<% end_if %> |
Empty file.
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,86 @@ | ||
<?php | ||
|
||
namespace NSWDPC\SpamProtection\Tests; | ||
|
||
use NSWDPC\SpamProtection\EditableRecaptchaV3Field; | ||
use NSWDPC\SpamProtection\RecaptchaV3SpamProtector; | ||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\Dev\SapphireTest; | ||
|
||
/** | ||
* Test badge placement for editable recaptcha fields | ||
* @author James | ||
*/ | ||
class EditableRecaptchaV3FieldBadgePlacementTest extends SapphireTest | ||
{ | ||
|
||
protected $usesDatabase = false; | ||
|
||
public function testDefaultBadgePlacement() { | ||
Config::modify()->set(RecaptchaV3SpamProtector::class, 'badge_display', RecaptchaV3SpamProtector::BADGE_DISPLAY_DEFAULT); | ||
$field = EditableRecaptchaV3Field::create([ | ||
'Score' => 50, | ||
'Action' => 'test/default' | ||
]); | ||
$field->write(); | ||
|
||
$displayOption = RecaptchaV3SpamProtector::get_badge_display(); | ||
$this->assertEquals(RecaptchaV3SpamProtector::BADGE_DISPLAY_DEFAULT, $displayOption, "ShowRecaptchaV3Badge returned empty"); | ||
|
||
$template = $field->getFormField()->FieldHolder()->forTemplate(); | ||
|
||
$this->assertTrue( strpos($template, "https://policies.google.com/privacy") === false, "Recaptcha policy link not in template"); | ||
|
||
$this->assertTrue( strpos($template, "https://policies.google.com/terms") === false, "Recaptcha T&C link not in template"); | ||
} | ||
|
||
public function testFieldBadgePlacement() { | ||
Config::modify()->set(RecaptchaV3SpamProtector::class, 'badge_display', RecaptchaV3SpamProtector::BADGE_DISPLAY_FIELD); | ||
$field = EditableRecaptchaV3Field::create([ | ||
'Score' => 60, | ||
'Action' => 'test/field' | ||
]); | ||
$displayOption = RecaptchaV3SpamProtector::get_badge_display(); | ||
$this->assertEquals(RecaptchaV3SpamProtector::BADGE_DISPLAY_FIELD, $displayOption, "ShowRecaptchaV3Badge returned field setting"); | ||
|
||
$template = $field->getFormField()->FieldHolder()->forTemplate(); | ||
|
||
$this->assertTrue( strpos($template, "https://policies.google.com/privacy") !== false, "Recaptcha policy link in template"); | ||
|
||
$this->assertTrue( strpos($template, "https://policies.google.com/terms") !== false, "Recaptcha T&C link in template"); | ||
} | ||
|
||
public function testFormBadgePlacement() { | ||
Config::modify()->set(RecaptchaV3SpamProtector::class, 'badge_display', RecaptchaV3SpamProtector::BADGE_DISPLAY_FORM); | ||
$field = EditableRecaptchaV3Field::create([ | ||
'Score' => 20, | ||
'Action' => 'test/form' | ||
]); | ||
$displayOption = RecaptchaV3SpamProtector::get_badge_display(); | ||
$this->assertEquals(RecaptchaV3SpamProtector::BADGE_DISPLAY_FORM, $displayOption, "ShowRecaptchaV3Badge returned page setting"); | ||
|
||
$template = $field->getFormField()->FieldHolder()->forTemplate(); | ||
|
||
$this->assertTrue( strpos($template, "https://policies.google.com/privacy") === false, "Recaptcha policy link not in template"); | ||
|
||
$this->assertTrue( strpos($template, "https://policies.google.com/terms") === false, "Recaptcha T&C link not in template"); | ||
|
||
} | ||
|
||
public function testPageBadgePlacement() { | ||
Config::modify()->set(RecaptchaV3SpamProtector::class, 'badge_display', RecaptchaV3SpamProtector::BADGE_DISPLAY_PAGE); | ||
$field = EditableRecaptchaV3Field::create([ | ||
'Score' => 40, | ||
'Action' => 'test/page' | ||
]); | ||
$displayOption = RecaptchaV3SpamProtector::get_badge_display(); | ||
$this->assertEquals(RecaptchaV3SpamProtector::BADGE_DISPLAY_PAGE, $displayOption, "ShowRecaptchaV3Badge returned page setting"); | ||
|
||
$template = $field->getFormField()->FieldHolder()->forTemplate(); | ||
|
||
$this->assertTrue( strpos($template, "https://policies.google.com/privacy") === false, "Recaptcha policy link not in template"); | ||
|
||
$this->assertTrue( strpos($template, "https://policies.google.com/terms") === false, "Recaptcha T&C link not in template"); | ||
|
||
} | ||
} |