mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-10-22 14:05:59 +02:00
Configurable fieldname (#56)
* Allow for a configurable field name * Add a test for configurable field name * Remove extra conditional by storing the field name in a private static * No need for field_name config removal as it's now specified as a class property
This commit is contained in:
parent
a25b052510
commit
ef3e6d45b6
@ -41,6 +41,15 @@ class FormSpamProtectionExtension extends Extension
|
|||||||
'authorId'
|
'authorId'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @config
|
||||||
|
*
|
||||||
|
* The field name to use for the {@link SpamProtector} {@link FormField}
|
||||||
|
*
|
||||||
|
* @var string $spam_protector
|
||||||
|
*/
|
||||||
|
private static $field_name = "Captcha";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate a SpamProtector instance
|
* Instantiate a SpamProtector instance
|
||||||
*
|
*
|
||||||
@ -75,7 +84,7 @@ class FormSpamProtectionExtension extends Extension
|
|||||||
if (isset($options['name'])) {
|
if (isset($options['name'])) {
|
||||||
$name = $options['name'];
|
$name = $options['name'];
|
||||||
} else {
|
} else {
|
||||||
$name = 'Captcha';
|
$name = Config::inst()->get('FormSpamProtectionExtension', 'field_name');
|
||||||
}
|
}
|
||||||
|
|
||||||
// captcha field title
|
// captcha field title
|
||||||
|
@ -67,6 +67,24 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||||||
$this->assertEquals('Qux', $form->Fields()->fieldByName('Borris')->Title());
|
$this->assertEquals('Qux', $form->Fields()->fieldByName('Borris')->Title());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConfigurableName()
|
||||||
|
{
|
||||||
|
$field_name = "test_configurable_name";
|
||||||
|
Config::inst()->update(
|
||||||
|
'FormSpamProtectionExtension', 'default_spam_protector',
|
||||||
|
'FormSpamProtectionExtensionTest_FooProtector'
|
||||||
|
);
|
||||||
|
Config::inst()->update(
|
||||||
|
'FormSpamProtectionExtension', 'field_name',
|
||||||
|
$field_name
|
||||||
|
);
|
||||||
|
$form = $this->form->enableSpamProtection();
|
||||||
|
// remove for subsequent tests
|
||||||
|
Config::inst()->remove('FormSpamProtectionExtension', 'field_name');
|
||||||
|
// field should take up configured name
|
||||||
|
$this->assertEquals('Foo', $form->Fields()->fieldByName($field_name)->Title());
|
||||||
|
}
|
||||||
|
|
||||||
public function testInsertBefore()
|
public function testInsertBefore()
|
||||||
{
|
{
|
||||||
$form = $this->form->enableSpamProtection(array(
|
$form = $this->form->enableSpamProtection(array(
|
||||||
|
Loading…
Reference in New Issue
Block a user