BootstrapMFALoginFormTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFormFieldsWithTokens() 0 18 3
A testGetFormFieldsNoTokens() 0 13 1
1
<?php
2
3
namespace Firesphere\BootstrapMFA\Tests;
4
5
use Firesphere\BootstrapMFA\Authenticators\BootstrapMFAAuthenticator;
6
use Firesphere\BootstrapMFA\Forms\BootstrapMFALoginForm;
7
use SilverStripe\Control\Controller;
8
use SilverStripe\Core\Injector\Injector;
9
use SilverStripe\Dev\SapphireTest;
10
use SilverStripe\Forms\FieldList;
11
12
class BootstrapMFALoginFormTest extends SapphireTest
13
{
14
    public function testGetFormFieldsWithTokens()
15
    {
16
        $controller = Controller::curr();
17
        $controller->getRequest()->getSession()->set('tokens', '12345678');
18
        /** @var BootstrapMFALoginForm $form */
19
        $form = Injector::inst()->createWithArgs(
20
            BootstrapMFALoginForm::class,
21
            [$controller, BootstrapMFAAuthenticator::class, 'test']
22
        );
23
24
        $fields = $form->getFormFields();
25
        $this->assertInstanceOf(FieldList::class, $fields);
26
27
        $this->assertNull($controller->getRequest()->getSession()->get('tokens'));
28
        foreach ($fields as $field) {
29
            // Hack. InstanceOf fails while the field is there
30
            if ($field->getName() === 'tokens') {
31
                $this->assertTrue(true);
32
            }
33
        }
34
    }
35
36
    public function testGetFormFieldsNoTokens()
37
    {
38
        $controller = Controller::curr();
39
        /** @var BootstrapMFALoginForm $form */
40
        $form = Injector::inst()->createWithArgs(
41
            BootstrapMFALoginForm::class,
42
            [$controller, BootstrapMFAAuthenticator::class, 'test']
43
        );
44
45
        $fields = $form->getFormFields();
46
        $this->assertInstanceOf(FieldList::class, $fields);
47
48
        $this->assertEquals(null, $fields->dataFieldByName('tokens'));
49
    }
50
}
51