mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-10-22 14:05:59 +02:00
Add namespaces, separate test classes, add PSR-4 autoloader, update PSR-2 compliance
This commit is contained in:
parent
a60f592598
commit
c5f0827c2e
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
SilverStripe 3.0.0 or greater
|
SilverStripe 4.0 or greater
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
@ -3,4 +3,4 @@ name: spamprotection
|
|||||||
---
|
---
|
||||||
SilverStripe\Forms\Form:
|
SilverStripe\Forms\Form:
|
||||||
extensions:
|
extensions:
|
||||||
- SilverStripe\Spamprotection\FormSpamProtectionExtension
|
- SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SilverStripe\Spamprotection;
|
|
||||||
|
namespace SilverStripe\SpamProtection;
|
||||||
|
|
||||||
|
use SilverStripe\Forms\DropdownField;
|
||||||
|
use SilverStripe\Forms\FieldGroup;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
|
use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension;
|
||||||
|
use SilverStripe\ORM\UnsavedRelationList;
|
||||||
|
|
||||||
|
// @todo
|
||||||
|
use EditableEmailField;
|
||||||
|
use EditableFormField;
|
||||||
|
use EditableNumericField;
|
||||||
|
use EditableTextField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Editable Spam Protecter Field. Used with the User Defined Forms module (if
|
* Editable Spam Protecter Field. Used with the User Defined Forms module (if
|
||||||
@ -7,12 +20,16 @@ namespace SilverStripe\Spamprotection;
|
|||||||
*
|
*
|
||||||
* @package spamprotection
|
* @package spamprotection
|
||||||
*/
|
*/
|
||||||
|
// @todo update namespaced for userforms when it is 4.0 compatible
|
||||||
if (class_exists('EditableFormField')) {
|
if (class_exists('EditableFormField')) {
|
||||||
class EditableSpamProtectionField extends EditableFormField
|
class EditableSpamProtectionField extends EditableFormField
|
||||||
{
|
{
|
||||||
private static $singular_name = 'Spam Protection Field';
|
private static $singular_name = 'Spam Protection Field';
|
||||||
|
|
||||||
private static $plural_name = 'Spam Protection Fields';
|
private static $plural_name = 'Spam Protection Fields';
|
||||||
|
|
||||||
|
private static $table_name = 'EditableSpamProtectionField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fields to include spam detection for
|
* Fields to include spam detection for
|
||||||
*
|
*
|
||||||
@ -20,9 +37,9 @@ if (class_exists('EditableFormField')) {
|
|||||||
* @config
|
* @config
|
||||||
*/
|
*/
|
||||||
private static $check_fields = array(
|
private static $check_fields = array(
|
||||||
'EditableEmailField',
|
EditableEmailField::class,
|
||||||
'EditableTextField',
|
EditableTextField::class,
|
||||||
'EditableNumericField'
|
EditableNumericField::class
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
@ -148,15 +165,15 @@ if (class_exists('EditableFormField')) {
|
|||||||
|
|
||||||
// Each other text field in this group can be assigned a field mapping
|
// Each other text field in this group can be assigned a field mapping
|
||||||
$mapGroup = FieldGroup::create()
|
$mapGroup = FieldGroup::create()
|
||||||
->setTitle(_t('EditableSpamProtectionField.SPAMFIELDMAPPING', 'Spam Field Mapping'))
|
->setTitle(_t(__CLASS__.'.SPAMFIELDMAPPING', 'Spam Field Mapping'))
|
||||||
->setName('SpamFieldMapping')
|
->setName('SpamFieldMapping')
|
||||||
->setDescription(_t(
|
->setDescription(_t(
|
||||||
'EditableSpamProtectionField.SPAMFIELDMAPPINGDESCRIPTION',
|
__CLASS__.'.SPAMFIELDMAPPINGDESCRIPTION',
|
||||||
'Select the form fields that correspond to any relevant spam protection identifiers'
|
'Select the form fields that correspond to any relevant spam protection identifiers'
|
||||||
));
|
));
|
||||||
|
|
||||||
// Generate field specific settings
|
// Generate field specific settings
|
||||||
$mappableFields = Config::inst()->get('FormSpamProtectionExtension', 'mappable_fields');
|
$mappableFields = Config::inst()->get(FormSpamProtectionExtension::class, 'mappable_fields');
|
||||||
$mappableFieldsMerged = array_combine($mappableFields, $mappableFields);
|
$mappableFieldsMerged = array_combine($mappableFields, $mappableFields);
|
||||||
foreach ($this->getCandidateFields() as $otherField) {
|
foreach ($this->getCandidateFields() as $otherField) {
|
||||||
$mapSetting = "Map-{$otherField->Name}";
|
$mapSetting = "Map-{$otherField->Name}";
|
||||||
@ -228,10 +245,10 @@ if (class_exists('EditableFormField')) {
|
|||||||
|
|
||||||
if ($foundError !== false) {
|
if ($foundError !== false) {
|
||||||
// use error messaging already set from validate method
|
// use error messaging already set from validate method
|
||||||
$form->addErrorMessage($this->Name, $foundError['message'], $foundError['messageType'], false);
|
$form->sessionMessage($foundError['message'], $foundError['messageType']);
|
||||||
} else {
|
} else {
|
||||||
// fallback to custom message set in CMS or default message if none set
|
// fallback to custom message set in CMS or default message if none set
|
||||||
$form->addErrorMessage($this->Name, $this->getErrorMessage()->HTML(), 'error', false);
|
$form->sessionError($this->getErrorMessage()->HTML());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\Spamprotection;
|
namespace SilverStripe\SpamProtection\Extension;
|
||||||
|
|
||||||
use SilverStripe\Core\Extension;
|
use SilverStripe\Core\Extension;
|
||||||
|
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SilverStripe\Spamprotection;
|
|
||||||
|
namespace SilverStripe\SpamProtection\Extension;
|
||||||
|
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Core\Extension;
|
use SilverStripe\Core\Extension;
|
||||||
@ -59,7 +60,7 @@ class FormSpamProtectionExtension extends Extension
|
|||||||
* Instantiate a SpamProtector instance
|
* Instantiate a SpamProtector instance
|
||||||
*
|
*
|
||||||
* @param array $options Configuration options
|
* @param array $options Configuration options
|
||||||
* @return SpamProtector
|
* @return SpamProtector|null
|
||||||
*/
|
*/
|
||||||
public static function get_protector($options = null)
|
public static function get_protector($options = null)
|
||||||
{
|
{
|
||||||
@ -67,7 +68,7 @@ class FormSpamProtectionExtension extends Extension
|
|||||||
if (isset($options['protector'])) {
|
if (isset($options['protector'])) {
|
||||||
$protector = $options['protector'];
|
$protector = $options['protector'];
|
||||||
} else {
|
} else {
|
||||||
$protector = Config::inst()->get('FormSpamProtectionExtension', 'default_spam_protector');
|
$protector = Config::inst()->get(self::class, 'default_spam_protector');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($protector && class_exists($protector)) {
|
if ($protector && class_exists($protector)) {
|
||||||
@ -90,7 +91,7 @@ class FormSpamProtectionExtension extends Extension
|
|||||||
if (isset($options['name'])) {
|
if (isset($options['name'])) {
|
||||||
$name = $options['name'];
|
$name = $options['name'];
|
||||||
} else {
|
} else {
|
||||||
$name = Config::inst()->get('FormSpamProtectionExtension', 'field_name');
|
$name = Config::inst()->get(self::class, 'field_name');
|
||||||
}
|
}
|
||||||
|
|
||||||
// captcha field title
|
// captcha field title
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SilverStripe\Spamprotection;
|
|
||||||
|
namespace SilverStripe\SpamProtection;
|
||||||
|
|
||||||
use SilverStripe\Forms\FormField;
|
use SilverStripe\Forms\FormField;
|
||||||
|
|
@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace SilverStripe\Spamprotection;
|
|
||||||
|
|
||||||
use SilverStripe\Dev\Deprecation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package spamprotection
|
|
||||||
*
|
|
||||||
* @deprecated 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
class SpamProtectorManager
|
|
||||||
{
|
|
||||||
private static $spam_protector = null;
|
|
||||||
|
|
||||||
public static function set_spam_protector($protector)
|
|
||||||
{
|
|
||||||
Deprecation::notice(
|
|
||||||
'1.1',
|
|
||||||
'SpamProtectorManager::set_spam_protector() is deprecated. '.
|
|
||||||
'Use the new config system. FormSpamProtectorExtension.default_spam_protector'
|
|
||||||
);
|
|
||||||
|
|
||||||
static::$spam_protector = $protector;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function get_spam_protector()
|
|
||||||
{
|
|
||||||
Deprecation::notice(
|
|
||||||
'1.1',
|
|
||||||
'SpamProtectorManager::get_spam_protector() is deprecated'.
|
|
||||||
'Use the new config system. FormSpamProtectorExtension.default_spam_protector'
|
|
||||||
);
|
|
||||||
|
|
||||||
return static::$spam_protector;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function update_form($form, $before = null, $fieldsToSpamServiceMapping = array(), $title = null, $rightTitle = null)
|
|
||||||
{
|
|
||||||
Deprecation::notice(
|
|
||||||
'1.1',
|
|
||||||
'SpamProtectorManager::update_form is deprecated'.
|
|
||||||
'Please use $form->enableSpamProtection() for adding spamprotection'
|
|
||||||
);
|
|
||||||
|
|
||||||
return $form->enableSpamProtection();
|
|
||||||
}
|
|
||||||
}
|
|
@ -21,6 +21,12 @@
|
|||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "3.0.x-dev"
|
"dev-master": "3.0.x-dev"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"SilverStripe\\SpamProtection\\": "code/",
|
||||||
|
"SilverStripe\\SpamProtection\\Tests\\": "tests/"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
de:
|
de:
|
||||||
EditableSpamProtectionField:
|
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||||
PLURALNAME: Spamschutzfelder
|
PLURALNAME: Spamschutzfelder
|
||||||
SINGULARNAME: Spamschutzfeld
|
SINGULARNAME: Spamschutzfeld
|
||||||
SPAMFIELDMAPPING: 'Spamschutzfeld Zuordnung'
|
SPAMFIELDMAPPING: 'Spamschutzfeld Zuordnung'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
en:
|
en:
|
||||||
EditableSpamProtectionField:
|
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||||
PLURALNAME: 'Spam Protection Fields'
|
PLURALNAME: 'Spam Protection Fields'
|
||||||
SINGULARNAME: 'Spam Protection Field'
|
SINGULARNAME: 'Spam Protection Field'
|
||||||
SPAMFIELDMAPPING: 'Spam Field Mapping'
|
SPAMFIELDMAPPING: 'Spam Field Mapping'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
eo:
|
eo:
|
||||||
EditableSpamProtectionField:
|
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||||
PLURALNAME: 'Spamprotektaj kampoj'
|
PLURALNAME: 'Spamprotektaj kampoj'
|
||||||
SINGULARNAME: 'Spamprotekta kampo'
|
SINGULARNAME: 'Spamprotekta kampo'
|
||||||
SPAMFIELDMAPPING: 'Spamkampa mapigo'
|
SPAMFIELDMAPPING: 'Spamkampa mapigo'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
es:
|
es:
|
||||||
EditableSpamProtectionField:
|
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||||
PLURALNAME: 'Campos de protección de spam'
|
PLURALNAME: 'Campos de protección de spam'
|
||||||
SINGULARNAME: 'Campo de protección de spam'
|
SINGULARNAME: 'Campo de protección de spam'
|
||||||
SPAMFIELDMAPPING: 'Mapeo del campo spam'
|
SPAMFIELDMAPPING: 'Mapeo del campo spam'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
fa_IR:
|
fa_IR:
|
||||||
EditableSpamProtectionField:
|
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||||
PLURALNAME: 'فیلدهای محافظت از هرزنوشته'
|
PLURALNAME: 'فیلدهای محافظت از هرزنوشته'
|
||||||
SINGULARNAME: 'فیلد محافظت از هرزنوشته'
|
SINGULARNAME: 'فیلد محافظت از هرزنوشته'
|
||||||
SPAMFIELDMAPPING: 'نقشهبرداری فیلد هرزنوشته'
|
SPAMFIELDMAPPING: 'نقشهبرداری فیلد هرزنوشته'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
hr:
|
hr:
|
||||||
EditableSpamProtectionField:
|
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||||
PLURALNAME: 'Polja Spam zaštite'
|
PLURALNAME: 'Polja Spam zaštite'
|
||||||
SINGULARNAME: 'Polje Spam zaštite'
|
SINGULARNAME: 'Polje Spam zaštite'
|
||||||
SPAMFIELDMAPPING: 'Mapiranje polja Spama'
|
SPAMFIELDMAPPING: 'Mapiranje polja Spama'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
ru:
|
ru:
|
||||||
EditableSpamProtectionField:
|
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||||
PLURALNAME: 'Поля защиты от спама'
|
PLURALNAME: 'Поля защиты от спама'
|
||||||
SINGULARNAME: 'Поле защиты от спама'
|
SINGULARNAME: 'Поле защиты от спама'
|
||||||
SPAMFIELDMAPPING: 'Привязка полей для защиты от спама'
|
SPAMFIELDMAPPING: 'Привязка полей для защиты от спама'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
sk:
|
sk:
|
||||||
EditableSpamProtectionField:
|
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||||
PLURALNAME: 'Polia ochrany proti spamu'
|
PLURALNAME: 'Polia ochrany proti spamu'
|
||||||
SINGULARNAME: 'Pole ochrany proti spamu'
|
SINGULARNAME: 'Pole ochrany proti spamu'
|
||||||
SPAMFIELDMAPPING: 'Mapovanie spamového poľa'
|
SPAMFIELDMAPPING: 'Mapovanie spamového poľa'
|
||||||
|
@ -1,11 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SpamProtection\Tests;
|
||||||
|
|
||||||
|
use UserDefinedForm;
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\Forms\Form;
|
||||||
|
use SilverStripe\Forms\RequiredFields;
|
||||||
|
use SilverStripe\SpamProtection\EditableSpamProtectionField;
|
||||||
|
use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension;
|
||||||
|
use SilverStripe\SpamProtection\Tests\EditableSpamProtectionFieldTest\Protector;
|
||||||
|
|
||||||
class EditableSpamProtectionFieldTest extends SapphireTest
|
class EditableSpamProtectionFieldTest extends SapphireTest
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $usesDatabase = true;
|
protected $usesDatabase = true;
|
||||||
|
|
||||||
public function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
@ -13,10 +23,10 @@ class EditableSpamProtectionFieldTest extends SapphireTest
|
|||||||
$this->markTestSkipped('"userforms" module not installed');
|
$this->markTestSkipped('"userforms" module not installed');
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::inst()->update(
|
Config::modify()->set(
|
||||||
'FormSpamProtectionExtension',
|
FormSpamProtectionExtension::class,
|
||||||
'default_spam_protector',
|
'default_spam_protector',
|
||||||
'EditableSpamProtectionFieldTest_Protector'
|
Protector::class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +43,7 @@ class EditableSpamProtectionFieldTest extends SapphireTest
|
|||||||
|
|
||||||
$formMock
|
$formMock
|
||||||
->expects($this->never())
|
->expects($this->never())
|
||||||
->method('addErrorMessage');
|
->method('sessionMessage');
|
||||||
|
|
||||||
$formFieldMock->validateField(array('MyField' => null), $formMock);
|
$formFieldMock->validateField(array('MyField' => null), $formMock);
|
||||||
}
|
}
|
||||||
@ -53,9 +63,13 @@ class EditableSpamProtectionFieldTest extends SapphireTest
|
|||||||
|
|
||||||
$formMock
|
$formMock
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('addErrorMessage')
|
->method('sessionMessage')
|
||||||
->with($this->anything(), $this->stringContains('some field message'), $this->anything(), $this->anything());
|
->with(
|
||||||
;
|
$this->anything(),
|
||||||
|
$this->stringContains('some field message'),
|
||||||
|
$this->anything(),
|
||||||
|
$this->anything()
|
||||||
|
);
|
||||||
|
|
||||||
$formFieldMock->validateField(array('MyField' => null), $formMock);
|
$formFieldMock->validateField(array('MyField' => null), $formMock);
|
||||||
}
|
}
|
||||||
@ -75,8 +89,13 @@ class EditableSpamProtectionFieldTest extends SapphireTest
|
|||||||
|
|
||||||
$formMock
|
$formMock
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('addErrorMessage')
|
->method('sessionMessage')
|
||||||
->with($this->anything(), $this->stringContains('default error message'), $this->anything(), $this->anything());
|
->with(
|
||||||
|
$this->anything(),
|
||||||
|
$this->stringContains('default error message'),
|
||||||
|
$this->anything(),
|
||||||
|
$this->anything()
|
||||||
|
);
|
||||||
|
|
||||||
$formFieldMock->validateField(array('MyField' => null), $formMock);
|
$formFieldMock->validateField(array('MyField' => null), $formMock);
|
||||||
}
|
}
|
||||||
@ -102,7 +121,7 @@ class EditableSpamProtectionFieldTest extends SapphireTest
|
|||||||
|
|
||||||
protected function getFormMock()
|
protected function getFormMock()
|
||||||
{
|
{
|
||||||
$formMock = $this->getMockBuilder('Form', array('addErrorMessage'))
|
$formMock = $this->getMockBuilder(Form::class, array('sessionMessage'))
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$formMock
|
$formMock
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SpamProtection\Tests;
|
||||||
|
|
||||||
|
use SilverStripe\Control\Controller;
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
|
use SilverStripe\Forms\Form;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension;
|
||||||
|
use SilverStripe\SpamProtection\Tests\Stub\FooProtector;
|
||||||
|
use SilverStripe\SpamProtection\Tests\Stub\BarProtector;
|
||||||
|
use SilverStripe\SpamProtection\Tests\Stub\BazProtector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package spamprotection
|
* @package spamprotection
|
||||||
*/
|
*/
|
||||||
@ -12,24 +25,25 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||||||
*/
|
*/
|
||||||
protected $form = null;
|
protected $form = null;
|
||||||
|
|
||||||
public function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->form = new Form($this, 'Form', new FieldList(
|
$this->form = new Form(new Controller, 'Form', new FieldList(
|
||||||
new TextField('Title'),
|
new TextField('Title'),
|
||||||
new TextField('Comment'),
|
new TextField('Comment'),
|
||||||
new TextField('URL')
|
new TextField('URL')
|
||||||
), new FieldList());
|
), new FieldList());
|
||||||
|
|
||||||
$this->form->disableSecurityToken();
|
$this->form->disableSecurityToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEnableSpamProtection()
|
public function testEnableSpamProtection()
|
||||||
{
|
{
|
||||||
Config::inst()->update(
|
Config::modify()->set(
|
||||||
'FormSpamProtectionExtension',
|
FormSpamProtectionExtension::class,
|
||||||
'default_spam_protector',
|
'default_spam_protector',
|
||||||
'FormSpamProtectionExtensionTest_FooProtector'
|
FooProtector::class
|
||||||
);
|
);
|
||||||
|
|
||||||
$form = $this->form->enableSpamProtection();
|
$form = $this->form->enableSpamProtection();
|
||||||
@ -40,7 +54,7 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||||||
public function testEnableSpamProtectionCustomProtector()
|
public function testEnableSpamProtectionCustomProtector()
|
||||||
{
|
{
|
||||||
$form = $this->form->enableSpamProtection(array(
|
$form = $this->form->enableSpamProtection(array(
|
||||||
'protector' => 'FormSpamProtectionExtensionTest_BarProtector'
|
'protector' => BarProtector::class
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEquals('Bar', $form->Fields()->fieldByName('Captcha')->Title());
|
$this->assertEquals('Bar', $form->Fields()->fieldByName('Captcha')->Title());
|
||||||
@ -49,7 +63,7 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||||||
public function testEnableSpamProtectionCustomTitle()
|
public function testEnableSpamProtectionCustomTitle()
|
||||||
{
|
{
|
||||||
$form = $this->form->enableSpamProtection(array(
|
$form = $this->form->enableSpamProtection(array(
|
||||||
'protector' => 'FormSpamProtectionExtensionTest_BarProtector',
|
'protector' => BarProtector::class,
|
||||||
'title' => 'Baz',
|
'title' => 'Baz',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -59,7 +73,7 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||||||
public function testCustomOptions()
|
public function testCustomOptions()
|
||||||
{
|
{
|
||||||
$form = $this->form->enableSpamProtection(array(
|
$form = $this->form->enableSpamProtection(array(
|
||||||
'protector' => 'FormSpamProtectionExtensionTest_BazProtector',
|
'protector' => BazProtector::class,
|
||||||
'title' => 'Qux',
|
'title' => 'Qux',
|
||||||
'name' => 'Borris'
|
'name' => 'Borris'
|
||||||
));
|
));
|
||||||
@ -70,17 +84,19 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||||||
public function testConfigurableName()
|
public function testConfigurableName()
|
||||||
{
|
{
|
||||||
$field_name = "test_configurable_name";
|
$field_name = "test_configurable_name";
|
||||||
Config::inst()->update(
|
Config::modify()->set(
|
||||||
'FormSpamProtectionExtension', 'default_spam_protector',
|
FormSpamProtectionExtension::class,
|
||||||
'FormSpamProtectionExtensionTest_FooProtector'
|
'default_spam_protector',
|
||||||
|
FooProtector::class
|
||||||
);
|
);
|
||||||
Config::inst()->update(
|
Config::modify()->set(
|
||||||
'FormSpamProtectionExtension', 'field_name',
|
FormSpamProtectionExtension::class,
|
||||||
|
'field_name',
|
||||||
$field_name
|
$field_name
|
||||||
);
|
);
|
||||||
$form = $this->form->enableSpamProtection();
|
$form = $this->form->enableSpamProtection();
|
||||||
// remove for subsequent tests
|
// remove for subsequent tests
|
||||||
Config::inst()->remove('FormSpamProtectionExtension', 'field_name');
|
Config::modify()->remove(FormSpamProtectionExtension::class, 'field_name');
|
||||||
// field should take up configured name
|
// field should take up configured name
|
||||||
$this->assertEquals('Foo', $form->Fields()->fieldByName($field_name)->Title());
|
$this->assertEquals('Foo', $form->Fields()->fieldByName($field_name)->Title());
|
||||||
}
|
}
|
||||||
@ -88,7 +104,7 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||||||
public function testInsertBefore()
|
public function testInsertBefore()
|
||||||
{
|
{
|
||||||
$form = $this->form->enableSpamProtection(array(
|
$form = $this->form->enableSpamProtection(array(
|
||||||
'protector' => 'FormSpamProtectionExtensionTest_FooProtector',
|
'protector' => FooProtector::class,
|
||||||
'insertBefore' => 'URL'
|
'insertBefore' => 'URL'
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -102,7 +118,7 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||||||
public function testInsertBeforeMissing()
|
public function testInsertBeforeMissing()
|
||||||
{
|
{
|
||||||
$form = $this->form->enableSpamProtection(array(
|
$form = $this->form->enableSpamProtection(array(
|
||||||
'protector' => 'FormSpamProtectionExtensionTest_FooProtector',
|
'protector' => FooProtector::class,
|
||||||
'insertBefore' => 'NotAField'
|
'insertBefore' => 'NotAField'
|
||||||
));
|
));
|
||||||
|
|
||||||
|
23
tests/FormSpamProtectionExtensionTest/BarProtector.php
Normal file
23
tests/FormSpamProtectionExtensionTest/BarProtector.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SpamProtection\Tests\FormSpamProtectionExtensionTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\SpamProtection\SpamProtector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package spamprotection
|
||||||
|
*/
|
||||||
|
class BarProtector implements SpamProtector, TestOnly
|
||||||
|
{
|
||||||
|
public function getFormField($name = null, $title = null, $value = null)
|
||||||
|
{
|
||||||
|
$title = $title ?: 'Bar';
|
||||||
|
return new TextField($name, $title, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFieldMapping($fieldMapping)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
22
tests/FormSpamProtectionExtensionTest/BazProtector.php
Normal file
22
tests/FormSpamProtectionExtensionTest/BazProtector.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SpamProtection\Tests\FormSpamProtectionExtensionTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\SpamProtection\SpamProtector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package spamprotection
|
||||||
|
*/
|
||||||
|
class BazProtector implements SpamProtector, TestOnly
|
||||||
|
{
|
||||||
|
public function getFormField($name = null, $title = null, $value = null)
|
||||||
|
{
|
||||||
|
return new TextField($name, $title, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFieldMapping($fieldMapping)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
22
tests/FormSpamProtectionExtensionTest/FooProtector.php
Normal file
22
tests/FormSpamProtectionExtensionTest/FooProtector.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SpamProtection\Tests\FormSpamProtectionExtensionTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\SpamProtection\SpamProtector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package spamprotection
|
||||||
|
*/
|
||||||
|
class FooProtector implements SpamProtector, TestOnly
|
||||||
|
{
|
||||||
|
public function getFormField($name = null, $title = null, $value = null)
|
||||||
|
{
|
||||||
|
return new TextField($name, 'Foo', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFieldMapping($fieldMapping)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SpamProtection\Tests\Stub;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\SpamProtection\SpamProtector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package spamprotection
|
* @package spamprotection
|
||||||
*/
|
*/
|
||||||
class FormSpamProtectionExtensionTest_BarProtector implements SpamProtector, TestOnly
|
class BarProtector implements SpamProtector, TestOnly
|
||||||
{
|
{
|
||||||
public function getFormField($name = null, $title = null, $value = null)
|
public function getFormField($name = null, $title = null, $value = null)
|
||||||
{
|
{
|
@ -1,9 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SpamProtection\Tests\Stub;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\SpamProtection\SpamProtector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package spamprotection
|
* @package spamprotection
|
||||||
*/
|
*/
|
||||||
class FormSpamProtectionExtensionTest_BazProtector implements SpamProtector, TestOnly
|
class BazProtector implements SpamProtector, TestOnly
|
||||||
{
|
{
|
||||||
public function getFormField($name = null, $title = null, $value = null)
|
public function getFormField($name = null, $title = null, $value = null)
|
||||||
{
|
{
|
@ -1,9 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SpamProtection\Tests\Stub;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\SpamProtection\SpamProtector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package spamprotection
|
* @package spamprotection
|
||||||
*/
|
*/
|
||||||
class FormSpamProtectionExtensionTest_FooProtector implements SpamProtector, TestOnly
|
class FooProtector implements SpamProtector, TestOnly
|
||||||
{
|
{
|
||||||
public function getFormField($name = null, $title = null, $value = null)
|
public function getFormField($name = null, $title = null, $value = null)
|
||||||
{
|
{
|
@ -1,6 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class EditableSpamProtectionFieldTest_Protector implements SpamProtector, TestOnly
|
namespace SilverStripe\SpamProtection\Tests\Stub;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\SpamProtection\SpamProtector;
|
||||||
|
|
||||||
|
class Protector implements SpamProtector, TestOnly
|
||||||
{
|
{
|
||||||
public function getFormField($name = null, $title = null, $value = null)
|
public function getFormField($name = null, $title = null, $value = null)
|
||||||
{
|
{
|
Loading…
Reference in New Issue
Block a user