diff --git a/code/extensions/FormSpamProtectionExtension.php b/code/extensions/FormSpamProtectionExtension.php index 7346d5e..38f6aa8 100644 --- a/code/extensions/FormSpamProtectionExtension.php +++ b/code/extensions/FormSpamProtectionExtension.php @@ -41,6 +41,15 @@ class FormSpamProtectionExtension extends Extension '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 * @@ -75,7 +84,7 @@ class FormSpamProtectionExtension extends Extension if (isset($options['name'])) { $name = $options['name']; } else { - $name = 'Captcha'; + $name = Config::inst()->get('FormSpamProtectionExtension', 'field_name'); } // captcha field title diff --git a/tests/FormSpamProtectionExtensionTest.php b/tests/FormSpamProtectionExtensionTest.php index 91111b5..1df952e 100644 --- a/tests/FormSpamProtectionExtensionTest.php +++ b/tests/FormSpamProtectionExtensionTest.php @@ -67,6 +67,24 @@ class FormSpamProtectionExtensionTest extends SapphireTest $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() { $form = $this->form->enableSpamProtection(array(