testCreateHCaptchaProtector()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace X3dgoo\HCaptcha\Tests;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\Form;
10
use SilverStripe\Forms\TextField;
11
use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension;
12
use X3dgoo\HCaptcha\Forms\HCaptchaProtector;
13
14
class HCaptchaProtectorTest extends SapphireTest
15
{
16
    protected $usesDatabase = true;
17
18
    public function testCreateHCaptchaProtector()
19
    {
20
        $hCaptchaProtector = new HCaptchaProtector();
21
22
        $this->assertNotNull($hCaptchaProtector);
23
    }
24
25
    public function testEnableSpamProtection()
26
    {
27
        Config::modify()->set(
28
            FormSpamProtectionExtension::class,
29
            'default_spam_protector',
30
            HCaptchaProtector::class
31
        );
32
33
        $form = Form::create(Controller::create(), 'Form', FieldList::create(
34
            TextField::create('Title'),
35
            TextField::create('Comment')
36
        ), FieldList::create());
37
38
        $form->disableSecurityToken();
39
40
        $form = $form->enableSpamProtection();
41
42
        $this->assertNotNull($form->Fields()->fieldByName('Captcha'));
43
    }
44
}
45