mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-10-22 14:05:59 +02:00
FIX Check value is not NULL
This commit is contained in:
parent
2c8fc03f2f
commit
2a55708ae8
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\SpamProtection\Extension;
|
||||
|
||||
use LogicException;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
@ -84,6 +85,7 @@ class FormSpamProtectionExtension extends Extension
|
||||
* Activates the spam protection module.
|
||||
*
|
||||
* @param array $options
|
||||
* @throws LogicException when get_protector method returns NULL.
|
||||
* @return Object
|
||||
*/
|
||||
public function enableSpamProtection($options = array())
|
||||
@ -106,7 +108,11 @@ class FormSpamProtectionExtension extends Extension
|
||||
// set custom mapping on this form
|
||||
$protector = self::get_protector($options);
|
||||
|
||||
if (isset($options['mapping'])) {
|
||||
if ($protector === null) {
|
||||
throw new LogicException('No spam protector has been set. Null is not valid value.');
|
||||
}
|
||||
|
||||
if ($protector && isset($options['mapping'])) {
|
||||
$protector->setFieldMapping($options['mapping']);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\SpamProtection\Tests;
|
||||
|
||||
use LogicException;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
@ -38,6 +39,14 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
||||
$this->form->disableSecurityToken();
|
||||
}
|
||||
|
||||
public function testEnableSpamProtectionThrowsException()
|
||||
{
|
||||
$this->expectException(LogicException::class);
|
||||
$this->expectExceptionMessage('No spam protector has been set. Null is not valid value.');
|
||||
|
||||
$this->form->enableSpamProtection();
|
||||
}
|
||||
|
||||
public function testEnableSpamProtection()
|
||||
{
|
||||
Config::modify()->set(
|
||||
|
Loading…
Reference in New Issue
Block a user